The problem with Serial library for C++
-
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
-
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
I believe the second parameter to the
Open
function is a window handle. You're trying to pass it aCWnd*
. Try this -port.Open(m_strComPort, m_hWnd);
«_Superman_» _I love work. It gives me something to do between weekends.
-
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
It doesnt work. :((
-
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
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 castAs to your error message, the
Open()
function requires some value which is anunsigned long
not a pointer to your enclosing class. You should check the documentation for theOpen()
function for specific details.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
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
-
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
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.