Results 1 to 6 of 6

Thread: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

  1. #1
    Join Date
    Nov 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    Hi everybody,

    I need some help for Serial Port programming (My environment is :Win7 64Bit, QT Creator 2.4.1, QT 4.7.4 32bit).

    1) First of all I'd like to know if I can use Windows API's function suc as CreateFile, WriteFile etc in order to write the code.
    I tryed to write some lines, using the "CreateFile" function but an error accurs on building : It is not possible to convert from const char[4] to LPCWSTR.
    This is the code :

    HANDLE hSerial;
    hSerial = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if(hSerial==INVALID_HANDLE_VALUE){
    if(GetLastError()==ERROR_FILE_NOT_FOUND){
    //--code
    }
    //--some other error occurred. Inform user.
    }

    2) Is there any other simplier way for programming serial ports in QT?
    I looked up in the forum and tried downloading QTserialPort but I can't manage to use it...

    Anybody could please help a newbe??? I'm going crazy
    Thank you in advance

    Giovanni

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    You can use ready made libraries:

    QSerialDevice - it supports Qt 4.7.4, but it development is stopped.

    QtSerialPort - is a fork of QSerialDevice and is actively developing, but for it needs Qt >= 4.8.0.

    I recommend QtSerialPort, though you can try and other libraries...

  3. #3
    Join Date
    Nov 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    Thank you Kuzulis, I'll try to use QTSerialPort Library with QT 4.8

    Besides this, could you give me an hint on how to work out the "step 1" problem I wrote?
    Why can't I build that simple code without errors?

    Besides the serial port programming methods I need to UNDERSTAND what I am doing and why that error occurs...("It is not possible to convert from const char[4] to LPCWSTR" in Italian "Non e' possibile convertire da const char[4] a LPCWSTR")

    thanks to those who can give me an help

    Giovanni

  4. #4
    Join Date
    Feb 2011
    Location
    Romania
    Posts
    53
    Thanks
    1
    Thanked 11 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    Quote Originally Posted by pitopito View Post
    Besides the serial port programming methods I need to UNDERSTAND what I am doing and why that error occurs...
    Your project is set to use unicode character set. So first parameter of CreateFile functions is wchar_t* type and not char*. You need to use
    Qt Code:
    1. CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    Thank you, how should I avoid the "undeclared identifier" message when building using L("COM1") ?

    Gio

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Serial Port Programming (QT 4.7.4, Windows Seven 64Bit)

    Lose the brackets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. serial port programming and fancy telemtry control.
    By hjjayakrishnan in forum Newbie
    Replies: 9
    Last Post: 7th July 2012, 07:35
  2. Replies: 3
    Last Post: 22nd December 2011, 06:39
  3. Windows programming in Qt (serial communication)
    By bnilsson in forum General Programming
    Replies: 17
    Last Post: 9th February 2010, 19:17
  4. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 16:51
  5. serial port programming in qt
    By sar_van81 in forum Qt Programming
    Replies: 46
    Last Post: 13th June 2007, 13:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.