Bottom Page

Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry + RS485 shield | pySerial
#1
Hello,

I am using a RS485 shield for Raspberry v3 together with the pySerial class provided by Python to communicate with a device through the serial port.
The device I am communicating with, uses the S-Bus protocol and has a physical output with D+/D- and ground.
The device has a proprietary software that displays, in hex, what is broadcast and received on the device and on any other supplementary devices attached to it.
So, regarding topology, I went from the device's S-Bus port into the RS485 shield attached to the Raspberry.
At first, I was not sure that I will receive anything while listening to the port since I wasn't sure of the compatibility. Had to try it tough..

After I did the setup and made a little code in python using the pySerial class I was able to receive the same messages that are shown in the proprietary software of the device.
As a mention, in python, I had to encode the message received, to hex to have an exact match with what the proprietary software was displaying.

On the proprietary software I can give commands to the device and this device can trigger, from example, a relay.
While giving such a command and while monitoring the communication between the Raspberry and the device I "recorded" all the messages, in hex, that were transmitted on the S-bus protocol, including the code sent from the proprietary software to the device to trigger the relay.

My goal is to send the same command (as hex code) that triggers the relay from Raspberry and not from the proprietary software; and to work of course :D.
My logic (faulty or not ) was that sending the same hex code as the proprietary software sent to the device to trigger the relay should have the same effect. This seems like Captain Obvious.

Unfortunately, it didn't happen.
The message leaves the Raspberry (the led on the RS485 shield confirms it) but the relay isn't triggered and nothing is shown on the proprietary software display.
As a mention, I managed to command the relay with commands from the Raspberry to the device on the RS485 port also present on the device.
I am trying to make the commands work through the S-Bus port since it will benefit more.

Any ideas, hints of what could cause that ? Things to try ?

Serial Novice :D
Quote
#2
Some things come to mind.
Check the protocol on your serial port, you are mainly interested in number of databits
This only matters if the command that triggers the relay uses bit 7 (numbered 0-7)
for any purpose. It is possible to set databits to 7 or 8, with or without parity.

This is only important if the 7th bit is used, in whichcase, set data bits to 8, no parity.

Also, for your edification, hex is just the representstion used.

0101 0101 binary
is the same as 0x55 hex
is the same as 85 decimal.
is the same as 125 octal
...
Quote
#3
Many thanks for the insight.

Data bits were set to 8 with no parity. No luck.
I will continue trying playing with the connection, see if I get anywhere.
Quote
#4
Does the baud rate match on both ends of the connection?
That's the transfer speed and if it doesn't match you'll just see garbage on the receiving end
(if anything at all)


Also, the fact that the led comes on only indicates data at the source, and nothing about it's format.

I would suggest using putty (available on line free) on the receiving end. that way you can play with the baud rate parity, etc
without changing the software (until after you know what you're dealing with). In addition, since you indicate that only the data
lines are being used, I expect something like full duplex may be used for hand shaking, which may or may not be the case.
Quote
#5
Sorry for the awol. I've been meddling with other stuff. Thanks for the additional insight.

About the baud rate I'm pretty sure it is the same at both ends of the connection. I have some basic information, a document, about the serial communication used by the device, including the baud rate and I am using that for my python serial port configuration.
Unfortunately, I don't have any tools to measure it.

Regarding the integrity of the message I send from my RPI to the device, I tried to see what actually reaches the equipment by doing the following setup ( I think you will need to click on the image to enlarge it)
İmage

I sent my message from the RPI to Device 1 and with the sniffer on PC (that was connected through serial with Device2 | Device 2 was connected to Device 1 | No link from RPI to PC) I saw on the PC the exact message sent without any noticeable distortion.
That made me believe, that a theoretically correct code, reaches Device 1.
That's the best I could do for now and with the tools I had.

More tests are coming with different settings. Will post any worthy failures and/or breakthroughs.

Thanks again !
Quote
#6
In addition to Lars60+'s mention of baud rate, data bits and stop bits, many times you also need to set the flow control (or handshaking).  This can either be software or hardware controlled.  Software being Xon (ascii character 17) and Xoff (ascii character 19). Hardware makes use of pins on the chip, CTS (Clear to Send), DTR (Data Terminal Ready) and RTS (Ready To Send).

They make inline testers for RS232, RS422 and RS485 running from relatively cheap to outrageously expensive, depending on your needs and pocketbook.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Quote
#7
Don't forget there are software testers as well:

For example:
http://www.microridge.com/comtestserial.htm
http://www.serial-port-monitor.com/
https://freeserialanalyzer.com/
and more
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  pyserial-master installed bbut not recognized elwolv1 0 64 Jan-04-2019, 08:37 PM
Last Post: elwolv1
  Python version 3 that seems to be ignored by the system on a Raspberry Pi Discret68 3 153 Dec-28-2018, 06:42 PM
Last Post: Gribouillis
  Python Idea Assist.: BerryIMU & Raspberry Pi 3 Audio Mapping StephLeber 0 159 Dec-09-2018, 10:43 AM
Last Post: StephLeber
  async question on raspberry pi baukeplugge 2 135 Nov-07-2018, 07:58 PM
Last Post: baukeplugge
  Trouble with Pyserial and Arduino LiTing 3 403 Oct-07-2018, 11:00 AM
Last Post: Larz60+
  pyserial char by char io fcagney 4 477 May-15-2018, 10:45 PM
Last Post: DeaD_EyE
  import keyboard module doesn't get found - working on laptop but no on raspberry pi.. HANSJORG2 1 986 Mar-16-2018, 02:48 PM
Last Post: sparkz_alot
  Address WS2811 LED matrix attached to Raspberry Pi 3 sebar 4 1,150 Jan-08-2018, 07:59 PM
Last Post: sebar
  No route to host error when using requests.post in python on raspberry pi mariummalik22 0 798 Jan-06-2018, 08:34 PM
Last Post: mariummalik22
  Setting GPIO on Raspberry PI using a function jmjasper1 6 995 Dec-29-2017, 08:42 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)