Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. The problem with Serial library for C++

The problem with Serial library for C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpvisual-studiocom
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LongDuyTran
    wrote on last edited by
    #1

    I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

    _ L L O 5 Replies Last reply
    0
    • L LongDuyTran

      I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      I believe the second parameter to the Open function is a window handle. You're trying to pass it a CWnd*. Try this - port.Open(m_strComPort, m_hWnd);

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • L LongDuyTran

        I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

        L Offline
        L Offline
        LongDuyTran
        wrote on last edited by
        #3

        It doesnt work. :((

        1 Reply Last reply
        0
        • L LongDuyTran

          I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Please make your posts readable by putting code extracts within <pre> tags, indenting the code and removing unnecessary control or meta characters. Something like the following: This uses <pre lang="c++"></pre>

          CString m_strComPort;
          m_strComPort.Format(TEXT("COM2"));
          CSerial port;
          if (port.Open(m_strComPort,this) != ERROR_SUCCESS
          {
          AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK);
          GetParent()->PostMessage(WM_CLOSE);
          return 0;
          }

          This uses <pre lang="text"></pre>

          H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long'
          This conversion requires a reinterpret_cast, a C-style cast or function-style cast

          As to your error message, the Open() function requires some value which is an unsigned long not a pointer to your enclosing class. You should check the documentation for the Open() function for specific details.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          1 Reply Last reply
          0
          • L LongDuyTran

            I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            So give the Open() func the correct parameter. I havent a clue what it is, Ramions API doesnt have a second param, other APIs have baudrate, so look at the documentation.

            ============================== Nothing to say.

            1 Reply Last reply
            0
            • L LongDuyTran

              I'm a beginner with VC++. I tried to do program to communicate with COM port of PC but I failed to use the MSComm lib. After that, I changed to use the "Serial library for VC++" which was written by Ramon de Klein but now I had an error I dont know how to solve. The following sentence is the error: "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 H:\\Program Files\\Microsoft Visual Studio\\MyProjects\\TestXbee\\TestXbeeDlg.cpp(130) : error C2664: 'Open' : cannot convert parameter 2 from 'class CTestXbeeDlg *const ' to 'unsigned long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast }" Now is the part of my program which informed about that error "CString m_strComPort; m_strComPort.Format(TEXT("COM2")); CSerial port; if (port.Open(m_strComPort,this) != ERROR_SUCCESS { AfxMessageBox(TEXT("Unable to open COM"),MB_ICONSTOP | MB_OK); GetParent()->PostMessage(WM_CLOSE); return 0;" Thank you very much

              O Offline
              O Offline
              OneKey2Press
              wrote on last edited by
              #6

              How to use that library if it is so bad documented? We do alot of serial programing. At the end it pays 10x using a good commercial library with technical support. We successfuly replaced MSComm with SuperCom ActiveX and it also solved us a lot other issues we had with Bluetooth devices.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups