You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
995 B
37 lines
995 B
|
|
#ifndef _WWSerialPort_H
|
|
#define _WWSerialPort_H
|
|
|
|
class WWSerialPort
|
|
{
|
|
public:
|
|
WWSerialPort();
|
|
~WWSerialPort();
|
|
|
|
// 打开串口,成功返回true,失败返回false
|
|
// portname(串口名): 在Windows下是"COM1""COM2"等,在Linux下是"/dev/ttyS1"等
|
|
// baudrate(波特率): 9600、19200、38400、43000、56000、57600、115200
|
|
// parity(校验位): 0为无校验,1为奇校验,2为偶校验,3为标记校验
|
|
// databit(数据位): 4-8,通常为8位
|
|
// stopbit(停止位): 1为1位停止位,2为2位停止位,3为1.5位停止位
|
|
// synchronizable(同步、异步): 0为异步,1为同步
|
|
bool open(const char* portname, int baudrate, char parity, char databit, char stopbit, char synchronizeflag=1);
|
|
|
|
//关闭串口,参数待定
|
|
void close();
|
|
|
|
//发送数据或写数据,成功返回发送数据长度,失败返回0
|
|
int send(const void *buf,int len);
|
|
|
|
//接受数据或读数据,成功返回读取实际数据的长度,失败返回0
|
|
int receive(void *buf,int maxlen);
|
|
//
|
|
void send_command(int argc, int cmd, int param);
|
|
void* recv_results();
|
|
//
|
|
private:
|
|
int pHandle[16];
|
|
char synchronizeflag;
|
|
};
|
|
|
|
#endif
|