/[H7]/trunk/H7 Server/Serial.cpp
ViewVC logotype

Diff of /trunk/H7 Server/Serial.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 38 by hedin, Thu Feb 1 09:21:43 2007 UTC revision 39 by hedin, Thu Feb 1 13:49:01 2007 UTC
# Line 57  void CSerial::open(CString port, int bit Line 57  void CSerial::open(CString port, int bit
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,
# Line 65  void CSerial::open() Line 66  void CSerial::open()
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());
# Line 74  void CSerial::open() Line 76  void CSerial::open()
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();
# Line 81  void CSerial::open() Line 84  void CSerial::open()
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;
# Line 90  void CSerial::open() Line 94  void CSerial::open()
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();
# Line 122  unsigned char CSerial::readByte() Line 127  unsigned char CSerial::readByte()
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();

Legend:
Removed from v.38  
changed lines
  Added in v.39

  ViewVC Help
Powered by ViewVC 1.1.20