The stupid way to see if the serial port is available under Linux __linux

Source: Internet
Author: User

A recent attempt to migrate a gateway program from the VxWorks platform to the Linux platform. In the serial port has encountered some problems, here record.
First, under VxWorks, use the devs command to view the device:

-> devs
DRV name
  0/null 1/tyco/0 1/tyco/1 2/pcconsole/0 2/pcconsole/1
  9 Host:
  4/ram
 11/vio
  4/ahci01:1
value = 0 = 0x0

The source program used the serial port is/tyco/0 and/TYCO/1, and then colleagues said that Linux system does not have a serial drive, I think this how possible. So, under Linux with ls/dev/tty* view a bit, there are a lot of AH. So, how to determine which serial port is available.
I'll start with DMESG | grep TTY looks at which serial devices are initialized during the system startup, and the output is as follows:

[    0.000000] console [tty0] enabled
[    1.478484] 00:0c ttyS2 at I/o 0x3e8 (IRQ = 5, Base_baud = 115200) is a 16550A
[    1.500255] 00:0d ttyS3 at I/o 0x2e8 (IRQ = ten, Base_baud = 115200) is a 16550A

Tty0 is the current control terminal that executes the command echo 123456 >/dev/tty0 and finds that it will print "123456" under the current terminal. Similarly, we tested echo 123456 >/dev/ttys2 and echo 123456 >/dev/ttys3 and found no prompts for errors, while others (such as: ttyS0) prompted errors.
In addition, we can use cat/proc/tty/driver/serial to view the serial port driver information, the partial output is as follows:

serinfo:1.0 Driver Revision: 0:uart:unknown port:000003f8 irq:4 1:uart:unknown port:000002f8 irq:3
2: uart:16550a port:000003e8 irq:5 tx:0 rx:0 3:uart:16550a port:000002e8 irq:10 tx:0 rx:0 4:uart:unknown port:0000
0000 irq:0
5:uart:unknown port:00000000 irq:0 6:uart:unknown port:00000000 irq:0
...
31:uart:unknown port:00000000 irq:0

Obviously, the information here is exactly right when the system starts to print, 16550A is the model of the programmable serial interface chip. In addition, some useful information can be seen through commands such as cat/proc/devices and Cat/proc/tty/drivers and Ls-l/dev/tty*.
Through these stupid methods, we can basically determine the/tyco/0 and/TYCO/1 of the VxWorks system for the/DEV/TTYS2 and/DEV/TTYS3 of the Linux system. Then you can modify the corresponding code to verify, or serial port programming to test, for example:

int FD;
FD = open ("/dev/ttys2", O_RDWR);
if (fd = = 1)
{
    perror ("serial port 1) failed to open. ");
}

More detailed serial port programming, can refer to: http://www.cnblogs.com/lovemo1314/archive/2010/10/29/1864327.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.