2

Beaglebone Black Wireless: Ubuntu 16.04,

Computer: Ubuntu 16.04,

Python 3.5.2

I am trying to communicate with a device via Modbus using a Beaglebone Black. I have read of people doing this same thing with a USB/RS485 dongle using minimalmodbus. I've tried changing up the settings; every possible baud rate, shorter cable, etc. There must be something within the Beagle that needs to be configured/is mis-configured for this type of work.

Code

#!/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)

...using a USB/RS485 dongle. Using this dongle/code combination yields perfect results on my computer (for the past 4 months) but not the Beagle today.

Computer: Message received:

[0, 0]

Beagle: Error received:

IOError: No communication with instrument (no answer)

I am looking for possible avenues of troubleshooting. I have verified that the cable is not too long, and the USB dongle is OK. I have also ruled out any code issues.

Edit 1: Forgot to include lsusb and 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

and

/dev/ttyUSB0

Edit 2:

I am able to achieve a loopback setup using pyserial and shorting the Rxd and Txd + and - terminals.

Edit 3:

I have tried all possible wiring configurations. Only one configuration works on the computer (Tx+ -> A and Tx- -> B). While using the minimalmodbus debug feature, I can see that the same message is being sent to the device on the Beagle and the computer ('\x01\x03\x07Ø\x00\x02ED' (01 03 07 D8 00 02 45 44) ). The computer receives a response while the Beagle does not.

The Beagle has no trouble mounting the adapter to /dev/ttyUSB0.

Edit 4:

@Carlo Zanocco requested the output of 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

Edit 5:

Output of 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
ChumiestBucket
  • 868
  • 4
  • 22
  • 51
  • Edit your Question and show the output of `lsusb` in console window. – stovfl Sep 18 '18 at 18:21
  • Please post the Modbus device name and check if you have the correct wiring(include the termination resistor) – Carlo Zanocco Sep 19 '18 at 15:15
  • @CarloZanocco the device is an industrial coriolis flowmeter with Modbus capabilities. The wiring is correct; if it wasn't, it probably wouldn't work on my computer as stated in the question. Also, there is no terminating resistor in this setup. – ChumiestBucket Sep 20 '18 at 16:46
  • @star_trac can you post the output of this command: "ls /dev/ | grep tty". Also test the serial port using the library pyserial and check what happened – Carlo Zanocco Sep 21 '18 at 07:30
  • @CarloZanocco the command `ls /dev/ | grep tty` returns the same thing as `ls /dev/ttyUSB*`, just like in the question. Also what do you mean "test the serial port"? I'm not sure how to test the port using pyserial. I can try and establish a connection through pyserial through `/dev/ttyUSB0` which I can most definitely do. – ChumiestBucket Sep 21 '18 at 14:29
  • @star_trac "ls /dev/ttyUSB*" return all the ttyUSB , I want to check if this name is correct or not, I read on some forums that on beagle you can find the serial port under "/dev/tty01", so post the result please. You can test the serial port using pyserial, it's just to test if the config is correct on the beagle. – Carlo Zanocco Sep 21 '18 at 14:32
  • @CarloZanocco please see the output – ChumiestBucket Sep 21 '18 at 14:46
  • @star_trac I had seen it, I'm thinking where the problem is. The port is correct, the program is correct. I think you can test with pyserial to figure out the problem. try to make a small program that import pyserial and write this string to the device: "010307D800024544". After than use `time.sleep(1)` and after that the read command and see if you receive response – Carlo Zanocco Sep 21 '18 at 14:50
  • @CarloZanocco I will give it a shot, thanks Carlo! – ChumiestBucket Sep 21 '18 at 14:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180531/discussion-between-carlo-zanocco-and-star-trac). – Carlo Zanocco Sep 21 '18 at 14:57
  • @star_trac post the output of the following command: `stty -F /dev/ttyUSB0 -a`, probably I found the problem – Carlo Zanocco Sep 21 '18 at 16:00

1 Answers1

1

I experienced the same issues and it turned out it was a problem of termination and flow control.

I tried different USB dongles, all working with pcs and macs, and many different configurations on the BeagleBone, but nothing worked.

Low-cost USB dongles work well with PCs, but with microcontrollers, such as the BeagleBone, you need something that better handles the bus specifications.

I found out that some simple and low-cost TTL RS232 to RS485 boards work perfectly without any special configuration on the BeagleBone side since they automatically manage flow control. You can search for RS485 automatic flow control on Ebay or similar websites.

Since the default serial port on your BeagleBone is already coupled to the system console, you need to enable another UART by properly editing the file /boot/uboot/uEnv.txt.

Then you need to connect 5V power supply and GND (available on P9_5 and P9_1 pins) and the correct serial pins (i.e. P9_26 and P9_24 if you enabled UART1) to the 5V, GND, RX and TX connectors of the adapter (do not bother with RTS and CTS since the adapter will manage those for you).

In your code change the port name to the new serial port (i.e. /dev/ttyO1 if you enabled UART1).

To easily debug your code, you can connect the USB dongle on a PC and the adapter on the BeagleBone through the RS485 wires and open two serial terminals.

luigif
  • 544
  • 4
  • 8