Reading command status w/usb, rpi, and python

Hi, I’m trying to read back command status use the USB interface with rpi and python.
The command executes. However, the query blocks when trying to read the result.
The query succeeds when executed using screen.

Start command here

d_node = open("/dev/sec_32u", “rb+”)
d_node.write(“Q\n”)
stat = d_node.read(1) <- Blocks here
print stat

Hi,

We are unsure what your issue might be with so little information. It would be easier to help you with your issue if you could provide more information about the situation:

  1. What model is your Raspberry Pi?
  2. Which OS are you running on it? What customizations did you make?
  3. What is your Raspberry Pi connected to (brand, model, revision etc.)? What type of connection does it offer? Do you have any datasheet of the product or other information on its communication protocol?
  4. What does “/dev/sec_32u” refer to? Have you tried using “r+” instead to connect to it?

Sincerely,

  1. What model is your Raspberry Pi?

This is a raspberry PI 1 Model B
docs-europe.electrocomponents.co … 27da4b.pdf

  1. Which OS are you running on it? What customizations did you make?

pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux
No major modifications

  1. What is your Raspberry Pi connected to (brand, model, revision etc.)? What type of connection does it offer? Do you have any datasheet of the product or other information on its communication protocol?

Connected to SSC-32U with firmware 2.50USB using the USB port, no changes to the default configuration.

  1. What does “/dev/sec_32u” refer to? Have you tried using “r+” instead to connect to it?

/dev/sec32_u is a softlink to the device /dev/ttyUSB0, the ssc_32u device.

The device is read/writeable and executes “#0P1.5S750” and “Q\n” with GNU screen “screen /dev/sec_32u”. This seems to indicate that the device/connections are good.
Are the serial port parameters important here?

pi@raspberrypi ~ $ stty -F /dev/sec_32u -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^H; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

^ Serial port parameters after screen exits.

Can you provide an image or two of the setup which clearly show the connections?
The serial port parameters are very important.
Not sure why “#0P1.5S750” would work - should be “#0P1500S750”.

Hi,

Thank you for all the information.

The SSC-32U is by default set to 9600 baud, 8N1 settings for the virtual serial port over USB. When you establish a connection using screen what is the result if you send the command “ver”? You should receive a response containing the version of the firmware on the device.

We have tried a small example using Python’s open function and also using the py-serial library (recommended for serial port stuff) and it seems to block too. We investigated a bit further and the input buffer seems to be empty after sending “ver” to the SSC-32U (we tried this with both Python 2.7 and Python 3.X). But, it also seems like the SSC-32U is able to receive commands sent by the Python code.

Since the SSC-32U seems to respond properly over the screen utility, it would indicate a problem with Python to properly interact (receive buffer always empty) with the virtual serial port over USB. We recommend that you check for more support from the Python maintainers and community.

Sincerely,

Screen output:
ver
SSC32-V2.50USB

I have also experimented with py-serial which also blocks.
Are there other specific serial settings, that could be in play here?
For example xonxoff or rtscts?

Since the serial port of the SSC-32U is a virtual serial port, there is no other settings that should be required (hardware flow control and such are usually ignored).

Also, because the card receives & sends data properly over the port using screen, it seems to indicate the issue is not with the SSC-32U, the serial port or your Linux kernel / drivers / setup but with Python and its libraries.
Another way to see it is this: you have the following setup: You code > Python interpreter / Python libraries > Linux > Hardware / Peripherals > SSC-32U and everything in there works except the part between your code and the operating system. We recommend that you try accessing the port using a different programming language / runtime environment. Maybe make a small test using C ?