Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed
#ifndef __SERIALCONNECTION_H#define __SERIALCONNECTION_H#include <crtdbg.h>#include <tchar.h>#include <windows.h>#include <stdio.h>#include <process.h>#include "CanProtoMessage.h"#include "compiler.h"#define SERIAL_INPUT_BUFFER_SIZE 1024#define SERIAL_READ_BUFFER_SIZE 8192#define QUEUE_PLACES 32class SerialConnection{public:// Baudratetypedef enum{EBaudUnknown = -1, // UnknownEBaud110 = CBR_110, // 110 bits/secEBaud300 = CBR_300, // 300 bits/secEBaud600 = CBR_600, // 600 bits/secEBaud1200 = CBR_1200, // 1200 bits/secEBaud2400 = CBR_2400, // 2400 bits/secEBaud4800 = CBR_4800, // 4800 bits/secEBaud9600 = CBR_9600, // 9600 bits/secEBaud14400 = CBR_14400, // 14400 bits/secEBaud19200 = CBR_19200, // 19200 bits/sec (default)EBaud38400 = CBR_38400, // 38400 bits/secEBaud56000 = CBR_56000, // 56000 bits/secEBaud57600 = CBR_57600, // 57600 bits/secEBaud115200 = CBR_115200, // 115200 bits/secEBaud128000 = CBR_128000, // 128000 bits/secEBaud256000 = CBR_256000, // 256000 bits/sec}EBaudrate;// Data bits (5-8)typedef enum{EDataUnknown = -1, // UnknownEData5 = 5, // 5 bits per byteEData6 = 6, // 6 bits per byteEData7 = 7, // 7 bits per byteEData8 = 8 // 8 bits per byte (default)}EDataBits;// Parity schemetypedef enum{EParUnknown = -1, // UnknownEParNone = NOPARITY, // No parity (default)EParOdd = ODDPARITY, // Odd parityEParEven = EVENPARITY, // Even parityEParMark = MARKPARITY, // Mark parityEParSpace = SPACEPARITY // Space parity}EParity;// Stop bitstypedef enum{EStopUnknown = -1, // UnknownEStop1 = ONESTOPBIT, // 1 stopbit (default)EStop1_5 = ONE5STOPBITS,// 1.5 stopbitEStop2 = TWOSTOPBITS // 2 stopbits}EStopBits;public:SerialConnection(LPCTSTR portName,EBaudrate baudRate,EDataBits byteSize,EParity parity, EStopBits stopBits);~SerialConnection();bool open(void);bool close(void);bool isOpen(void);bool write(LPCVOID lpBuffer, unsigned int nNumberOfBytesToWrite);HANDLE getHandle(void);bool getMessage(CanProtoMessage *cpm);protected:LPCTSTR uportName;EBaudrate ubaudRate;EDataBits ubyteSize;EParity uparity;EStopBits ustopBits;};#endif