I'm trying to learn the RS-485 interface by sending data between two Linux computers. The main computer is running ubuntu16.04 and the other is running a debian based system on kernel 4.19.
The main PC has a USB to RS-485 adapter and the other PC has RS-485 interface.
Initially I assumed that i could simply echo data on the interface but I could not. If i connected with picocom I could type data but not send it. By looking around i realized that this is because both PCs are waiting for RTS that somehow needs to be toggled.
I then concluded that I need some sort of C program to initialize the interface(please correct me if I'm wrong).
I went https://www.kernel.org/doc/Documentation/serial/serial-rs485.txt Where the is an example code for setting up RS-485.
However, when I try to run it always fails at:
status = ioctl(fd,TIOCSRS485, &ctrl485);
if (status) {
printf("ERROR PORT 1! TIOCSERSETRS485 failed %i", status);
return -1;
}
I have googled every combination of RS-485 that i can think of but most information is about modbus and sensors. I also read about ioctls but I'm still stuck.
If anyone has experience or tips I would be really thankful.
Best Regards, W
ctrl485
. Show how you openfd
. What type isstatus
? – Zipstatus:-1,fd:3, content of ctrl485:0,1,0,1
. – Junierrno
? – Zipprintf("error %s\n", strerror(errno));error Inappropriate ioctl for device
– Junistruct serial_rs485 rs485conf;
, if it's an automatic variable, itsflags
field may contain garbage (do the initialization with struct .. rs485conf = {0}). Also, some ioctls may return a positive int on success -- better to check with
if(status < 0) ...` – Exuviate