Pyserial reads data but does not write

1

I have a Digi Transport WR41 cellular router that runs a it's own proprietary operating system and a Python 2.6 interpreter. The router has a serial port (RJ45) that I've connected to a serial port (DB9) on a Windows 7 PC. The cable wiring is a straight through configuration.

On the PC, I've installed RealTerm Serial Capture program and connected it to COM1.

I want to be able to read/write data through the serial connection using python (and pyserial).

My python script is very very basic:

import serial
ser = serial.Serial(port=0, baudrate=9600, parity=serial.PARITY_EVEN, timeout=1)
ser.write(‘hello world’)
#ser.read(1000)

When I send data from RealTerm, I can read it just fine in python via ser.read(1000). This works all day long.

However, when I try to send data from python via ser.write('hello world'), I am unable to see it in RealTerm.

Thinking it might be a RealTerm issue, I tried other emulator/capture programs on the PC: TeraTerm and Serial Port Monitor 6 (by Eltima), but I never saw the data show up.

Serial Port Monitor 6 was the only program to show some sort activity, but I still never saw my data. I don't know enough about serial communication to make any sense of the output, but here is an excerpt:

[19/02/2015 07:58:21] 
435 IRP_MJ_DEVICE_CONTROL - Request operates a serial port (COM1) 
    STATUS_SUCCESS 
        IOCTL_SERIAL_WAIT_ON_MASK - Request is used to wait for the occurrence of any wait event specified by using an IOCTL_SERIAL_SET_WAIT_MASK request 
            Mask - 0x00000010 (EV_DSR) 
---------------------------------------------------------------------------------- 
[19/02/2015 07:58:21] 
437 IRP_MJ_DEVICE_CONTROL - Request operates a serial port (COM1) 
    STATUS_SUCCESS 
        IOCTL_SERIAL_GET_WAIT_MASK - Request returns the event wait mask that is currently set on a COM port 
            Mask - 0x00000119 (EV_CTS | EV_DSR | EV_RING | EV_RXCHAR) 
---------------------------------------------------------------------------------- 
[19/02/2015 07:58:21] 
439 IRP_MJ_DEVICE_CONTROL - Request operates a serial port (COM1) 
    STATUS_SUCCESS 
        IOCTL_SERIAL_GET_MODEMSTATUS - Request updates the modem status, and returns the value of the modem status register before the update 
            Modem Status - 0x00000080 (MS_RLSD_ON) 
----------------------------------------------------------------------------------

The router has a counter for Bytes Sent. Every time I call ser.write('hello world'), I see it increment by the correct number of bytes.

I've looked at two similar issues on SO:

I've verified that the device, RealTerm and the python code have consistent settings for the baudrate, parity, stopbits, control flow, etc.

Any other ideas why serial communication with pyserial would only work one way? Why would reads be allowed but not writes?

python
pyserial
asked on Stack Overflow Feb 19, 2015 by John Russell • edited May 23, 2017 by Community

1 Answer

0

When I send data from RealTerm, I can read it just fine in python via ser.read(1000). This works all day long.

However, when I try to send data from python via ser.write('hello world'), I am unable to see it in RealTerm.

Are you sure that you can send 'hello world' maybe this is just filtered ? Did you try with another command or at least another encoding format?

answered on Stack Overflow Feb 19, 2015 by PyNico • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0