Results 1 to 8 of 8

Thread: bluetooth communications (RS-232)

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default bluetooth communications (RS-232)

    I have a working code in dev-c++ where I'm transmitting from a host PC to a mobile robot using bluetooth. However, I'm getting errors when I try to integrate the working program into my Qt GUI. I'm getting this particular error:

    In member function 'void Bluetooth::initialize()': error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'

    Here's my code:
    bluetooth.h
    Qt Code:
    1. #ifndef BLUETOOTH_H
    2. #define BLUETOOTH_H
    3.  
    4. #include <windows.h>
    5.  
    6. class Bluetooth {
    7. public:
    8. Bluetooth();
    9. ~Bluetooth();
    10.  
    11. void initialize();
    12. void transmit(int right, int left);
    13.  
    14. private:
    15. DWORD bytes_written;
    16. BOOL Status;
    17. HANDLE SerialHandle;
    18. DCB SerialConfigs;
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    bluetooth.cpp
    Qt Code:
    1. #include <QDebug>
    2. #include "bluetooth.h"
    3. #include "settings.h"
    4.  
    5. Bluetooth::Bluetooth() {}
    6.  
    7. Bluetooth::~Bluetooth() {}
    8.  
    9. void Bluetooth::initialize() {
    10. qDebug()<<"Initializing BlueTooth...";
    11. Status = 0;
    12. SerialHandle = CreateFile("COM5",
    13. GENERIC_WRITE,
    14. 0,
    15. NULL,
    16. OPEN_EXISTING,
    17. FILE_ATTRIBUTE_NORMAL,
    18. NULL);
    19.  
    20. if(SerialHandle==INVALID_HANDLE_VALUE) {
    21. if(GetLastError()==ERROR_FILE_NOT_FOUND) {
    22. qDebug()<<"E: Serial Port Does Not Exist!";
    23. }
    24. qDebug()<<"An Error Occured!";
    25. }
    26. ZeroMemory(&SerialConfigs, sizeof(SerialConfigs));
    27. SerialConfigs.DCBlength = sizeof(SerialConfigs);
    28. if (!GetCommState(SerialHandle, &SerialConfigs)) {
    29. qDebug()<< "Error Getting State!";
    30. }
    31. SerialConfigs.BaudRate = CBR_9600;
    32. SerialConfigs.ByteSize = 8;
    33. SerialConfigs.StopBits = ONESTOPBIT;
    34. SerialConfigs.Parity = NOPARITY;
    35.  
    36. if(!SetCommState(SerialHandle, &SerialConfigs)) {
    37. qDebug()<<"Error Setting Serial Port State!";
    38. }
    39. qDebug()<<"Initialization Done";
    40. }
    41.  
    42. void Bluetooth::transmit(int right, int left) {
    43. WriteFile(SerialHandle,
    44. &right, // Outgoing data
    45. 1, // Number of bytes to write
    46. &bytes_written, // Number of bytes written
    47. NULL);
    48. Status = WriteFile(SerialHandle,
    49. &left,
    50. 1,
    51. &bytes_written,
    52. NULL);
    53. if (Status == 0) {
    54. qDebug()<<"Error Writing";
    55. }
    56. }
    To copy to clipboard, switch view to plain text mode 

  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: bluetooth communications (RS-232)

    In member function 'void Bluetooth::initialize()': error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'
    use CreateFileA

    or ready-made libraries:
    QSerialDevice -> http://fireforge.net/snapshots.php?group_id=199
    or
    QExtSerialPort -> http://code.google.com/p/qextserialport/

  3. #3
    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: bluetooth communications (RS-232)

    In member function 'void Bluetooth::initialize()': error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'void* CreateFileW(const WCHAR*, DWORD, DWORD, _SECURITY_ATTRIBUTES*, DWORD, DWORD, void*)'
    use CreateFileA

    or ready-made libraries:
    QSerialDevice -> http://fireforge.net/snapshots.php?group_id=199
    or
    QExtSerialPort -> http://code.google.com/p/qextserialport/

  4. #4
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: bluetooth communications (RS-232)

    Quote Originally Posted by kuzulis View Post
    use CreateFileA
    I didn't really specify CreateFileW my code just reads CreateFile.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: bluetooth communications (RS-232)

    It looks like you have an issue with unicode.
    See if somewhere _UNICODE is defined in your project settings.
    here is some info on the subject:
    http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

    Derived from this link you might try using one of the macros specified for example:

    Qt Code:
    1. SerialHandle = CreateFile(_T("COM5"),
    2. GENERIC_WRITE,
    3. 0,
    4. NULL,
    5. OPEN_EXISTING,
    6. FILE_ATTRIBUTE_NORMAL,
    7. NULL);
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: bluetooth communications (RS-232)

    Quote Originally Posted by high_flyer View Post
    It looks like you have an issue with unicode.
    See if somewhere _UNICODE is defined in your project settings.
    here is some info on the subject:
    http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

    Derived from this link you might try using one of the macros specified for example:

    Qt Code:
    1. SerialHandle = CreateFile(_T("COM5"),
    2. GENERIC_WRITE,
    3. 0,
    4. NULL,
    5. OPEN_EXISTING,
    6. FILE_ATTRIBUTE_NORMAL,
    7. NULL);
    To copy to clipboard, switch view to plain text mode 
    The _T() flags an error: undeclared (first use of this function).

  7. #7
    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: bluetooth communications (RS-232)

    I didn't really specify CreateFileW my code just reads CreateFile.
    if you look at include the compiler (such as MinGW) you will see the following:
    Qt Code:
    1. ...
    2. WINBASEAPI HANDLE WINAPI CreateFileA (LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
    3. WINBASEAPI HANDLE WINAPI CreateFileW (LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
    4. ...
    5. # define CreateFile CreateFileW
    6. ...
    To copy to clipboard, switch view to plain text mode 

    As you can see under CreateFile default means CreateFileW!!!

    One solution to your problem is to use CreateFileA. This is the easiest, or use macros TEXT()
    Last edited by kuzulis; 11th February 2010 at 07:33.

  8. The following user says thank you to kuzulis for this useful post:

    freekill (12th February 2010)

  9. #8
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: bluetooth communications (RS-232)

    CreateFileA worked..all the thanks

Similar Threads

  1. Using QT to read and write files over bluetooth FTP
    By deano in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 00:22
  2. QDBus Bluetooth Pairing problem
    By Yashpal in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2009, 08:54
  3. Bluetooth app?
    By danoh in forum Newbie
    Replies: 2
    Last Post: 30th August 2009, 23:48
  4. Bluetooth libraries in Qt 4.4
    By s4077154 in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 18th May 2009, 03:42
  5. Send File Via bluetooth
    By IGHOR in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2008, 18:48

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.