Sending HEX to RS232

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Dan, Jan 16, 2020.

  1. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    Hello all.

    Wondering if someone could help.

    I'm trying to send a HEX string via the RS232 port on my Pascal unit. This is the code I have -

    {RS232}
    once (GetCBusState("local", "Logic Groups", "RS232 Test") = ON) then
    begin
    OpenSerial(1, 7, 9600, 8, 1, scNoFlowControl, scNoParity);
    WriteSerial(1, 55 56 00 00 00 03 02 B0);
    CloseSerial(1);

    end;

    I get compile errors of :

    Error C006 at line 61:21 - Illegal symbol
    Error C006 at line 61:24 - Illegal symbol
    Error C006 at line 61:27 - Illegal symbol
    Error C006 at line 61:30 - Illegal symbol
    Error C006 at line 61:33 - Illegal symbol
    Error C006 at line 61:36 - Illegal symbol
    Error C006 at line 61:39 - Illegal symbol
    Error C104 at line 61:39 - Identifier is not declared

    Can the unit send a HEX code directly or is there some trickery involved.?

    Thanks!
     
    Dan, Jan 16, 2020
    #1
  2. Dan

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    You just need to put apostrophes either side of your HEX string. Pascal doesnt care what you are sending, but you need to encapsulate the message so it knows what to send.

    Have a look at page 196 of the Logic Manual (You can find a PDF version in your PICED/Manuals folder)

    "
    Example
    To write a string s to serial port number 2 :
    WriteSerial(2, s);
    To write the string 'stop' terminated with a carriage return character to serial port 1 :
    WriteSerial(1, 'stop'#13); "
     
    jboer, Jan 16, 2020
    #2
  3. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    This depends on whether you are trying to write hex data or binary. Binary is a raw 8 bit value. Hex is 2 ascii digits that encode each 4 bits of a byte using the characters 0-9 and A-F.

    If it's binary you need:

    WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0);

    Here # tells the compiler to build an 8 bit binary value out of the following ascii characters. The $ tells it the characters represent a hex value (the default is decimal)

    If it's hex you need:

    WriteSerial(1, '55560000000302B0');

    This is just an ascii string that is output as is.

    The documentation may tell you which one you need.

    People get very confused between binary and hex and documentation often uses the incorrect description.
     
    Ashley, Jan 16, 2020
    #3
  4. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    Thanks for the reply. I knew it would be something simple I was missing.

    I now have some new errors. The code compiles but there is a new error in PICED when I trigger the condition to run -

    EDIT:

    I also tried

     

    Attached Files:

    Dan, Jan 16, 2020
    #4
  5. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    When running from PICED you need to select the actual com port you are using on your PC. You probably don't have a COM1:

    Also, you don't need to open and close the port each time. Just open it from the initialisation section and leave it open.
     
    Ashley, Jan 16, 2020
    #5
  6. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    PICED is connected to the CBUS network when it generates the error. I have also adjusted the logic code to select the correct COMM port.
    upload_2020-1-16_18-21-49.png

    As for the initialisation section, what are you refering to? Is there something else I need to do in the logic editor?

    Thanks!
     
    Dan, Jan 16, 2020
    #6
  7. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    When you run the logic in PICED, it runs on the PC, so it opens the serial port on the PC, not the target device.

    To test it in PCED, you need to connect your external serial device to a PC serial port and select the (com ) port in PICED.
     
    Ashley, Jan 16, 2020
    #7
  8. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    The logic has an initialisation section that is just run once on startup. You will see it in the left side list above the modules. Open the serial port in that.
     
    Ashley, Jan 16, 2020
    #8
  9. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    OK lets break this down into some individial steps.

    Whats the initialisation section, I have seen this in the logic window. Is it required? I just want to get it to send a command to begin with then I can make the code more efficient. This is one command of many I will set up.

    I have the device plugged into the PC, its on COMM port 7. I can control the device with Docklight with sending a command in the HEX window.

    I changed the logic in PICED to:

    once (GetCBusState("local", "Logic Groups", "RS232 Test") = ON) then
    begin
    OpenSerial(1, 7, 9600, 8, 1, scNoFlowControl, scNoParity);
    WriteSerial(1, '55560000000302B0');
    CloseSerial(1);

    end;

    It does not opperate the function on the device though. I don't have Docklight open when I'm trying with PICED either..
     
    Dan, Jan 16, 2020
    #9
  10. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    You open the serial port, send the data then immediately close the port. Thing is at 9600 baud it is going to take 16 mS to send the characters, but you are closing the port immediately after the send which will abort the operation so you are probably only getting a couple of characters out.

    With the serial port, you just open it once and use it. You only ever need to close it to change the configuration, which you rarely need to do.

    That's the whole point of the Initialisation section. It contains code that is only run once when the logic engine starts up. So you open the serial port in the initialisation section and just leave it open and just issue WriteSerial or readSerial commands to it in your module.

    I haven't used Docklight but it looks to me like what they call hex is really binary (I mentioned lots of people get this confused. Even people that should know better.)

    Try the

    WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0);

    version.
     
    Ashley, Jan 16, 2020
    #10
  11. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    OK so I removed the close port command and now have :

    ---------------------------------------------------------------------------------------------------

    once (GetCBusState("local", "Logic Groups", "RS232 Test") = ON) then
    begin
    WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0);
    end;

    Also tried;

    WriteSerial(1, '#$55#$56#$00#$00#$00#$03#$02#$B0');

    ---------------------------------------------------------------------------------------------------

    Nothing happens. Also, I have in the initialisation section I have put;

    ---------------------------------------------------------------------------------------------------

    {Enter Initialisation code here}
    begin
    OpenSerial(1, 1, 9600, 8, 1, scNoFlowControl, scNoParity);
    end;


    ---------------------------------------------------------------------------------------------------

    I am now trying this directly by uploading to the Pascal unit but not working.


    Thanks for the help so far!
     
    Dan, Jan 16, 2020
    #11
  12. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Firstly make sure the serial is being sent.

    Run PICED on the PC, display the log (VIEW/LOG), go to the options tab and select 'View Logic Serial Messages'

    Then trigger you code and make sure it appears in the log.

    If this works then either your command or the format you are using is wrong.

    WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0); looks correct to me given how Docklight seems to work under the HEX tab.

    (Your version with quotes is definitely wrong. Nothing works like that!)

    What device are your talking to? Can you post a copy of the command descriptions?
     
    Ashley, Jan 17, 2020
    #12
  13. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    The device is an 8 channel relay, same as the one here - https://www.amazon.com/Eletechsup-Channel-Remote-Control-Switch/dp/B07H8G8FSS?th=1 .

    The instructions for the unit are in a zip file here - https://1drv.ms/u/s!AjrAGEbCBLlsuXwHtex91_1wLTFs .

    [​IMG]

    I am using a RJ45 Male / RS232 Female Serial Console Configuration Cable;

    [​IMG]

    I am also using a RS232 gender changer as the board and cable female connections;

    [​IMG]

    OK so for '55 56 00 00 00 03 02 B0'

    WriteSerial(1, '55 56 00 00 00 03 02 B0');

    18/01/2020 11:21:36 AM Logic : COM8 Tx 55 56 00 00 00 03 02 B0 (Logic Line 62)
    18/01/2020 11:21:37 AM Logic : COM8 Rx Command Too Long<13><10>

    for WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0);

    18/01/2020 11:23:00 AM Logic : COM8 Tx UV<0><0><0><3><2><176> (Logic Line 62)

    no Rx..

    and for WriteSerial(1, '55560000000302B0');

    18/01/2020 11:26:16 AM Logic : COM8 Tx 55560000000302B0 (Logic Line 62)
    18/01/2020 11:26:17 AM Logic : COM8 Rx Command Too Long<13><10>

    In Docklight I get RX replys from the device when sending th hex.

    upload_2020-1-18_13-19-23.png
    upload_2020-1-18_13-19-38.png
    upload_2020-1-18_13-19-55.png
    upload_2020-1-18_13-19-46.png
     
    Last edited: Jan 18, 2020
    Dan, Jan 18, 2020
    #13
  14. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    I think one of my next steps might be to try a 24VAC power supply;

    "4.2 Connecting RS-232 Devices
    If you do not know whether the serial device you are connecting
    has control over the handshaking lines, simply try the device to see if it works. If not,
    connect the 24V a.c. power supply."

    I hooked up my PAC to my UDS1100 today and there is no output on the RS232 ports when the logic is triggered. I can see it in the log as above but the moitoring software shows no message being broadcasted out through the seruak port. I can monitor the port in the software.

    However when I plug in the USB to serial device that is able to control the relay into the same input of the UDS1100 I can see the messages being transmitted from the USB port of my PC back through to the USD1100.

    I think I may need power for the RS232 24VAC input of the PAC?

    This is the last thing I can think of trying.

    I can't however control the relay with the UDS1100. I can confirm though that the correct command is being broadcasted through the UDS1100 to the serial port as I have looped it back to the PC and monitored the port. Maybe this confirms I need the power to the port?;

    upload_2020-1-19_17-52-40.png
     
    Last edited: Jan 19, 2020
    Dan, Jan 19, 2020
    #14
  15. Dan

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    So WriteSerial(1, #$55#$56#$00#$00#$00#$03#$02#$B0); is definitely the correct format of the command for that device.

    If you can control the device from the PC using Docklight there is no reason why it shouldn't work from PICED running on the PC issuing the above command. given you can see PICED outputting the serial string. If it doesn't work from the PC you have something else setup wrong that I can't see.

    You always want to get serial devices working via PICED on a PC first before trying it from the target device.

    When running on the PAC you will most likely need the 24VAC supply as it is unlikely the relay module will provide power to the DTR control line. You can easily test that with a meter though.

    Not sure where the UDS1100 comes in? Are you using this from the PC via a virtual com port? You say it doesn't work but you can control the device via Docklight. What interface on the PC are you using for this?
     
    Ashley, Jan 19, 2020
    #15
  16. Dan

    Wonkey

    Joined:
    Aug 3, 2004
    Messages:
    395
    Likes Received:
    37
    Location:
    Adelaide
    Have you considered just changing your relay for a C-Bus ELV relay part no L5108RELVP
    If this a customer site then it would be cheaper given the cost of labour.
     
    Wonkey, Jan 19, 2020
    #16
  17. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    I'm using the UDS1100 just to confirm that the PASCAL unit is actually sending out a command or anything for that matter.

    I can confirm that my serial to USB device are broadcasting commands, not only does the device react but I can see the commands on the monitoring software when I swtich from the device to the UDS1100. (Remove DB9 plug from the relay and then plug the DB9 into the UDS1100)

    I not trying to see if the PAC is actually sending anything at all out through the serial port by transfering the PICED file to the unit. When I plug in serial port one of the PAC into the same port that the UDS1100 is monitoring, NOTHING is being sent out from the PAC when I turn on the group even though I can see the group being turned on in the toolkit log.

    I have a 24VAC power supply plugged into the pascal unit now also.

    I'm starting to think maybe the pascal unit may be faulty? I mean, even if the WriteSerial command is wrong in the logic file, if the group is turned on, the logic should open the port and send out something for me to see on the port that I'm monitoring. I'm not seeing anything at all even with the power supply :/.

    This is what is on the PASCAL unit at the moment -

    {Enter Initialisation code here}
    begin
    OpenSerial(1, 1, 9600, 8, 1, scNoFlowControl, scNoParity);
    end;

    In modules I have -

    once (GetCBusState("local", "Logic Groups", "RS232 Test") = ON) then
    begin
    WriteSerial(1, '#$55#$56#$00#$00#$00#$03#$02#$B0');
    end;
     
    Last edited: Jan 20, 2020
    Dan, Jan 20, 2020
    #17
  18. Dan

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    Try changing your COM port to 0

    OpenSerial(1, 0, 9600, 8, 1, scNoFlowControl, scNoParity);
     
    jboer, Jan 20, 2020
    #18
  19. Dan

    Dan

    Joined:
    Jan 17, 2018
    Messages:
    26
    Likes Received:
    6
    Thanks for the advise.

    Just tried it but no go. The relay doesnt respond, also when I swtich the same serial port to my UDS1100 which is being monitored with CPR Monitor, displays no read/writes.

    It doesn't seem to be doing anything. I have the 24VAC powered to it also.

    I'm going to contact Clipsal and see of one of their techs can help.

    Edit;

    Ok, so I have finally got PICED to send out the command, but, what it'se sending out isn't what appears on the monitoring port:

    20/01/2020 3:15:31 PM Logic : COM10 Tx #$55#$56#$00#$00#$00#$03#$02#$B0 (Logic Line 62)

    upload_2020-1-20_15-17-3.png


     
    Last edited: Jan 20, 2020
    Dan, Jan 20, 2020
    #19
  20. Dan

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    Oh also I have found when using serial on the PAC, after you transfer the code just make sure you do a restart of the PAC..

    Also I just did a job reading/writing serial to a PAC here are my screenshots, Im not writing HEX just an ASCII string:

    upload_2020-1-20_16-9-25.png


    upload_2020-1-20_16-10-27.png

    upload_2020-1-20_16-11-19.png
     
    Last edited: Jan 20, 2020
    jboer, Jan 20, 2020
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.