請先看『使用說明』
RS485 Module under console of Linux
From LEXWiKi
(Difference between revisions)
(→The Sample code source you can download from) |
(→How to use the application) |
||
Line 20: | Line 20: | ||
2:RS232 | 2:RS232 | ||
4.If you assign RS485 style of COM port in previous choose , will be show this question.<br /> | 4.If you assign RS485 style of COM port in previous choose , will be show this question.<br /> | ||
- | In this question,If | + | In this question,If software control is opened , keyin 1:enable. |
- | + | Enable or disable your RTS (1:enable/2:disable) | |
== Sample code Introduction == | == Sample code Introduction == |
Revision as of 14:06, 22 August 2018
Contents |
The Sample code source you can download from
Source file: rs485_console_source1.1.tar.gz
Refer below steps to source code to binary file
1.Using Code::Blocks to load project and build a binary file 2.Using "make" command to compile source code and create it. $cd /rs485_console_source/485_console $make $./rs485_console
Binary file: rs485_console_binary1.1.tar.gz
How to use the application
1.assign the port is Send node or Receive node.
Please select Send or Receiver port(Send:1 , Recive:2)
2.choice open port number(default is port1~10)
Please input port number(1~10)
3.assign the por is RS485 or RS232
choose your port style: 1:RS485 2:RS232
4.If you assign RS485 style of COM port in previous choose , will be show this question.
In this question,If software control is opened , keyin 1:enable.
Enable or disable your RTS (1:enable/2:disable)
Sample code Introduction
Open COM Port Device
default setting COM1~10,you can modify"/dev/ttyS0" to open other COM port device.
case 1: fd=open("/dev/ttyS0",O_RDWR| O_NOCTTY | O_NDELAY); break; case 2: fd=open("/dev/ttyS1",O_RDWR| O_NOCTTY | O_NDELAY); break; case 3: fd=open("/dev/ttyS2",O_RDWR| O_NOCTTY | O_NDELAY); break;
Control RTS signal
1.control RTS high to send data for COM port
ioctl(Port_fd, TIOCMGET, &mcs); mcs |= TIOCM_RTS; //RTS high ioctl(Port_fd, TIOCMSET, &mcs);
2.control RTS low to receive data for COM port
ioctl(Port_fd, TIOCMGET, &mcs); mcs &= ~TIOCM_RTS; //RTS low ioctl(Port_fd, TIOCMSET, &mcs);
Send Message
Send message and return transfer counts
write(Port_fd,o_char,i);
Receive Message
Receive message and return receive counts
read(Port_fd,i_char,1024);