LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2019, 09:35 AM   #1
helpful_user
LQ Newbie
 
Registered: May 2019
Posts: 5

Rep: Reputation: Disabled
RS-485 in Linux


Hello guys,

I'm having a hard time understanding the RS-485 interface and how it can be used in Linux.

Background:
I have one industrial box PC with a RS-485 chip, and my PC which has a USB to RS-485 adapter.

The box PC is running a Debian based distro with kernel 4.19 and my PC is running ubuntu 16.04(LTS).

In my first test i connected a usb to RS232 converter to one of the COM ports on the box PC. I was able to echo text from the PC to the box PC.

After that I changed the BIOS settings on the box PC to RS-485 and re-did the test without success.

My first question is the following:
What is the simplest way of displaying RS-485 data? Is it even possible to echo simple data streams or does it require more effort in terms of creating some sort of server with master address and slaves etc.

I then tried to create a small program from:
https://www.kernel.org/doc/Documenta...rial-rs485.txt

But that was also unsuccessful, before digging deeper into the code I think I need to fully understand the interface and how to use it.

Would be really grateful for any help or tips
 
Old 05-24-2019, 10:07 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Welcome to Linux Questions.

I don't know your background so will start from the basics just in case. Without knowing anything about the industrial PC I can not help you with specific settings.

Basically RS-485 is an electrical specification. While 485 uses two wires many or most adapters also can be a 4 wire i.e RS-422. Make sure you are wired correctly. For short runs all you need is two wires twisted together connected between the 485 + and 485 - signals on each PC. There might be specific 485 notes on the Industrial PC.

Your still communicating between to com ports and if configured with the same serial port parameters an echo test using a standard communication program should work the same as RS-232.
 
Old 05-24-2019, 10:16 AM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Haven't done it but I'm not sure there would be a native driver for your USB to RS-485 adapter in the default Linux kernel.

You might want to go to the manufacturer's site for the USB to RS-485 adapter to see if it supports Linux and if so if they have a driver you can install and download.

For example this site has a link to download drivers for the adapter it shows.
 
Old 05-24-2019, 10:18 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,876
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
The best way to look at RS485 data is too look at the bytes transmitted. It is a byte and small message serial protocol, conveyed over 2 or 4 wire, typically 2.

The content is usually dependent upon the devices being used. Some of it may be non-printable bytes, < 0x20 or 0x7f (DEL), so be prepared to look at it in hex. Likely the directives or commands are readable but the settings might be 0x00 or 0x01, which are not printable.
 
Old 05-24-2019, 10:19 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
LTSP?

linux terminal server project

http://www.ltsp.org/


EIA-485:
http://www.tldp.org/HOWTO/html_singl...-HOWTO/#ss21.3
 
Old 05-24-2019, 11:03 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Without much success is not much to go on.

Knowing nothing about the Industrial PC I would assume changing the BIOS settings just switches the serial port output from a UART to a 485 converter. The operating system still sees it as a serial port so installing drivers are not required on that end.

While the USB to 485 adapter depends on its chipset. My FTDI based 485 adapter is automatically recognized and assigned a ttyUSBx device ID. The OP should verify that Ubuntu is recognizing the adapter and assigning it a device ID.

485 has no defined communication protocol. I agree that typically it is byte or small message but it can be anything and many of the 485 devices I have played with over the years used ASCII based text commands versus binary. Using minicom or another communication program is suggested over sending echo commands using bash.

Last edited by michaelk; 05-24-2019 at 12:50 PM. Reason: fixed errors.
 
Old 05-24-2019, 01:03 PM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by michaelk View Post
The operating system still sees it as a serial port so installing drivers are not required on that end.
Are you sure? The last time I had to do RS422 on Unix I had to have a different adapter with its own driver. Admittedly that was a long time ago and I dever did it on Linux but what I found on a web search that talked about a driver for the RS485 to USB I linked makes me wonder if you don't need a driver to make that work and see it as RS485 vs RS232 traffic.
 
Old 05-24-2019, 01:23 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Quote:
Are you sure?
Not really with zero information. I've used several embedded boards where you had to set a bit to convert the serial port from RS-232 to RS-485. Considering that the OP posted changing the BIOS to switch types seems reasonable. I should edit that post and put a should somewhere.

It can be more complicated but the microprocessor serial port is TTL and all you need to convert it to the real world is a UART for RS-232 or a 485 converter IC.
 
Old 05-24-2019, 08:37 PM   #9
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,272
Blog Entries: 28

Rep: Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124Reputation: 6124
Maybe I'm quibbling, but RS-485 did not "come to be used" in Linux. RS-485 is a very old spec that predates Linux by many years, so Linux needed to be able to use it.

I used to work for a company that produced access control components and they used RS-485 to communicate with remote field components (controller boards), which in turned communicated with locks, keypads, door sensors, multi-purpose relays, etc. Their original product was based on the QNX OS, a commercially developed Unix-like system (later ones were based on Windows and WinNT).
 
Old 05-25-2019, 12:45 AM   #10
WFV
Member
 
Registered: Apr 2012
Location: somehow, somewhere
Distribution: Arch
Posts: 197

Rep: Reputation: Disabled
try Hyper-Terminal or Putty in Wine - and go with an RS232-485 converter
 
Old 05-27-2019, 04:33 AM   #11
helpful_user
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hello guys,

Thanks for all your help!

I noticed something this morning which makes me believe that the problem is on the box PC side. The box PC also has a BIOS setting for RS-422/RS-485 full duplex. When i changed into that I could send/read data on both PCs. That should clarify that:
1. The USB to RS-485 adapter is working.
2. Sending simple commands with picocom/bash is possible.
I still dont understand why half duplex is not working, but I will do some more tests and get back here if I find anything useful
 
1 members found this post helpful.
Old 05-27-2019, 05:26 AM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
There might not be be an automatic send capability. You might have to set RTS flow control.
 
Old 05-27-2019, 06:00 AM   #13
helpful_user
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
There might not be be an automatic send capability. You might have to set RTS flow control.
Could you elaborate? Since the full-duplex version is working I would assume that RTS is working automatically.
 
Old 05-27-2019, 08:55 AM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Basically full duplex means there are separate wires for transmit and receive and therefore driver chips are always enabled. Half duplex means that transmit and receive signals are on the same wires and there needs to be control signals to switch between the two states.

Adapters typically are always in receive mode and have an auto detect circuit to switch to transmit when sending a signal or require hardware flow control of some sort to switch states. I would hope the industrial PC manual contains some information about how the built in RS-422/RS-485 circuit works.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux and 9 bit RS-485 wufo Linux - Hardware 1 09-09-2014 03:27 PM
485 serial port IDEASeth Linux - Embedded & Single-board computer 3 04-27-2013 10:41 AM
RS-485 / RS-232 problem, how to solve?!? rkrijger Linux - Hardware 2 10-29-2003 02:37 AM
rs-485? alaios Linux - Networking 3 04-28-2003 10:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration