当前位置: 技术问答>linux和unix
在linux下如何驱动本机的串口
来源: 互联网 发布时间:2016-01-15
本文导语: 在linux下如何驱动本机的串口,小弟急用 | #include /* perror, printf, puts, fprintf, fputs */ #include /* read, write, close */ #include /* open */ #incl...
在linux下如何驱动本机的串口,小弟急用
|
#include /* perror, printf, puts, fprintf, fputs */
#include /* read, write, close */
#include /* open */
#include
#include /* bzero, memcpy */
#include /* CHAR_MAX */
//#include "vardef.h" /* int, INT16, INT8, Uint, UINT16, UINT8 */
#include /* tcgetattr, tcsetattr */
//#include
class CSerialPort
{
public:
CSerialPort();
~CSerialPort();
int OpenComPort(int ComPort, int baudrate, int databit,
const char *stopbit, char parity);
void CloseComPort (void);
int ReadComPort (void *data, int datalength);
int WriteComPort (unsigned char * data, int datalength);
//int SendFile (const char *pathname);
virtual void GetData(double &RTData, double &TotalData);
private:
int fd; //File descriptor for the port
struct termios termios_old, termios_new;
fd_set fs_read, fs_write;
struct timeval tv_timeout;
//struct sigaction sigaction_io; /* definition of signal action */
//int SetPortSig ();
// static void signal_handler_IO (int status);
void SetBaudrate (int);
int GetBaudrate ();
void SetDataBit (int databit);
int BAUDRATE (int baudrate);
int _BAUDRATE (int baudrate);
int SetPortAttr (int baudrate, int databit,
const char *stopbit, char parity);
void SetStopBit (const char *stopbit);
void SetParityCheck (char parity);
};
#endif