Home > Mobile >  Why is set to open a serial port, with isopen shows not open?
Why is set to open a serial port, with isopen shows not open?

Time:11-22

Void Serial: : openPort_btn (bool)
{
/* -- -- -- -- -- -- -- -- -- -- PortName -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
The switch (UI - & gt; Com_cmb - & gt; CurrentIndex ()) {
Case 0:
Global_port. SetPortName (" COM1 ");
break;
Case 1:
COM2 global_port. SetPortName (" ");
break;
Case 2:
Global_port. SetPortName (" COM3 ");
break;
Default:
COM4 global_port. SetPortName (" ");
break;
}
/* -- -- -- -- -- -- -- -- -- -- BaudRate -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
The switch (UI - & gt; BaudRate_cmb - & gt; CurrentIndex ()) {
Case 0:
Global_port. SetBaudRate (QSerialPort: : Baud115200);
break;
Case 1:
Global_port. SetBaudRate (QSerialPort: : Baud57600);
break;
Case 2:
Global_port. SetBaudRate (QSerialPort: : Baud38400);
break;
Case 3:
Global_port. SetBaudRate (QSerialPort: : Baud19200);
break;
Case 4:
Global_port. SetBaudRate (QSerialPort: : Baud9600);
break;
Default:
Global_port. SetBaudRate (QSerialPort: : Baud4800);
break;
}
/* -- -- -- -- -- -- -- -- -- -- DateBit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */
The switch (UI - & gt; DateBits_cmb - & gt; CurrentIndex ()) {
Case 0:
Global_port. SetDataBits (QSerialPort: : Data8);
break;
Case 1:
Global_port. SetDataBits (QSerialPort: : Data7);
break;
Case 2:
Global_port. SetDataBits (QSerialPort: : Data6);
break;
Default:
Global_port. SetDataBits (QSerialPort: : Data5);
break;
}
/* -- -- -- -- -- -- -- -- -- -- check bit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */
The switch (UI - & gt; CheckBit_cmb - & gt; CurrentIndex ()) {
Case 0:
Global_port. SetParity (QSerialPort: : NoParity);
break;
Case 1:
Global_port. SetParity (QSerialPort: : EvenParity);
Default:
Global_port. SetParity (QSerialPort: : OddParity);
break;
}
/* -- -- -- -- -- -- -- -- -- -- the Stop bit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */
The switch (UI - & gt; StopBit_cmb - & gt; CurrentIndex ()) {
Case 0:
Global_port. SetStopBits (QSerialPort: : OneStop);
break;
Case 1:
Global_port. SetStopBits (QSerialPort: : OneAndHalfStop);
break;
Default:
Global_port. SetStopBits (QSerialPort: : TwoStop);
break;
}
/* -- -- -- -- -- -- -- -- -- -- the Open -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */
Global_port. Open (QIODevice: : ReadWrite);
QDebug () & lt; /* -- -- -- -- -- -- -- -- -- -- Check -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - */
If (global_port. Open (QIODevice: : ReadWrite))
{
QMessageBox: : information (this, "the Open success!" , "already open serial");
}
The else
{
QMessageBox: : critical (this, "Fail", "Fail to open the serial");
}
}


Qt as above code, serial port to open the failure condition, who met a similar situation can help tell why?
  •  Tags:  
  • Qt
  • Related