Hello! I have several functions for working with COM-port. Here is a small listing, that I used in C++ Builder:

Qt Code:
  1. //function for opening COM-port
  2. void COMOpen(portname)
  3. {
  4. DCB dcb;
  5. COMMTIMEOUTS timeouts; //structure for timeouts
  6.  
  7. //open COM-port!
  8. COMport = CreateFile(portname.c_str(),GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
  9.  
  10. if(COMport == INVALID_HANDLE_VALUE) { //if error
  11. QMessageBox::warning(this, "Error", "No such COM!");
  12. return;
  13. }
  14. }
  15.  
  16. //function for closing COM-port
  17. void COMClose()
  18. {
  19. CloseHandle(COMport);
  20. COMport=0;
  21. handle=0;
  22. }
  23.  
  24.  
  25. on_pushButton_clicked() // function send pulse on button click
  26. {
  27. COMOpen(portname); //initialized and open port
  28.  
  29. int i;
  30. EscapeCommFunction(COMport, SETDTR); //set hight level DTR
  31. ui->label->setText("Sending pulse to com-port..."); //sign about sending pulse
  32. i=0;
  33. while (i<3000000) { // wait a little, pulse should have a duration
  34. i++;
  35. Application->ProcessMessages();
  36. }
  37. EscapeCommFunction(COMport, CLRDTR); // free DTR pin
  38. ui->label->setText(""); //pulse finished, so remove label
  39. COMClose(portname); //close COM-port
  40.  
  41. }
To copy to clipboard, switch view to plain text mode 

When I include the code to Qt creator I get errors. I'm novice in Qt. Could someone make simple example, which open COM1, for instance, with this code? Thanks a lot!