Pyserial读取数据但不写入

时间:2015-02-19 14:20:32

标签: python pyserial

我有一个Digi Transport WR41蜂窝路由器,运行它自己的专有操作系统和Python 2.6解释器。路由器有一个串口(RJ45),我已连接到Windows 7 PC上的串行端口(DB9)。电缆布线是直通配置。

在PC上,我已安装RealTerm Serial Capture program并将其连接到COM1

我希望能够使用python(和pyserial)通过串行连接读取/写入数据。

我的python脚本非常基础:

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

当我从RealTerm发送数据时,我可以通过ser.read(1000)在python中读取它。这一整天都在运作。

但是,当我尝试通过ser.write('hello world')从python发送数据时,我无法在RealTerm中看到它。

认为这可能是RealTerm问题,我在PC上尝试了其他模拟器/捕获程序:TeraTermSerial Port Monitor 6(由Eltima提供),但我从未看到数据显示

Serial Port Monitor 6是唯一一个显示某种排序活动的程序,但我仍然没有看过我的数据。我对串行通信知之甚少,无法对输出有所了解,但这里有一段摘录:

[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) 
----------------------------------------------------------------------------------

路由器有Bytes Sent的计数器。每当我调用ser.write('hello world')时,我都会看到它以正确的字节数递增。

我在SO上看了两个类似的问题:

我已经验证了设备,RealTerm和python代码对波特率,奇偶校验,停止位,控制流等具有一致的设置。

为什么与pyserial的串行通信只能以一种方式工作的任何其他想法?为什么会允许读取而不是写入?

1 个答案:

答案 0 :(得分:0)

  

当我从RealTerm发送数据时,我可以通过ser.read(1000)在python中读取它。这一整天都在运作。

     

然而,当我尝试通过ser.write('hello world')从python发送数据时,我无法在RealTerm中看到它。

你确定你可以发送'hello world'吗?这可能只是过滤了吗? 您是否尝试过其他命令或至少其他编码格式?

相关问题