Logo Search packages:      
Sourcecode: qmk-groundstation version File versions  Download package

bool Win_QextSerialPort::open ( OpenMode  mode = 0  )  [virtual]

Opens a serial port. Note that this function does not specify which device to open. If you need to open a device by name, see Win_QextSerialPort::open(const char*). This function has no effect if the port associated with the class is already open. The port is also configured to the current settings, as stored in the Settings structure.

Implements QextSerialBase.

Definition at line 144 of file win_qextserialport.cpp.

References setBaudRate(), setDataBits(), setFlowControl(), setParity(), setStopBits(), and setTimeout().

                                           {
      unsigned long confSize = sizeof(COMMCONFIG);
      Win_CommConfig.dwSize = confSize;
      
      LOCK_MUTEX();
      if (mode == QIODevice::NotOpen)
            return isOpen();
      if (!isOpen()) {
            /*open the port*/
            Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
            if (Win_Handle!=INVALID_HANDLE_VALUE) {
                  /*set open mode*/
                  QIODevice::open(mode);
                  
                  /*configure port settings*/
                  GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
                  GetCommState(Win_Handle, &(Win_CommConfig.dcb));
                  
                  /*set up parameters*/
                  Win_CommConfig.dcb.fBinary=TRUE;
                  Win_CommConfig.dcb.fInX=FALSE;
                  Win_CommConfig.dcb.fOutX=FALSE;
                  Win_CommConfig.dcb.fAbortOnError=FALSE;
                  Win_CommConfig.dcb.fNull=FALSE;
                  setBaudRate(Settings.BaudRate);
                  setDataBits(Settings.DataBits);
                  setStopBits(Settings.StopBits);
                  setParity(Settings.Parity);
                  setFlowControl(Settings.FlowControl);
                  setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec);
                  SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
            }
      }
      UNLOCK_MUTEX();
      return isOpen();
}


Generated by  Doxygen 1.6.0   Back to index