当前位置: 技术问答>linux和unix
请教UNIX下的串口编程
来源: 互联网 发布时间:2014-11-08
本文导语: 现在有些串口编程的工作需要在UNIX下完成(具体工作是通过串口通信的方式将一些指令发送给程控交换机)。在此请教一下,需要调用些什么函数,有没有像Windows的TAPI那样封装好的API? | 更...
现在有些串口编程的工作需要在UNIX下完成(具体工作是通过串口通信的方式将一些指令发送给程控交换机)。在此请教一下,需要调用些什么函数,有没有像Windows的TAPI那样封装好的API?
|
更文件操作一样...
unix函数: open, write, read 等.
unix函数: open, write, read 等.
|
/*
This is like all programs in the Linux Programmer's Guide meant
as a simple practical demonstration.
It can be used as a base for a real terminal program.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyS0"
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
void child_handler(int s)
{
STOP=TRUE;
}
main()
{
int size ,i;
int fd;
unsigned char c;
unsigned char buff[1024];
struct termios oldtio,newtio,oldstdtio,newstdtio;
struct sigaction sa;
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd
This is like all programs in the Linux Programmer's Guide meant
as a simple practical demonstration.
It can be used as a base for a real terminal program.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyS0"
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
void child_handler(int s)
{
STOP=TRUE;
}
main()
{
int size ,i;
int fd;
unsigned char c;
unsigned char buff[1024];
struct termios oldtio,newtio,oldstdtio,newstdtio;
struct sigaction sa;
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd