LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Reading ASCII PLC data from a usb/serial connection (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/reading-ascii-plc-data-from-a-usb-serial-connection-737762/)

searchingfortao 07-04-2009 05:20 PM

Solved: Reading ASCII PLC data from a usb/serial connection
 
Hi there, I've been commissioned to write an embedded Linux component of a larger, more complicated machine and I'm having real trouble reading data from an Automation Direct "Click" PLC.

The PLC was programmed by someone-not-me to send an ASCII string over a serial connection every time a button was pushed. My code would then read said data from the serial connection and do a bunch of interesting stuff.

The PLC is doing its job, because if I connect a Windows laptop to the serial-to-usb cable and connect to it with Putty, I see the aforementioned output.

The trouble comes when I try this with Linux. Using the very same settings are were used on the Windows machine, I only *sometimes* see the output. I'm at the end of my rope here and I'm coming up empty.

I've tried using minicom, which insists that I'm always "Offline", and I've written a simple Python script to use the same settings with the same results. The settings I'm using are:

Code:

ser = serial.Serial(
  "/dev/ttyUSB0",
  baudrate=38400,
  parity=serial.PARITY_ODD,
  stopbits=serial.STOPBITS_ONE,
  bytesize=serial.EIGHTBITS,
  rtscts=0,
  xonxoff=1,
  timeout=None
)

Or in other words 38400 801. I *believe* that I have the rtscts and xonxoff settings right but I really can't be sure.

In terms of modules, I've made sure that there are no modules loaded, and then I run the following:

Code:

modprobe usbserial vendor=0x067b product=0x2303
modprobe pl2303

I got the vendor and product codes from dmesg when the PLC was connected via USB the first time.

So, that's all I have... please tell me that someone out there understands what I'm doing wrong?

searchingfortao 07-05-2009 06:05 PM

Figured it out
 
Turns out that you don't always need to pass arguments to usbserial as I have above. I thought you did since usbserial was being used by another device on this machine and that one did need the extra arguments. Providing them in this case seems to just have broken it :-(

To make it work, all I had to do was make sure that no related modules were loaded and then run:
Code:

modprobe pl2303
. That loaded usbserial and everything Just Worked.


All times are GMT -5. The time now is 08:06 AM.