Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use RS232 Port for serial communication from PLC
#1
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!
Reply
#2
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
Reply
#3
(03-04-2013, 04:17 PM)hbausley Wrote: 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
Reply
#4
On an unrelated note, but related to my application, is there support for regular expressions in a PLC, or just a background C application?
Reply
#5
(03-06-2013, 09:16 AM)jhendges Wrote: 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.
Reply
#6
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.
Reply
#7
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.
Reply
#8
jhendges:

The Power PMAC uses glibc, which includes the POSIX regex library.

See: http://www.gnu.org/software/libc/manual/...sions.html
Reply
#9
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.


(03-04-2013, 04:49 PM)hbausley Wrote:
(03-04-2013, 04:17 PM)hbausley Wrote: 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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)