pazucj
Posts: 14
Joined: Wed Dec 06, 2017 8:31 am

two RS-485 communicate on Raspberry Pi 3

Wed Jan 03, 2018 11:46 am

Hello, I want to check communicate RS-485 with two devices (FTDI), I have connected two FTDI's via USB PORT to Raspberry Pi and i closed loop with 2 to 1 RJ45 connector.
My question is how to communicate (send data ) from device 0 to device 1 and vice versa? I want also return a status from that communication - succes or false (in the future I will show communication status on LED).
Im looking for a commands in terminal or a C source example.
Thank You

User avatar
topguy
Posts: 4537
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: two RS-485 communicate on Raspberry Pi 3

Wed Jan 03, 2018 12:31 pm

If you now have "/dev/ttyUSB0" and "/dev/ttyUSB1" then you program them just like any other serial ports.

If you want to do testing with commandline you should first read up on "stty" command.

For a simple test try this:

Code: Select all

#Open one terminal and run
stty -F /dev/ttyUSB1 9600
cat /dev/ttyUSB1

#Open another terminal and run
stty -F /dev/ttyUSB0 9600
echo "Hello World" > /dev/ttyUSB0
If I have understood your setup correctly and everything is wired accordingly then "Hello world" should appear in the first terminal.
If there is some buffering going on, then maybe try "ls -al > /dev/ttyUSB0" to send a bigger chunk of text.

pazucj
Posts: 14
Joined: Wed Dec 06, 2017 8:31 am

Re: two RS-485 communicate on Raspberry Pi 3

Wed Jan 03, 2018 1:40 pm

Thank You, it's working ;) but I have delays with tranmission (I must wait 7-10 sec since next transmission to correctly receive a string. When I put faster it return me a splitted string with trash). I have one more question, have u got a examples for ANSI C to communicate via RS? I want to check that transmission works better than commands on terminal.

User avatar
topguy
Posts: 4537
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: two RS-485 communicate on Raspberry Pi 3

Wed Jan 03, 2018 1:59 pm

There are many if you google.
This is one: http://tldp.org/HOWTO/Serial-Programmin ... /x115.html that is quite detailed on how you change some of the parameters of the tty.

But the basics are the same, you use standard open/read/write functions on the tty device.

Return to “Beginners”

Who is online

Users browsing this forum: Bing [Bot], PingoBags and 49 guests