pyserial/Modbus - 故障排除 "No communication with instrument"

pyserial/Modbus - troubleshooting "No communication with instrument"

Beaglebone 黑色无线:Ubuntu16.04,

计算机:Ubuntu16.04,

Python 3.5.2

我正在尝试使用 Beaglebone Black 通过 Modbus 与设备通信。我读过有人用 USB/RS485 加密狗使用 minimalmodbus 做同样的事情。我试过更改设置;每个可能的波特率、更短的电缆等。Beagle 中必须有一些东西需要 configured/is 为此类工作错误配置。

代码

#!/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 加密狗。使用此 dongle/code 组合在我的计算机上(过去 4 个月)产生了完美的结果,但在今天的 Beagle 上却没有。

计算机:收到的消息:

[0, 0]

Beagle:收到错误:

IOError: No communication with instrument (no answer)

我正在寻找可能的故障排除途径。我已经确认电缆不是太长,USB dongle 没问题。我也排除了任何代码问题。

编辑 1: 忘记包括 lsusbls /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 配合良好,但对于微控制器(例如 BeagleBone),您需要能够更好地处理总线规范的东西。

我发现一些简单且低成本的 TTL RS232 到 RS485 板可以完美工作,无需在 BeagleBone 端进行任何特殊配置,因为它们会自动管理流量控制。 您可以在 Ebay 或类似网站上搜索 RS485 automatic flow control

由于 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上的适配器,并打开两个串口终端。