Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

[Solved] Conrad Relais Card on Serial Port

If you have a question or need help, this is the place to be.
Post Reply
mannyk
Posts: 4
Joined: Sun Aug 24, 2008 9:03 pm

[Solved] Conrad Relais Card on Serial Port

Post by mannyk »

Hello,
I have read the Wiki about the Serial Port Plugin, but I still have no clue how to control my card with EG.
The problem for me is, that I don't know what I have to send to my card.

I think here is the information, how the card can be controlled:
Commands and replies consist, in each case, of a series of 4 bytes.
In the following, we refer to these subsequently as frames.

Frame Organisation: Byte 0: Command, Byte 1: Board address, Byte 2: Data, Byte 3 Test sum
Here is the whole documentation of the card:
http://www.thomas-dohl.de/docu/Handbuch.pdf

I have been trying to control my card with EG for a long time now. So if anyone has a hint for me, I would be really thankfull.
Regards,
mannyk
Last edited by mannyk on Tue Aug 26, 2008 12:35 pm, edited 1 time in total.
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Conrad Relais Card on Serial Port

Post by jinxdone »

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
mannyk
Posts: 4
Joined: Sun Aug 24, 2008 9:03 pm

Re: Conrad Relais Card on Serial Port

Post by mannyk »

Hello,
thank you for your great post.

I tried to control the card with the Serial Port plugin. The properties of the connection are, as stated by you and in the documentation.
Image

Also, the card is not damaged and properly connected (I can also work with the card in the program Conrad LeC. This works perfectly).

However, it does not in EG. I have sent the code for the first Relais ("\0x03\0x00\0x01\0x02") but nothing happened.
I also installed a software to monitor the serial Port (Serial Monitor 4.0). When using the LeC-Software and successfully turning on the first Relais the data "03 01 01 03" was sent.

I tried to sent the same data with EG (in this format and with \0x) but again, nothing happened.
I have not tried your code till now, but I will do so. However, I think a primitive action like turning on one relais should have also worked by now.

Do you have any other idea, why the card remains silent?
Kind regards,
manuel
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Conrad Relais Card on Serial Port

Post by jinxdone »

It seems you are using an old version, please update to the latest nightly version of eventghost. (0.36 build 1449). The latest version will have the 'HEX' option in the serial plugin configuration dialog that I was talking about.

http://www.eventghost.org/downloads/



For testing, try it out with the string "\x03\x01\x01\x03" using the 'Write data' action, you'll hopefully have better results. :)

---

About the more advanced stuff:

The whole point of the custom script is so that it calculates the checksum automatically, as it'd be quite laborious to manually figure it out each time you want to input a new command.

Now, if you want to send the same data "03 01 01 03" using the example script, you should use the command:
eg.TriggerEvent("mycommand", payload="030101")
mannyk
Posts: 4
Joined: Sun Aug 24, 2008 9:03 pm

Re: Conrad Relais Card on Serial Port

Post by mannyk »

Thank you for that hint!

Now it finally works!
Unfortunately, the message code depends on the state of the card.
I am currently able to switch on the 1st, 3rd, 4th, 6th, 7th, 8th relais (all in all 8).
However, if I switch on one of them the other one (which was switched on before) gets switched off. So its just possible for me having switched on only one single relais.

I have tested that with Serial Monitor and LeC with different combinations and it seems to be very complicated.

Would your script which calculates the checksum fix that?
I have been able to paste it into a xml file for EG with my previous version. The current version does not seem to accept it.

Regards,
manuel
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Conrad Relais Card on Serial Port

Post by jinxdone »

No, I don't think my little checksum script will help with that, however it's easier to use that than to calculate the checksums manually.

And you should be able to copy & paste the xml snipplet into EG, atleast I can paste it fine.


--

And about the commands, again as the manual says..
Commands 02 and 03 - set and read ports
These instructions refer to the relay of the board. Bit 0 in the data value corresponds to relay 1 (terminal KL1), bit 1 with relay 2 (terminal KL2) etc.
So in other words, when you use the set or get command, each relay has it's own bit inside the byte. Maybe this example will make it easier to understand the bit values:

Code: Select all

Binary    int    hex    relay #
---------------------------------
00000000 | 0   | 0x00 | no relay selected
00000001 | 1   | 0x01 | relay 1
00000010 | 2   | 0x02 | relay 2
00000100 | 4   | 0x04 | relay 3
00001000 | 8   | 0x08 | relay 4
00010000 | 16  | 0x10 | relay 5
00100000 | 32  | 0x20 | relay 6
01000000 | 64  | 0x40 | relay 7
10000000 | 128 | 0x80 | relay 8

1  0   0   1   0  0  1  0 = selects relays 8, 5 and 2
^          ^         ^
128   +    16   +    2   = 146 (in hex value = 92)
So if for example you want to switch the state of relays 2, 5 and 8 you would issue the command "03019290", where:
03 - command = set relay
01 - address of circuit board, as set with the initialization command
92 - target relays 2, 5 and 8
90 - parity byte for this particular command


I hope you are now getting the hang of it, just keep the manual handy and make sure you have a plentiful supply of coffee. ;)

-jinxdone
mannyk
Posts: 4
Joined: Sun Aug 24, 2008 9:03 pm

Re: Conrad Relais Card on Serial Port

Post by mannyk »

Hiho,
I want to thank you for your final hint!

I now made a script that is able to handle the card.
Perhaps, there will be someone else, who could need it ;-)
Attachments
conrad_relais_board.xml
(9.06 KiB) Downloaded 392 times
Post Reply