RevPI with Serial Gatway and UART

Topics about the Software of Revolution Pi
Post Reply
takeoo111111
Posts: 1
Joined: 18 Apr 2017, 22:41
Answers: 0

RevPI with Serial Gatway and UART

Post by takeoo111111 »

Hey,
we would like to use our RevPi together with the Kunbus Serial Gateway.
I couldn't find any information or example code how to use this specific device with RevPi. We would like to communicate/receive serial data from a Siemens Logo installation via UART.
I had a look on python3-revpimodio and could communicate with the gateway itself. But I did't find a way to transmit or receive data. Can you give me some hints where to start?

Thank you very much!
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: RevPI with Serial Gatway and UART

Post by volker »

I fear there is a misunderstanding of the purpose of KUNBUS gateway modules. These modules originally were constructed to always work as a pair of 2 modules to perform a cyclical data exchange between 2 different field buses. This task is done by 2 data exchange memories (one in each gateway module). Each module is mirroring 512 Byte of data of its companion's data exchange memory (over the back-plane bus). The data exchange memory of each gateway module itself does cyclically exchange the data with the connected fiedl bus. You will find more details in the gateway manuals which can be downloaded on the individual gateway web sites on www.KUNBUS.de (there are English sites and English manuals for each gateway).
When using a gateway module not as a pair of 2 but in combination with a revPi Core, the RevPi Core behaves like a companion gateway and is cyclically mirroring a portion of its central process image with the data exchange memory of the connected gateway module. This portion of data again is mirrored on the connected field bus. The way the data is sent on the field bus is normally well defined by the field bus protocol (e.g. Profibus). Data from the data exchange memory is used as a "payload" for transmission packages which normally consist of many more bytes forming the framework of the protocol.
So up to this point this technology is not comparable to typical UART software which is listening to the serial data stream, interpreting it and extracting the information needed from the data stream. All this work is done automatically by the gateway modules according the the rules of the respective field-bus protocol. You application's task is only to provide the payload data in a compact block of data (although the PiCore's process image can be viewed as a structured block of data, all gateway modules are defined as unstructured block of bytes in PiCtory).
But now comes a serial gateway specialty: On RS485 / RS232 you have typically Modbus RTU as a protocol. Thus the serial gateway works per default as a modbus RTU (slave) gateway and reacts to a polling Modbus master by interpreting its data exchange memory as Modbus registers (see manual of the Modbus gateway for further information on how these registers are addressed). BUT: If you wish to use any other customer specific protocol on the RS485 /232 interface to cyclically exchange data with any device talking such a protocol you may use the KUNBUS scripter. This is a software running on the gateway which interprets uploaded scripts to pack or unpack data from the data exchange memory when talking on the serial line. The scripts can be written and debugged by use of a srcipt editor running on a Windows PC. You can find this editor and the user manual for it on the KUNBUS support webpages:
https://www.kunbus.com/support.html
Please note that you will need the programming adapter to upload scipts on the module. It can be ordered from KUNBUS (see note on the Serial Gateway Web page: https://www.kunbus.com/serial-rx-gateway-module.html) for I think about 15 Euros.

After all it would not be wise to use this complex way to simply send or receive RS232 or 485 data streams from a RevPi Core's application software. For such a purpose better use a USB to serial converter (which can be found in the Revpi Shop). With such a converter you will get a "/dev/ttyUSBx" device under Linux which can be treated as a standard UART under all programming languages. The serial gateway module would only be appropriate to handle a fixed and fast protocol of cyclical data exchange with a serial device if you want to let the gateway do the packing/unpacking task and do not need to change the protocol's details for a long time (such a scenario would e.g. be a laboratory measuring equipment talking a generic protocol which you will connect to RevPi Core and you need to do this for many customers in the same way).

Hope this long answer could clarify how to use the serial gateway. Sorry that we not yet have such an explanation on our shop's web pages but the KUNBUS gateways have been sold long before the RevPi was introduced to the market and thus we have all the material on the KUNBUS web pages.
Unser RevPi Motto: Don't just claim it - make it!
Charmanag
Posts: 4
Joined: 15 Oct 2019, 10:16
Answers: 0

Re: RevPI with Serial Gatway and UART

Post by Charmanag »

Hi Volker.

Totally new to this forum and RevPi but this seems like a good thread to ask this question on.

We have two devices that are serial over USB. No D sub 9 port. Just emulated serial over usb and 1 device that is RS232. We want to add these three devices data together using switches etc for timing.

Am i right in thinking the serial bridge would work with our rs232/conventional serial device and the RevPi itself would handle our two usb emulated serial devices?

Cheers
Dom
User avatar
dirk
KUNBUS
Posts: 1926
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: RevPI with Serial Gatway and UART

Post by dirk »

Hi Dom, so I have understood that you have USB and Serial devices that you want to process, right?
The Serial Gateway Module has been developed as a separate product before the RevPi existed.
You may use them but you need to write a script with the KUNBUS Scripter and a USB-Serial PiBridge adapter to upload it to process the data.
It is possible but well a bit cumbersome.

So I recommend you to use a RevPi Core or a Connect Module together with USB-Serial adapters from the shop which are industrial grade.

The USB-Serial devices will show up on the RevPi via "/dev/ttyUSBx", i.e. "/dev/ttyUSB0". Then you may open the device and process the data easily.
Try to search for Python RS232 or so. Have a look at this wonderful PySerial short introduction.
Charmanag
Posts: 4
Joined: 15 Oct 2019, 10:16
Answers: 0

Re: RevPI with Serial Gatway and UART

Post by Charmanag »

Thanks Dirk. Sorry for the super slow reply from me.

The two ish devices (maybe three in the long run) are serial over USB devices. So am I write in thinking you mean we can just plug two of these straight into the USB ports on the RevPi core and hook up the conventional tx, rx, gnd cables from the othet device to a usb serial adapter on a RevPi usb module (to give us the extra ports) and we should be good to go?

Thanks for the detailed response and again sorry for being so slow coming back.

Dom
User avatar
dirk
KUNBUS
Posts: 1926
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: RevPI with Serial Gatway and UART

Post by dirk »

Hi Dom, never mind for the slow reply. So I uderstood that you want to know if this scenario is technically possible:
Two RevPi Modules, each is equipped with an USB-Serial interface, RX-TX and TX-RX and GND-GND connection?
Yes it is possible that the two RevPi's can communicate with each other.
Charmanag
Posts: 4
Joined: 15 Oct 2019, 10:16
Answers: 0

Re: RevPI with Serial Gatway and UART

Post by Charmanag »

No, sorry Dirk I am not being clear. Quite new to this!!

Three USB Rs232 devices. 1 Conventional D Sub 9/3 sure RS232 device.

From my reading today I think (and sure you'll correct me of I'm wrong) we can use a RevPi core, connect one of your USB hubs and then connect our USB RS 232 to the USB ports and our RS 232 D SUB to your adapter and then to the USB ports or hub.

So we only need a RevPi Core?
User avatar
dirk
KUNBUS
Posts: 1926
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: RevPI with Serial Gatway and UART

Post by dirk »

Hi Charmanag,
>> Three USB Rs232 devices.
No problem.
>> 1 Conventional D Sub 9/3 sure RS232 device.
Could you be so kind to explain what you mean here?

>> From my reading today I think we can use a RevPi core,
>> connect one of your USB hubs
yes
>> and then connect our USB RS 232 to the USB ports
which?
>> and our RS 232 D SUB to your adapter
Again what do you mean here?
>>and then to the USB ports or hub.
>>So we only need a RevPi Core?

Well I understood that you want to use three (3) RS232 interfaces.
So you can use three USB-RS232 converters have a look at a distributor nearby i.e. RS-Components or Digi-Key, etc.
We just have USB-RS422/RS485 interfaces in our shop.
Charmanag
Posts: 4
Joined: 15 Oct 2019, 10:16
Answers: 0

Re: RevPI with Serial Gatway and UART

Post by Charmanag »

Thanks Dirk.

Bascially the three usb RS232 device- no issue. Straight into your USB hub from the shop and then into the USB ports on the Core. Providing 3 USB RS232 devices through a single USB port.

The fourth device is RS232 but not via usb. It uses the conventional 3 cable Rx Tx and Gnd connector. 9 pin d sub 9 we call them. But I can then use a Serial port to USB adapter and plug this into the other usb port on the Core I think from what you're saying?

We'd then have our 4 serial devices connected to the Core and it's just a matter of writing the code to get all the data in one place.

Cheers
Dom
User avatar
dirk
KUNBUS
Posts: 1926
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: RevPI with Serial Gatway and UART

Post by dirk »

Hi Charmanag, the Industrial USB 2.0 Hub with 4 ports has also the USB-Host that you connet to the RevPi Core Module. So you can connect all four USB-Serial devices to it. On the RevPi you can use "lsusb -v" and "ls /dev/ttyUSB*" to get lists of the connected devices. I.e. "/dev/ttyUSB0", "/dev/ttyUSB1", etc. The key point here is to guarantee that the USB enummeration provides each device on the same interface. Have a research on the topic "udev rules" for this.
Post Reply