RS485 Module under console of Linux

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
(The Sample code source you can download from)
Current revision (11:50, 12 February 2025) (edit) (undo)
 
Line 1: Line 1:
[[Category:AllowPages]]
[[Category:AllowPages]]
== The Sample code source you can download from ==
== The Sample code source you can download from ==
-
Source file:
 
 +
Source file:
 +
<!--
<Google Drive> [https://drive.google.com/file/d/1aMU0yxQKPmeo83qGEqstVWImEUX1amdX/view?usp=sharing RS485_Console_v1.1_Src]
<Google Drive> [https://drive.google.com/file/d/1aMU0yxQKPmeo83qGEqstVWImEUX1amdX/view?usp=sharing RS485_Console_v1.1_Src]
 +
-->
<FTP> [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/RS485/rs485_console_source.tar.gz RS485_Console_v1.1_Src]
<FTP> [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/RS485/rs485_console_source.tar.gz RS485_Console_v1.1_Src]
 +
Refer below steps to source code to binary file
Refer below steps to source code to binary file
Line 13: Line 16:
$make
$make
$./rs485_console
$./rs485_console
-
Binary file:
 
 +
 +
Binary file:
 +
<!--
<Google Drive> [https://drive.google.com/file/d/1hrGmBBHuniL69eK3A7K5I-PGNRCOk7ko/view?usp=sharing RS485_Console_v1.1_Bin]
<Google Drive> [https://drive.google.com/file/d/1hrGmBBHuniL69eK3A7K5I-PGNRCOk7ko/view?usp=sharing RS485_Console_v1.1_Bin]
 +
-->
<FTP> [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/RS485/rs485_console_source1.1.tar.gz RS485_Console_v1.1_Bin]
<FTP> [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/RS485/rs485_console_source1.1.tar.gz RS485_Console_v1.1_Bin]
 +
== How to use the application ==
== How to use the application ==
 +
1.assign the port is Send node or Receive node.
1.assign the port is Send node or Receive node.
Please select Send or Receiver port(Send:1 , Recive:2)
Please select Send or Receiver port(Send:1 , Recive:2)
Line 31: Line 39:
In this question,If software control is opened , keyin 1:enable.
In this question,If software control is opened , keyin 1:enable.
Enable or disable your RTS (1:enable/2:disable)
Enable or disable your RTS (1:enable/2:disable)
 +
== Sample code Introduction ==
== Sample code Introduction ==
===Open COM Port Device===
===Open COM Port Device===
 +
default setting COM1~10,you can modify"/dev/ttyS0" to open other COM port device.
default setting COM1~10,you can modify"/dev/ttyS0" to open other COM port device.
case 1:
case 1:
Line 44: Line 54:
fd=open("/dev/ttyS2",O_RDWR| O_NOCTTY | O_NDELAY);
fd=open("/dev/ttyS2",O_RDWR| O_NOCTTY | O_NDELAY);
break;
break;
 +
 +
===Control RTS signal===
===Control RTS signal===
 +
1.control RTS high to send data for COM port
1.control RTS high to send data for COM port
ioctl(Port_fd, TIOCMGET, &mcs);
ioctl(Port_fd, TIOCMGET, &mcs);
Line 53: Line 66:
mcs &= ~TIOCM_RTS; //RTS low
mcs &= ~TIOCM_RTS; //RTS low
ioctl(Port_fd, TIOCMSET, &mcs);
ioctl(Port_fd, TIOCMSET, &mcs);
 +
 +
===Send Message===
===Send Message===
 +
Send message and return transfer counts
Send message and return transfer counts
write(Port_fd,o_char,i);
write(Port_fd,o_char,i);
 +
 +
===Receive Message===
===Receive Message===
 +
Receive message and return receive counts
Receive message and return receive counts
read(Port_fd,i_char,1024);
read(Port_fd,i_char,1024);

Current revision

Contents

The Sample code source you can download from

Source file:

<FTP> RS485_Console_v1.1_Src


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:

<FTP> RS485_Console_v1.1_Bin


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);
Personal tools