58 |
|
|
59 |
void CSerial::open() |
void CSerial::open() |
60 |
{ |
{ |
61 |
|
CString comport = "\\\\.\\"; |
62 |
|
comport += mPortstr; |
63 |
// Åbner Serial porten. |
// Åbner Serial porten. |
64 |
mComport = CreateFile( mPortstr, |
mComport = CreateFile( comport, |
65 |
GENERIC_READ|GENERIC_WRITE, |
GENERIC_READ|GENERIC_WRITE, |
66 |
0, |
0, |
67 |
0, |
0, |
113 |
if (mIsopen) |
if (mIsopen) |
114 |
{ |
{ |
115 |
while (getComstat().cbOutQue >0) |
while (getComstat().cbOutQue >0) |
116 |
|
{ |
117 |
Sleep(5); |
Sleep(5); |
118 |
|
} |
119 |
SetCommState(mComport,&mDcbRestore); |
SetCommState(mComport,&mDcbRestore); |
120 |
CloseHandle(mComport); |
CloseHandle(mComport); |
121 |
mIsopen = false; |
mIsopen = false; |
129 |
unsigned long size; |
unsigned long size; |
130 |
|
|
131 |
if (!mIsopen) |
if (!mIsopen) |
132 |
|
{ |
133 |
throw std::exception("Port not opened"); |
throw std::exception("Port not opened"); |
134 |
|
} |
135 |
|
|
136 |
ReadFile(mComport,&out,1,&size,0); |
ReadFile(mComport,&out,1,&size,0); |
137 |
// Error check. |
// Error check. |
141 |
CloseHandle(mComport); |
CloseHandle(mComport); |
142 |
throw std::exception(error.c_str()); |
throw std::exception(error.c_str()); |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
//printByte("Read", out); |
//printByte("Read", out); |
147 |
return out; |
return out; |