Subversion Repositories HomeAutomation

Rev

Rev 270 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
270 johboh 1
#ifndef __SERIALCONNECTION_H
2
#define __SERIALCONNECTION_H
3
 
4
#include <crtdbg.h>
5
#include <tchar.h>
6
#include <windows.h>
7
#include <stdio.h>
8
#include <process.h>
9
#include "CanProtoMessage.h"
10
#include "compiler.h"
11
 
12
#define SERIAL_INPUT_BUFFER_SIZE 1024
13
#define SERIAL_READ_BUFFER_SIZE 8192
14
#define QUEUE_PLACES 32
15
 
16
 
17
class SerialConnection
18
{
19
public:
20
	// Baudrate
21
	typedef enum
22
	{
23
		EBaudUnknown = -1,			// Unknown
24
		EBaud110     = CBR_110,		// 110 bits/sec
25
		EBaud300     = CBR_300,		// 300 bits/sec
26
		EBaud600     = CBR_600,		// 600 bits/sec
27
		EBaud1200    = CBR_1200,	// 1200 bits/sec
28
		EBaud2400    = CBR_2400,	// 2400 bits/sec
29
		EBaud4800    = CBR_4800,	// 4800 bits/sec
30
		EBaud9600    = CBR_9600,	// 9600 bits/sec
31
		EBaud14400   = CBR_14400,	// 14400 bits/sec
32
		EBaud19200   = CBR_19200,	// 19200 bits/sec (default)
33
		EBaud38400   = CBR_38400,	// 38400 bits/sec
34
		EBaud56000   = CBR_56000,	// 56000 bits/sec
35
		EBaud57600   = CBR_57600,	// 57600 bits/sec
36
		EBaud115200  = CBR_115200,	// 115200 bits/sec
37
		EBaud128000  = CBR_128000,	// 128000 bits/sec
38
		EBaud256000  = CBR_256000,	// 256000 bits/sec
39
	}
40
	EBaudrate;
41
 
42
	// Data bits (5-8)
43
	typedef enum
44
	{
45
		EDataUnknown = -1,			// Unknown
46
		EData5       =  5,			// 5 bits per byte
47
		EData6       =  6,			// 6 bits per byte
48
		EData7       =  7,			// 7 bits per byte
49
		EData8       =  8			// 8 bits per byte (default)
50
	}
51
	EDataBits;
52
 
53
	// Parity scheme
54
	typedef enum
55
	{
56
		EParUnknown = -1,			// Unknown
57
		EParNone    = NOPARITY,		// No parity (default)
58
		EParOdd     = ODDPARITY,	// Odd parity
59
		EParEven    = EVENPARITY,	// Even parity
60
		EParMark    = MARKPARITY,	// Mark parity
61
		EParSpace   = SPACEPARITY	// Space parity
62
	}
63
	EParity;
64
 
65
	// Stop bits
66
	typedef enum
67
	{
68
		EStopUnknown = -1,			// Unknown
69
		EStop1       = ONESTOPBIT,	// 1 stopbit (default)
70
		EStop1_5     = ONE5STOPBITS,// 1.5 stopbit
71
		EStop2       = TWOSTOPBITS	// 2 stopbits
72
	} 
73
	EStopBits;
74
 
75
 
76
public:
77
	SerialConnection(LPCTSTR portName,EBaudrate baudRate,EDataBits byteSize,EParity parity, EStopBits stopBits);
78
	~SerialConnection();
79
	bool open(void);
80
	bool close(void);
81
	bool isOpen(void);
82
	bool write(LPCVOID lpBuffer, unsigned int nNumberOfBytesToWrite);
83
	HANDLE getHandle(void);
84
	bool getMessage(CanProtoMessage *cpm);
85
 
86
protected:
87
	LPCTSTR uportName;
88
	EBaudrate ubaudRate;
89
	EDataBits ubyteSize;
90
	EParity uparity;
91
	EStopBits ustopBits;
92
 
93
};	
94
 
95
 
96
#endif