Red Hat Linux 9.0 测试编译
默认com1 9600,n,8,1
1.接上板子的串口线在com1,接上usb线
2.编译: gcc -o comtest comtest.c
3.执行: ./comtest
4.鼠标移动
www.laorenshen.cn
2010.05
comtest.c 代码如下:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{
struct termios newtio,oldtio;
if ( tcgetattr( fd,&oldtio) != 0) {
perror("SetupSerial 1");
return -1;
}
bzero( &newtio, sizeof( newtio ) );
newtio.c_cflag |= CLOCAL | CREAD;
newtio.c_cflag &= ~CSI