Beaglebone 黑色无线: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 dongle 没问题。我还排除了任何代码问题。
编辑 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
请您参考如下方法:
我遇到了同样的问题,结果是终止和流量控制的问题。
我尝试了不同的 USB 加密狗,所有这些都适用于 pc 和 mac,以及 BeagleBone 上的许多不同配置,但没有任何效果。
低成本的 USB 软件狗与 PC 配合得很好,但对于微 Controller ,例如 BeagleBone,您需要能够更好地处理总线规范的东西。
我发现一些简单且低成本的 TTL RS232 到 RS485 板无需在 BeagleBone 端进行任何特殊配置即可完美运行,因为它们会自动管理流量控制。 您可以搜索RS485 automatic flow control在 Ebay 或类似网站上。
由于 BeagleBone 上的默认串行端口已经耦合到系统控制台,因此您需要 enable another UART通过正确编辑文件/boot/uboot/uEnv.txt。
然后您需要将 5V 电源和 GND(在 P9_5 和 P9_1 引脚上可用)和正确的串行引脚(即 P9_26 和 P9_24,如果您启用了 UART1)连接到适配器的 5V、GND、RX 和 TX 连接器(不要理会 RTS 和 CTS,因为适配器会为您管理这些)。
在您的代码中将端口名称更改为新的串行端口(即/dev/ttyO1,如果您启用了 UART1)。
为了轻松调试您的代码,您可以通过 RS485 线连接 PC 上的 USB dongle 和 BeagleBone 上的适配器,并打开两个串行终端。
