LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 8:33 am

Hello,
I would like to send and receive data between an embedded system communicating in RS232 and my Raspberry PI 3.

So I did several research, I found that we can use the serial port RPI (08-10-09-GND), but I find a lot of tutorials on the internet that offers a solution for this link, not wanting not wrong configuration, and not lose myself on several solutions

I would like some information on this subject?
Thank you all :)

B.Goode
Posts: 6005
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 10:32 am

The Raspberry Pi Foundation documentation for the RPi UARTs is here: https://www.raspberrypi.org/documentati ... on/uart.md

Perhaps the first thing to note is the warning in the first paragraph that the UART designated on the 40-way header is incompatible with, and can be fatally damaged by, a 'standard' rs232 serial connection.
extra care must be taken when connecting up to an RS232 or other system that utilises different voltage levels. An adapter must be used to convert the voltage levels between the two protocols.

hippy
Posts: 3156
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 10:49 am

Your easiest option will be to use a USB-to-RS232 converter.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 19809
Joined: Sat Jul 30, 2011 7:41 pm

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 10:54 am

hippy wrote:
Mon Jun 18, 2018 10:49 am
Your easiest option will be to use a USB-to-RS232 converter.
Indeed. They are incredibly cheap, and 'just work'.

e.g.

https://www.ebay.co.uk/itm/USB-to-RS232 ... SwdpxUWdps

https://www.ebay.co.uk/itm/CP2102-Modul ... Swz35bCBSq
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 11:48 am

Hello
I have indeed a USB / RS232 adapter (https://www.digikey.it/product-detail/i ... ND/3103022), so if I look at this solution, you think that flinching enough to do the exchange of data? Or should there be a python program to do that?

For a better understanding of my questions, here is the explanation and purpose of my research in more detail ( viewtopic.php?f=36&t=216052&p=1328688#p1328688)
You can close one of the two post, if you find this is repetitive
Thank you all :)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 19809
Joined: Sat Jul 30, 2011 7:41 pm

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 12:35 pm

LinuxKoku wrote:
Mon Jun 18, 2018 11:48 am
Hello
I have indeed a USB / RS232 adapter (https://www.digikey.it/product-detail/i ... ND/3103022), so if I look at this solution, you think that flinching enough to do the exchange of data? Or should there be a python program to do that?

For a better understanding of my questions, here is the explanation and purpose of my research in more detail ( viewtopic.php?f=36&t=216052&p=1328688#p1328688)
You can close one of the two post, if you find this is repetitive
USB serial adaptors should appear as serial devices, you can then use any serial software (lots of examples in C and Python on the net) to do what ever communications you need.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Mon Jun 18, 2018 12:55 pm

jamesh wrote:
Mon Jun 18, 2018 12:35 pm
you can then use any serial software (lots of examples in C and Python on the net) to do what ever communications you need.
Thanks for your feedback,
I'm not asking you to do my job, but could I have an example of an internet link to get a good idea of what you're talking about and to do specific research?
Thank you all :)

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 7:53 am

Hello,

Before proceeding with what you propose, I need your opinion on this tutorial (https://www.youtube.com/watch?v=9gLXfOA87zI) that offers me to work with TTYUSB0 and thus install minicom, you think it's the good approach? knowing that for my part I would connect directly to the counting system.
Thank you all :)

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 10:01 am

Hello,

I realize that minicom is a terminal emulation program so I could send and receive data manually.

:?:
Can I send any kind of data?
My goal is to send/receive this data automatically and not manually, so can I process this data and send it automatically?
If no, is there another way to proceed, like scripts?
Thank you all :)

hippy
Posts: 3156
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 12:28 pm

LinuxKoku wrote:
Tue Jun 19, 2018 10:01 am
My goal is to send/receive this data automatically and not manually, so can I process this data and send it automatically?
You need to know exactly what data it is you need to send and you need to know exactly what data you will receive.

Then you can determine what you need to do that and how to do it. It may require a specially written program to access and read the data in the format it comes back in which can translate that to something more meaningful which can then be used further.

It will greatly depend on what the data is and how it is to be used. If for example it were a PPP/SLIP serial connection for carrying TCP/IP which linked the attached thing to the host's network then everything to do that is already available in Linux; you would just need to install the PPP/SLIP software and configure it.

This seems to be another part of your project where you are trying to figure out how to do it without being entirely clear on what you need to actually do, what data you are dealing with.

The physical connection and how serial works is the least of your worries.

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 3:23 pm

Thank you for your answer,

Small error: I configured the speed to 9600 but 8N1, I saved the changes, but when I run the command line dmesg | grep tty, he still shows me 115200! knowing that I should work with a speed of 9600, what should I do?

I was able to configure the serial port and it is detected by the Raspberry PI.

I've done some research, and we're talking about the use of Python + Pyserial, so to be able to talk to the counting system, I have to do a program on the Raspberry PI, to send frames of data (bytes) more exactly one hexadecimal string through the serial port, and I should receive a frame of results that I should visualize (display)

So now I should write a program that can send / receive data of hexadecimal string type, indications?

:!: My tutor told me that the data conveyed are bytes (ASCII), but that what I should send and receive is a hexadecimal string, so we should think about converting the bytes each time to a string of characters ! what does he want to say exactly?
Thank you all :)

hippy
Posts: 3156
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 3:42 pm

LinuxKoku wrote:
Tue Jun 19, 2018 3:23 pm
So now I should write a program that can send / receive data of hexadecimal string type, indications?
That seems about right.
LinuxKoku wrote:
Tue Jun 19, 2018 3:23 pm
:!: My tutor told me that the data conveyed are bytes (ASCII), but that what I should send and receive is a hexadecimal string, so we should think about converting the bytes each time to a string of characters ! what does he want to say exactly?
There are a number of different interpretations on what may be meant by "a hexadecimal string" so you would have to ask your tutor which it is or provide some details of the device you are communicating with.

The device's datasheet or specification should describe what the protocol and command set is, what should be sent, what can be expected to be received.

Do you have details of the counting device you are connecting to; manufacturer, make and model ?

LinuxKoku
Posts: 67
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 4:03 pm

The counting system is manufactured by our company (http://www.elinap.com/), my goal is to send a string, (7E 7E 73 02 HiCrc LoCrc) (hexadicimal), the counting system should recognize this frame and should return a result, by example: the number of travelers
Thank you all :)

hippy
Posts: 3156
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: RS232 serial link with Raspberry PI 3

Tue Jun 19, 2018 4:45 pm

LinuxKoku wrote:
Tue Jun 19, 2018 4:03 pm
my goal is to send a string, (7E 7E 73 02 HiCrc LoCrc) (hexadicimal)
I am guessing that, in Python, one of these will do the job where 'hh' and 'll' are your CRC values -

Code: Select all

def ToHexString(n):
  return "0"+( hex(n)[2:] )[-2:].upper()
ser.write( "7E"+"7E"+"73"+"02"+ToHexString(hh)+ToHexString(ll) )

Code: Select all

ser.write( chr(0x7E)+chr(0x7E)+chr(0x73)+chr(0x02)+chr(hh)+chr(ll) )

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 17 guests