Linux 串口终端的实用性研究(linux串口终端)

With the increasing popularity of Linux, more and more applications related to Linux are emerging in the market. The serial port terminal is a product of the application of Linux, and can be applied to various areas.

The serial terminal is mostly used in industrial and scientific fields. It is an accessory of embedded device development and industrial debugging, and it has strong real-time performance. It can be connected to multiple devices through serial ports, so that it can be used in time sharing experiments. The serial port terminal for Linux is equipped with a variety of terminal systems, telnet, ssh and other protocols and test tools to provide logistic services for the development of embedded devices.

Besides, Linux serial port terminals have strong customizability. With script language, it can customize and manage serial port, turn on/off serial port, send and receive data, debug, control serial port parameters and so on. It can be connected with different IDEs for debugging, including muduo, eclipse and so on. And with the help of various development kits, various versions of Linux can be installed on it.

Moreover, Linux serial port terminals are price-competitive, durable and long-lasting. In the meantime, they maintain strong portability. With the support of the battery and USB interface, they can be used even without power supply.

To sum up, Linux serial port terminals have strong practicality. with relatively low costs, they can be applied to various areas, providing fast and reliable services. The following code is an example of how to use the serial port of Linux:

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char *argv[])

{

int fd;

int z, res;

struct termios tty;

struct termios tty_old;

char buf[]={‘1′,’2′,’3′,’4′,’5’ };

fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK);

if (0 > fd)

{

printf(“Error no is : %d\n”, errno);

printf(“Error description is : %s\n”,strerror(errno));

return -1;

}

res = tcgetattr(fd, &tty);

if(0 > res)

{

printf(“Error no is : %d\n”, errno);

printf(“Error description is : %s\n”,strerror(errno));

return -1;

}

tty_old = tty;

tty.c_cflag = B9600 | CS8 | CLOCAL | CREAD;

tty.c_oflag = 0;

tty.c_lflag = 0;

/* no echo, no visual editing */

tty_old.c_lflag &= ~ICANON;

/* Onl CR -> NL */

tty_old.c_iflag &= IXON;

/* Control Xon/Xoff */

tty_old.c_iflag &= ~ECHO;

/* no echoing */

tty_old.c_iflag &= ~ECHOE;

/* no echoing of erased chars */

tty_old.c_iflag &= ~ECHONL;

/* no NL -> CR/NL */

tty_old.c_iflag &= ~ISIG;

/* no interruption on INTR, QUIT and SUSP */

tty_old.c_iflag &= ~IEXTEN;

/* disable Goto NoSh */

tty.c_cc[VTIME] = 0;

tty.c_cc[VMIN] = 0;

cfsetispeed(&tty, B9600);

cfsetospeed(&tty, B9600);

tcflush(fd, TCIFLUSH);

if (tcsetattr(fd, TCSANOW, &tty) != 0)

{

printf(“Error no is : %d\n”, errno);

printf(“Error description is : %s\n”,strerror(errno));

return -1;

}

z = write(fd, buf, 5);

if (0 > z)

{

printf(“Error no is : %d\n”, errno);

printf(“Error description is : %s\n”,strerror(errno));

return -1;

}

return 0;

}

In conclusion, Linux serial port terminal has strong practicality, and it is widely used in industrial and scientific fields for embedded device development and industrial debugging. Meanwhile, its low cost and high performance make it an ideal choice for users.


数据运维技术 » Linux 串口终端的实用性研究(linux串口终端)