2

Beaglebone Black Wireless:Ubuntu 16.04,

电脑:Ubuntu 16.04,

Python 3.5.2

我正在尝试使用 Beaglebone Black 通过 Modbus 与设备通信。我读过有人用 USB/RS485 加密狗使用minimalmodbus. 我试过改变设置;每个可能的波特率,较短的电缆等。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]

比格犬:收到错误:

IOError: No communication with instrument (no answer)

我正在寻找可能的故障排除途径。我已经验证了电缆不是太长,并且 USB 加密狗是可以的。我还排除了任何代码问题。

编辑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
4

1 回答 1

1

我遇到了同样的问题,结果证明这是终止和流量控制的问题

我尝试了不同的 USB 加密狗,都适用于个人电脑和 Mac,以及 BeagleBone 上的许多不同配置,但没有任何效果。

低成本 USB 加密狗可以很好地与 PC 配合使用,但对于 BeagleBone 等微控制器,您需要能够更好地处理总线规范的东西。

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

由于 BeagleBone 上的默认串行端口已经耦合到系统控制台,因此您需要通过正确编辑文件 /boot/uboot/uEnv.txt来启用另一个 UART 。

然后您需要将 5V 电源和 GND(在 P9_5 和 P9_1 引脚上可用)和正确的串行引脚(即 P9_26 和 P9_24,如果您启用了 UART1)连接到适配器的 5V、GND、RX 和 TX 连接器(不要打扰使用 RTS 和 CTS,因为适配器将为您管理这些)。

在您的代码中,将端口名称更改为新的串行端口(即 /dev/ttyO1,如果您启用了 UART1)。

为了轻松调试代码,您可以通过 RS485 线连接 PC 上的 USB 加密狗和 BeagleBone 上的适配器,并打开两个串行终端。

于 2018-09-25T13:05:44.673 回答