Golang SDK

Topics about the Software of Revolution Pi
Post Reply
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39

Golang SDK

Post by imerledragon »

Hello,

I am wondering if you have any Golang SDK available for read/write I/O Modules.
Currently, the configuration I have is RevPi Core 3+ with two RevPi DIO and one RevPi MIO.

In your documentation I see that you provide a Python interface (revpimodio2) but unfortunately Python. Do you have any equivalent in Go?
If I were just to write outputs on DIO Module, is there any simple way to do it like I would do with GPIO in Go? I guess it's like opening the /dev and read/write with the offset?

Thank you very much,
Torpi
->Johannes<-

Re: Golang SDK

Post by ->Johannes<- »

Hi,

We can't do that at the moment, but we are taking up the topic.
However, I cannot guarantee that this will be implemented.

revpimodio2 does not come from Kunbus either, it is a 3rd party.

Everything should be documented in Github so that you can link up with your programming language.

GitHub RevPi

Here is a video tutorial on the piTest source code

Tutorial 13 – PiTest source code

Regards
Johannes
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39

Re: Golang SDK

Post by imerledragon »

Hello Johannes,

thank you for your reply. The repo and especially piControl.h is helping for all the constants. Thank you.
Based on https://github.com/mezzato/revpi, I have been able to make it work leveraging NumToBytes and Write functions.

It's easy to cross-compile it from my main computer and run it on the RevPi Core.

Code: Select all

// NumToBytes converts a generic fixed-size value to its byte representation.
func NumToBytes(num interface{}) ([]byte, error) {
	buf := new(bytes.Buffer)
	err := binary.Write(buf, binary.LittleEndian, num)
	if err != nil {
		fmt.Println("binary.Write failed:", err)
		return nil, err
	}
	return buf.Bytes(), nil
}

// Write writes process data at a specific position, writes len(pData) bytes to file.
// Returns number of bytes read or error
func (c *RevPiControl) Write(offset uint32, pData []byte) (n int, err error) {
	if err = c.Open(); err != nil {
		return -1, err
	}
	if _, err = c.handle.Seek(int64(offset), 0); err != nil {
		return -1, err
	}

	// write
	return c.handle.Write(pData)
}
Torpi
Last edited by imerledragon on 06 Oct 2021, 14:44, edited 1 time in total.
Post Reply