66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
|
|
//
|
||
|
|
// Created by matrixai on 3/26/24.
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifndef TRAIN_RFID_LINUX_BASECOMPORT_H
|
||
|
|
#define TRAIN_RFID_LINUX_BASECOMPORT_H
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <ctype.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <sys/types.h>
|
||
|
|
#include <sys/stat.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <arpa/inet.h>
|
||
|
|
#include <sys/socket.h>
|
||
|
|
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <fcntl.h>
|
||
|
|
#include <termios.h>
|
||
|
|
|
||
|
|
#include "AppCommon.h"
|
||
|
|
|
||
|
|
#define SOCKET_TIME_OUT_SETTING 10
|
||
|
|
|
||
|
|
class BaseComPort
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
BaseComPort();
|
||
|
|
~BaseComPort();
|
||
|
|
|
||
|
|
//打开comport通信
|
||
|
|
int32_t ttyOpen(std::string strName);
|
||
|
|
//关闭comport通信
|
||
|
|
int32_t ttyClose();
|
||
|
|
//设定波特率
|
||
|
|
int32_t ttySetBaud(int nbaud, int ndatabits, std::string nparitybits, int nstopbits);
|
||
|
|
//读取comport数据
|
||
|
|
int32_t ttyRead();
|
||
|
|
//写入comport数据
|
||
|
|
int32_t ttyWrite(char *buf, int32_t count);
|
||
|
|
//是否运行
|
||
|
|
bool bRuning();
|
||
|
|
//获取Buffer信息
|
||
|
|
int32_t vGetBuffer(char *chOutBuff, int32_t nSize);
|
||
|
|
|
||
|
|
int32_t vGetMaxBufferSize();
|
||
|
|
|
||
|
|
|
||
|
|
private:
|
||
|
|
|
||
|
|
int32_t fd = -1;
|
||
|
|
//运行状态
|
||
|
|
bool bRun = false;
|
||
|
|
|
||
|
|
char chbuffer[AEI_COMM_BUFFER_SIZE] = {0};
|
||
|
|
|
||
|
|
struct termios ntm; //串口设备选项
|
||
|
|
std::map<std::string, int32_t> m_map_parity;
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
#endif //TRAIN_RFID_LINUX_BASECOMPORT_H
|