Jump to content
OMRON Forums

Use RS232 Port for serial communication from PLC


jhendges

Recommended Posts

Is it possible to use the RS232 port on a Power PMAC inside a PLC? I would like to communicate to a device over the RS232 port if possible. If so, is there any examples of how to configure the port settings, open the port, and send a command?

 

I'm fairly certain this can be done from a background program, which would be acceptable, however it would be beneficial if this could be done through a PLC instead.

 

Thanks!

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

The powerpmac has /dev/ttyS0 tied to a linux console but you can turn it off with the following.

Comment the line in /etc/inittab line that has ttyS0

This command will do it

 

sed -i 's/T0:23/#T0:23/g' inittab

 

Now kill the linux init process so it doesn't come back with the following command

 

init q

 

 

Go here http://papers.mpastell.com/serial.pdf and learn how to use the serial port over the linux console and you can do the following in a PLC

 

 

open plc 1

if(p1==1)

system"`echo Hello There >/dev/ttyS0`"

p1=0

close

 

 

Alternatively you can use a USB to RS232 converter in that case change /dev/ttyUSB0

Link to comment
Share on other sites

The powerpmac has /dev/ttyS0 tied to a linux console but you can turn it off with the following.

Comment the line in /etc/inittab line that has ttyS0

This command will do it

 

sed -i 's/T0:23/#T0:23/g' inittab

 

Now kill the linux init process so it doesn't come back with the following command

 

init q

 

 

Go here http://papers.mpastell.com/serial.pdf and learn how to use the serial port over the linux console and you can do the following in a PLC

 

 

open plc 1

if(p1==1)

system"`echo Hello There >/dev/ttyS0`"

p1=0

close

 

 

Alternatively you can use a USB to RS232 converter in that case change /dev/ttyUSB0

 

I didn't put the full path for the inittab since I tested this from the etc directory. You should probable change inittab to /etc/inittab. Also there is no way to get rid of the initial data that comes out the serial port. Some of it is from the bootloader so if the device cannot handle useless information you will have to use a USB to RS232 converter.

 

sed -i 's/T0:23/#T0:23/g' /etc/inittab

Link to comment
Share on other sites

On an unrelated note, but related to my application, is there support for regular expressions in a PLC, or just a background C application?

 

Can you rephrase this? It is not clear to me what you want to do. An example would help us answer this.

Link to comment
Share on other sites

I would like to use regular expressions in a PLC if possible. Example code from a VB.NET application looks like this:

 

Dim measurement As Integer = CInt(Regex.Match(response, "\d+").ToString)

 

Apparently you can also do this in C in a POSIX system, though regular expressions are not native to ANSI C.

Link to comment
Share on other sites

Hi,

 

I'm still not totally clear as to what you want, but if you just want to dynamically form strings, you can use the sprintf() function. It's part of stdio.h, automatically included in PPMAC's C header files. After forming the string, you can send it to PPMAC's text parser with the Command() command, or with GetResponse(), or a number of other functions that are specifically intended for getting or setting variables (go to the Help function in the IDE and click Index, then type in Get or Set under "Look for:" and you will see them listed).

 

If that's not what you mean, please clarify further.

Link to comment
Share on other sites

  • 6 months later...

Using the ttyUSB0, I can send data all day long without a problem. Is there any good way to get data back into the PLC so I can use a value that will be returned on the serial port? I would like to get that value back into PMAC.

 

 

The powerpmac has /dev/ttyS0 tied to a linux console but you can turn it off with the following.

Comment the line in /etc/inittab line that has ttyS0

This command will do it

 

sed -i 's/T0:23/#T0:23/g' inittab

 

Now kill the linux init process so it doesn't come back with the following command

 

init q

 

 

Go here http://papers.mpastell.com/serial.pdf and learn how to use the serial port over the linux console and you can do the following in a PLC

 

 

open plc 1

if(p1==1)

system"`echo Hello There >/dev/ttyS0`"

p1=0

close

 

 

Alternatively you can use a USB to RS232 converter in that case change /dev/ttyUSB0

 

I didn't put the full path for the inittab since I tested this from the etc directory. You should probable change inittab to /etc/inittab. Also there is no way to get rid of the initial data that comes out the serial port. Some of it is from the bootloader so if the device cannot handle useless information you will have to use a USB to RS232 converter.

 

sed -i 's/T0:23/#T0:23/g' /etc/inittab

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...