【发布时间】:2019-02-22 20:00:38
【问题描述】:
Beaglebone Black Wireless:Ubuntu 16.04,
计算机:Ubuntu 16.04,
Python 3.5.2
我正在尝试使用 Beaglebone Black 通过 Modbus 与设备通信。我读过有人使用minimalmodbus 使用 USB/RS485 加密狗做同样的事情。我试过改变设置;每种可能的波特率、较短的电缆等。Beagle 中必须有一些东西需要配置/错误配置用于此类工作。
代码
#!/usr/bin/env python
# -*- coding; utf-8 -*-
import minimalmodbus
import serial
import time
i = minimalmodbus.Instrument(port='/dev/ttyUSB0', slaveaddress=1, mode='rtu')
i.serial.baudrate = 115200
i.serial.bytesize = 8
i.serial.parity = serial.PARITY_EVEN
i.serial.stopbits = 1
i.serial.timeout = 1
i.handle_local_echo = None
while True:
try:
print(i.read_registers(2008, 2, 3))
except serial.serialutil.SerialException as error:
print(error)
except FileNotFoundError as error2:
print(error2)
except IOError as error3:
print(error3)
time.sleep(1)
...使用USB/RS485 加密狗。使用这个加密狗/代码组合在我的计算机上(过去 4 个月)产生了完美的结果,但在今天的 Beagle 上却没有。
计算机:收到消息:
[0, 0]
Beagle:收到错误:
IOError: No communication with instrument (no answer)
我正在寻找可能的故障排除途径。我已经验证了电缆不是太长,并且 USB 加密狗是可以的。我也排除了任何代码问题。
编辑 1:
忘记包含lsusb 和ls /dev/ttyUSB*:
Bus 002 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 002 Device 003: ID 04d9:0024 Holtek Semiconductor, Inc.
Bus 002 Device 002: ID 0409:0059 NEC Corp. HighSpeed Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
和
/dev/ttyUSB0
编辑 2:
我能够使用pyserial 并短接 Rxd 和 Txd + 和 - 端子来实现环回设置。
编辑 3:
我已经尝试了所有可能的接线配置。计算机上只有一种配置有效(Tx+ -> A 和 Tx- -> B)。在使用minimalmodbus 调试功能时,我可以看到相同的消息正在发送到 Beagle 上的设备和计算机 ('\x01\x03\x07Ø\x00\x02ED' (01 03 07 D8 00 02 45 44)
)。计算机收到响应,而 Beagle 没有。
Beagle 可以轻松地将适配器安装到 /dev/ttyUSB0。
编辑 4:
@Carlo Zanocco 请求输出ls /dev/ | grep tty
tty
tty0
tty1
tty10
tty11
tty12
tty13
tty14
tty15
tty16
tty17
tty18
tty19
tty2
tty20
tty21
tty22
tty23
tty24
tty25
tty26
tty27
tty28
tty29
tty3
tty30
tty31
tty32
tty33
tty34
tty35
tty36
tty37
tty38
tty39
tty4
tty40
tty41
tty42
tty43
tty44
tty45
tty46
tty47
tty48
tty49
tty5
tty50
tty51
tty52
tty53
tty54
tty55
tty56
tty57
tty58
tty59
tty6
tty60
tty61
tty62
tty63
tty7
tty8
tty9
ttyGS0
ttyS0
ttyS1
ttyS2
ttyS3
ttyS4
ttyS5
ttyUSB0
编辑 5:
stty -F /dev/ttyUSB0 -a的输出:
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 0; time = 0;
parenb -parodd -cmspar 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 -flusho -extproc
【问题讨论】:
-
编辑您的问题并在控制台窗口中显示
lsusb的输出。 -
请贴出Modbus设备名称并检查接线是否正确(包括终端电阻)
-
@CarloZanocco 该设备是具有 Modbus 功能的工业科里奥利流量计。接线正确;如果不是,它可能无法在我的计算机上运行,如问题中所述。此外,此设置中没有终端电阻。
-
@star_trac 你能发布这个命令的输出吗:“ls /dev/ | grep tty”。还使用库 pyserial 测试串口并检查发生了什么
-
@CarloZanocco 命令
ls /dev/ | grep tty返回与ls /dev/ttyUSB*相同的内容,就像在问题中一样。另外你是什么意思“测试串口”?我不确定如何使用 pyserial 测试端口。我可以尝试通过 pyserial 通过/dev/ttyUSB0建立连接,这是我绝对可以做到的。
标签: python serial-port beagleboneblack beagleboard minimalmodbus