Author Topic: Sending and receiving on the rs232 line  (Read 12769 times)

pe700

  • Newbie
  • Posts: 1
  • I'm a llama!
    • View Profile
Sending and receiving on the rs232 line
« on: August 07, 2008, 10:56:12 AM »
Have a few questions about rs232 communication. I have written a Labview program to receive data from the T100MD+. I am receiving the analog values and digital inputs fine.  I would
like to send the status of a few relays from the T100 over the rs232 line. I know how to send the Input status by the command, example-STR$(INPUT[1]).  Can relay status be sent over rs232 line?

When I send a string of data or numbers from my Labview application how can I parse these numbers in the PLC program? I would like to input the numbers into the DM[] registers so I can act on them in the PLC program.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Sending and receiving on the rs232 line
« Reply #1 on: August 07, 2008, 03:03:52 PM »
Yes, internal relays status can be accessed using the RELAY[1]...RELAY[32]. Each RELAY[n] variable represents 16 relay bits.

If you send data from labview to the PLC via RS232, then you can read the data using either INPUT$(1) command (if it is terminated by carriage return) or INCOMM(1)  to accept binary number. You can then use TBASIC language to parse the data. For ASCII string it is quite simple - use the MID$() function to extract a string fragment from the received string and VAL() or HEXVAL() command to convert these string into numbers and you can then store them in DM[n] memory.

If the data is binary then you need to read them one byte at a time and store them into DM first and then parse the data in your program.

There is an excellent example on how to use TBASIC to send and receive MODBUS RTC Function 04 command. This involves using the INCOMM, OUTCOMM commands to implement the MODBUS RTU protocol and how to parse binary data received from a MODBUS slave. (Note: TBASIC already has special built-in commands to handle Modbus protocol, but the example shows how to do it with just pure TBASIC alone without using the special command):

http://www.tri-plc.com/yabbse/index.php?board=2;action=display;threadid=298

Email: support@triplc.com
Tel: 1-877-TRI-PLCS