RS232 Programming/Steps Example Desired

Hi All,
Is there any example that goes into detail on RS232 Communication Programming for the Opto22 programming language? Specifically, I’m looking for:

  1. Recommended programming procedure/methodology for how the Opto22 system likes RS232 (i.e. First open comms, then check # of characters, etc).

  2. A very simple example of RS232 communication (both transmit and receive). If the example is in flowcharts, the underlying commands in the flowchart blocks should be shown/discussed.

I’ve looked through the Opto22 literature, but it seems a bit sparse on pertinent underlying details.

Thank You, Gordon

Hi Gordon,

Welcome to the forums!

There are a couple of different ways to do this, but most likely you’ll want to look at the PAC Control User’s Guide (form 1700) for starters and use a communication handle in your strategy. Chapter 10 has a section called “Communication Commands.”

Are you using the built-in 232 port on the controller itself, or a serial module plugged into the rack? The built-in port would have a comm handle value something like: “ser:0,115200,n,8,1” (port 0, baud rate of 115,200, no parity, 8 data bits, and 1 stop bit) and a serial module would start with “tcp:” followed by an IP address and port number of that module. Details in form 1700.

Typically the commands you’d use would be “Open Outgoing Communication” followed by something like: “Transmit String” (I just wrote a chart that did just those two commands, the second in a loop, to blast out messages over and over).

For the receiving part, as you suggested, you’d likely use “Get Number of Characters Waiting” most likely in a loop with a delay. When that number waiting is enough for your purposes, you might use “Receive N Characters” before you start parsing the incoming data. That’s it!

Depending on the data that’s coming in and how values are separated, you can leverage the EOM (end of message) character to parse data as you receive it – for example using the “Receive String Table” command. This can be a lot quicker than writing your own logic for parsing.

What does your incoming data look like and what will you do with it? (Just curious!)

-OptoMary

Hi Mary,
Thank you very much for the reply. Answers to your questions/comments are:

  1. I’m currently using a SNAP-SCM-232 Serial Module plugged into the rack.

  2. I’ll make transmit string chart (like you did) and try that out.

  3. I’ll fiddle with a receive chart as you suggest also. That will get me some experience with working with OPTO 22 string commands.

  4. I would greatly appreciate an OPTO22 example of parsing the data assuming a EOM character.

  5. I had not gotten to the point of even looking to see what the incoming data looks like. I’m still at the “Programming RS232 on the OPTO22 for Dummies” level. The final result of my work will be to create an automated battery cycling machine. The OPTO22 system will command/control a Chroma Battery Load (RS232 controlled), Sorenson Power supply (RS232 controlled) and associated battery contactors along with voltage/amperage sensing.

Ok, I created a simple Transmit String chart using the Transmit String command and a literal string variable. The OPTO module is transmitting this string (verified by using Hyperterminal plugged into the output of the RS-232 module). I have a small problem however. I can’t get the string to command a line feed/end of line/new line command. I’ve tacked on a <nl> to the string command (as recommended by the Chroma Test machine literature) but that does not seem to help. The command I’m sending to the machine is: CONF:REM ON , which is a command to the machine to go into “remote” mode. This command is being sent (as shown by Hyperterminal) but no line feed is being sent. I have verified (using Hyperterminal to the Chroma test machine via RS232)that the machine does respond to RS232 command if they are sent correctly.

So how do I get a line feed sent separately OR appended to the literal string transmitted by the “transmit string” command?

Thank You, Gordon

Hi Gordon,

I’m glad your getting some strings moving. On the message termination thing, good question. The comm handle’s EOM (End of Message) character is NOT transmitted by the TransmitString command (I had to look in the help for that one, the TransmitStringTable command DOES send the EOM between strings. FYI, the EOM is configurable and has a default of 13, CR).

Anyway, before sending TransmitString you can use “Append Character to String” and append 10 (for your Line Feed character). The equivalent Optoscript might look something like this:
[B]Command_String += Chr(10);[/B]

Although I noticed you mentioned a “literal string.” To use “Append Character to String” you’d need to put your command in a string variable.

Or, you could also use the “Transmit Character” to send just the 10 if you wanted.

I hope that helps!

-OptoMary

Hi Gordon,

I’m glad your getting some strings moving. On the message termination thing, good question. The comm handle’s EOM (End of Message) character is NOT transmitted by the TransmitString command (I had to look in the help for that one, the TransmitStringTable command DOES send the EOM between strings. FYI, the EOM is configurable and has a default of 13, CR).

Anyway, before sending TransmitString you can use “Append Character to String” and append 10 (for your Line Feed character). The equivalent Optoscript might look something like this:
[B]Command_String += Chr(10);[/B]

Although I noticed you mentioned a “literal string.” To use “Append Character to String” you’d need to put your command in a string variable.

Or, you could also use the “Transmit Character” to send just the 10 if you wanted.

I hope that helps!

-OptoMary

Hi All,

Here’s a similar request and some sample code from another thread:
http://www.opto22.com/community/showthread.php?t=112
(using the built-in port rather than a 232 module, but the concept is the same).

I’ve also attached an example (must have PAC Control 8.2 or newer) that has a little less OptoScript than the example in the link above, for those of you not yet comfortable w/OptoScript. There’s a little OptoScript block, mostly comments, where I show how to use the EOM (End Of Message) character to parse data as it comes in.

-OptoMary

SerialDemo.Archive.ver1.zip (6.18 KB)

Hi,
Somebody can I help me, I need communication of SNAP PAC-R2 and card reader TRANSIT by Nedap - Leading platform for automatic vehicle identification, I review te example but I dont recieve anything data.

Hello macroabril,

Welcome to the OptoForums!

Please read this Comm Handle 101 post, especially the “debugging techniques” section, and the “comm errors” section just below that. Those two sections will show you how to can figure out: did your comm handle “open” okay? If not, what error came back? If so, did the comm handle “see” any characters?

Also remember our support is free! (Best to reach them via email, at support @ opto22.com, and include answers to those questions.

Thanks,
-OptoMary