Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 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.
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.
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.
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.
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.
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.
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).
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.