nim_duilib/examples/proto_debuger/serial_port.h
2021-09-20 22:37:32 +08:00

37 lines
904 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <iostream>
using namespace std;
class SerialPort
{
public:
SerialPort();
~SerialPort();
// 打开串口,成功返回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 = 115200, char parity = 0, char databit = 8, char stopbit = 1, char synchronizeflag = 0);
//关闭串口,参数待定
void Close();
//发送数据或写数据成功返回发送数据长度失败返回0
int Send(string dat);
//接受数据或读数据成功返回读取实际数据的长度失败返回0
string Receive();
private:
int pHandle[16];
char synchronizeflag;
};