SerialPort 1.0beta
|
serialport.h文件参考
一些串口例程,包括打开串口、配置串口以及关闭串口 更多...
函数 | |
int | open_port (int port) |
int | close_port (int fd) |
int | setup_port (int fd, int speed, int data_bits, int parity, int stop_bits) |
详细描述
一些串口例程,包括打开串口、配置串口以及关闭串口
Copyleft (C) 2010 Late Lee This program is tested on LINUX PLATFORM, WITH GCC 4.x. The program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. Please feel free to use the program, and I feel free to ignore the related issues. Any questions or suggestions, or bugs, please contact me at $ echo -n "aHR0cDovL3d3dy5sYXRlbGVlLm9yZwo=" | base64 -d or e-mail to $ echo -n "bGF0ZWxlZUAxNjMuY29tCg==" | base64 -d if you want to do this.
- 日期:
- 2011年1月10日
函数文档
int close_port | ( | int | fd | ) |
close_port - 关闭串口
- 参数:
-
fd : 由open_port()返回的fd
- 返回:
- 成功时返回0,否则返回-1并给出相应提示信息
int open_port | ( | int | port | ) |
open_port - 打开串口
- 参数:
-
port : 串口号,如open_port(1)表示打开串口1
- 返回:
- 成功时返回串口设备文件描述符,否则,返回-1并给出相应提示信息
- 注解:
- 在类UNIX系统中,每个串口都有一设备文件相对应(在/dev目录中),但每个系统 又不相同,下面是一些系统中对应的串口及设备文件(最后一行为Windows系统)。
System Port 1 Port 2 IRIX /dev/ttyf1 /dev/ttyf2 HP-UX /dev/tty1p0 /dev/tty2p0 Solaris/SunOS /dev/ttya /dev/ttyb Linux /dev/ttyS0 /dev/ttyS1 Linux /dev/ttyUSB0 /dev/ttyUSB1 (usb-serial converter) Digital UNIX /dev/tty01 /dev/tty02 (Windows COM1 COM2)
参数为串口号,比如,open_port(1)是打开系统中第1个串口设备。
int setup_port | ( | int | fd, |
int | speed, | ||
int | data_bits, | ||
int | parity, | ||
int | stop_bits | ||
) |
setup_port - 设置串口各种参数
- 参数:
-
fd : 串口文件描述符 speed : 波特率 data_bits : 数据位 parity : 校验位 stop_bits : 停止位
- 返回:
- 成功时返回0,否则返回-1并给出相应提示信息
- 注解:
- 该程序中一些设置优先考虑最常用的,如波特率为115200,数据位为8位
Generated at 2011年一月17日 星期一 10:44:34 for SerialPort by
