Hello.
What exactly was the problem in the serial interface? Have you tried opening the serial port and writing data to it?
I think the way to approach this is to first test if any of the commands specified in the manual work as expected, and once you know you are able to send and receive data from the device then build a nice receiver and sender action in EG.
---
From what I understand you should be able to communicate with the device like this:
First of all, open the serial connection, set it to the 19200bps, 8 data bits per byte, no parity bit, 1 stop bit; as specified in the manual. Also turn the 'event generation' on and set the encoding to 'HEX'. (We will be using this feature to send the data)
So each command is 4 bytes long, where the last byte is a checksum like so:
Code: Select all
Initialization command:
\x01 \x01 \x00 \x00
^CMD byte ^Address ^Data ^Checksum (XOR the first 3 bytes with each other to get this)
So for example to toggle/turn on relay 1 state:
\0x03\0x00\0x01\0x02
And so forth..
Here are some example EG events that could be used to send and receive the data: (copy & paste into EG)
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1449">
<Folder Name="relay_board">
<Macro Name="Generate_checksum">
<Event Name="mycommand" />
<Action>
EventGhost.PythonScript(u'a = int(eg.event.payload[0:2], 16) # Command\nb = int(eg.event.payload[2:4], 16) # Address\nc = int(eg.event.payload[4:6], 16) # Data\nd = a^b^c # Checksum (bitvise XOR value of the 3 data bytes)\nstring = "%.2X%.2X%.2X%.2X" % (a, b, c, d) # Form string for the event..\neg.TriggerEvent("Serial." + string) # Trigger the event.')
</Action>
</Macro>
<Macro Name="Example_send">
<Action>
EventGhost.PythonCommand(u'eg.TriggerEvent("mycommand", payload="000000")')
</Action>
</Macro>
<Macro Name="Example_receive">
<Action>
EventGhost.PythonCommand(u'eg.TriggerEvent("mycommand", payload="000000")')
</Action>
<Action>
Serial.Read(4, 1.0)
</Action>
<Action Name="Handle_return">
EventGhost.PythonScript(u'#Script that handles the return values\n#read data is in eg.result variable\nprint "Return value: " + eg.result')
</Action>
</Macro>
</Folder>
</EventGhost>
I made a little python script that generates the checksum automatically. It's made so that the script generates an eg action whenever it is used, which is picked up by the serial plugin that will then send the data.
To use the script make a "Python Command" action and input this in the text field:
"eg.TriggerEvent("mycommand", payload="01FF0A")". The "mycommand" is the name of an action in the same macro as your script in order to trigger it. Notice the payload="", this is where you input your command to send as HEX. So for example payload="01FF0A" is (in decimal form) command byte=1, address byte=255, data byte=10.
Next you may want to create a python script in EG to handle any return values. You should put the python command you use to send data and immediately after that use the 'read data' action of the serial plugin and then immediately after that a python script. The data read from the serial port will be available in the eg.result variable.
You should be able to to make a script to handle the return data if needed, it should be very similiar to what we've done just above..
* I don't take any responsibility if you do any damage with that relay board of yours with any of this.. Hopefully you can make it from here.
PS. I didn't test any of this so I wouldn't be too surprised if there are errors in it..
-jinxdone