57 |
|
|
58 |
void CSerial::open() |
void CSerial::open() |
59 |
{ |
{ |
60 |
|
// Åbner Serial porten. |
61 |
mComport = CreateFile( mPortstr, |
mComport = CreateFile( mPortstr, |
62 |
GENERIC_READ|GENERIC_WRITE, |
GENERIC_READ|GENERIC_WRITE, |
63 |
0, |
0, |
66 |
FILE_ATTRIBUTE_NORMAL, |
FILE_ATTRIBUTE_NORMAL, |
67 |
0); |
0); |
68 |
|
|
69 |
|
// Error check. |
70 |
if (mComport == INVALID_HANDLE_VALUE) |
if (mComport == INVALID_HANDLE_VALUE) |
71 |
{ |
{ |
72 |
throw std::exception(writeLastError().c_str()); |
throw std::exception(writeLastError().c_str()); |
76 |
dcb.DCBlength = sizeof(DCB); |
dcb.DCBlength = sizeof(DCB); |
77 |
mDcbRestore.DCBlength = sizeof(DCB); |
mDcbRestore.DCBlength = sizeof(DCB); |
78 |
|
|
79 |
|
// Error check. |
80 |
if (!GetCommState(mComport,&dcb) || !GetCommState(mComport,&mDcbRestore)) |
if (!GetCommState(mComport,&dcb) || !GetCommState(mComport,&mDcbRestore)) |
81 |
{ |
{ |
82 |
std::string error = writeLastError(); |
std::string error = writeLastError(); |
84 |
throw std::exception(error.c_str()); |
throw std::exception(error.c_str()); |
85 |
} |
} |
86 |
|
|
87 |
|
// Definerer Serial Conf. |
88 |
dcb.BaudRate = mBitrate; |
dcb.BaudRate = mBitrate; |
89 |
dcb.ByteSize = 8; |
dcb.ByteSize = 8; |
90 |
dcb.Parity = NOPARITY; |
dcb.Parity = NOPARITY; |
94 |
dcb.fParity = false; |
dcb.fParity = false; |
95 |
dcb.fDsrSensitivity = false; |
dcb.fDsrSensitivity = false; |
96 |
|
|
97 |
|
// Error check. |
98 |
if (!SetCommState(mComport,&dcb)) |
if (!SetCommState(mComport,&dcb)) |
99 |
{ |
{ |
100 |
std::string error = writeLastError(); |
std::string error = writeLastError(); |
127 |
throw std::exception("Port not opened"); |
throw std::exception("Port not opened"); |
128 |
|
|
129 |
ReadFile(mComport,&out,1,&size,0); |
ReadFile(mComport,&out,1,&size,0); |
130 |
|
// Error check. |
131 |
if (size != 1) |
if (size != 1) |
132 |
{ |
{ |
133 |
std::string error = writeLastError(); |
std::string error = writeLastError(); |