Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MScomm ActiveX control in C++

Status
Not open for further replies.

richsb

Technical User
Aug 2, 2001
34
NO
Hi folks,

Help with MSCOMM please. Setting up the commport for connection to a gps. Using mfcVC++ but not experienced enough to get to grips with my own classes etc. Have imported the ActiveX MSComm control into programme. Am using and so far set a dialog up to interact with the ports settings - baud, parity etc. no problem but am stuck at getting the gps data from the GetInput() function into an edit box. I gather it is returning a variant type data, but am unable to gather what and how much.

Q Could someone explain/show the code required to get this from the variant into the edit box please.

Have looked for help in MSDN but that only gives advice for the VBasic version for the MSCOMM control, and as for an explantion of a variant !@##$!#% Any explanation of the above and the wrapper classes in the MSComm class will be much appreciated.

Thanks in advance

Richard
 
>> but am unable to gather what and how much.

That is dependent on the device sending the data not the MSCOMM control.


-pete
I just can't seem to get back my IntelliSense
 
Ever thought of using CreateFile/ReadFile and such. Much more straightforward than using the MSCOMM control....


Greetings,
Rick
 
Palbano,

The device sending the data is a hand held gps unit sending out pre-formatted strings as defined by the marine electronics association NMEA. So I know what I should be receiving, I seem to be falling at the fence of getting it out of the variant that CMSComm uses to place said data into the buffer. I get to the point of placing the data into a variant of my own so that I can hold it, but I am unable to figure out how to change that data into a form that I can see it - specifically a string for display in an edit box. I have tried type casting but get the error that converting from parameter1 of targ VARIANT to CString doesn't work (I'll resend that error properly later, it's on my other machine)

Lazyme,

I have thought of using the Create/ReadFile functins but again the help files were confusing at this stage, and then I came across the MSComm control from which I was at least able to setup and open the port quite easy - I will have another look now that my knowledge has increased on the matter.

Thanks so far.[ponder]
 
Fella's,

I have managed to sort it out with guidance from another post by Hyslan(message thread 116-2455533). The function which is called by an event of the MSComm control is filled like so:-

Code:
void CPortComDlg::OnOnCommMSComm()
{
  tagVARIANT test = m_ctlMSCommPort.GetInput();
  CString intext = test.bstrVal;
  CEdit* pGpsOutputBox = (CEdit*)GetDlgItem(IDC_GPS_OUTPUT_BOX);
  pGpsOutputBox->SetWindowText(intext);
}
NB I had to increase the RThreshold of the port to an appropriate level - say 10 . The above then puts the string data into my edit box for viewing.

The only thing that I need to do now is figure out how to grab the strings I want as they come in various lengths and represent different types of info. Well here's to hoping, but I think that it is pub time!

Cheers

Richard[cheers]
 
You do know that OnComm is not only fired when data arrives at the port, don't you? If not, you do now and you should first check why the event has been fired, before doing anything significant....


Greetings,
Rick
 
Code:
tagVARIANT test = m_ctlMSCommPort.GetInput();
CString intext = test.bstrVal;

using one of the members of the VARIANT structure without checking the VARTYPE vt member is a common mistake that can lead to crashes and other anomolous behavior.


-pete
I just can't seem to get back my IntelliSense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top