Serial Communication using MSComm Control in VC++

B

Thread Starter

Blink182

I need information on how to make use of the MSComm control to send/receive data. I hope someone will help me as i cannot seem to find any resources on how to do it.

 
> I need information on how to make use of the MSComm control to send/receive data. I hope someone will help me as i cannot seem to find any resources on how to do it. <

have u tried msdn.microsoft.com?
 
Yeah. They only have for VB but none for VC++. The functions used in VB are totally different to the functions that are available in VC++ 6.0.

 
C

Cristian Gliga

Hi!

When you add the control to your project, you get an header file. There you can find the declaration of all the methods available. From this point you can use the VB example and make the approprite changes.

Regards,
Cristian Gliga - Systems Integrator
 
Yup, i already know that but i am don't know which functions to use to send/receive data as the functions are most set & get functions unlike in VB.

 
Hi,

I tried to use GetOutput and SetOutput functions that were generated but i am unable to compile the program cause i am not sure how to convert CString to tagVariant and Vice-Versa. I would be very grateful if you could like provide sample code on how to send/receive data through the comm port using this MsComm Control



 
R

Ramamurthi Natarajan

Here i am giving sample code for Using MSComm control in VC++ 6.0.m_objMSComm.SetCommPort(1);


1. Add MSComm control to your project.
2. Draw MSComm Control in your Dialog box.
3. Create an object m_objMScomm for your MSComm control.
4. Use following code to initialize you comm port.

m_objMSComm.SetRThreshold(1);
m_objMSComm.SetRTSEnable(TRUE);
m_objMSComm.SetSettings("9600,n,8,1");
m_objMSComm.SetSThreshold(1);
m_objMSComm.SetPortOpen(TRUE);

5. Use following code to form output buffer.

COleSafeArray objOutputBuffer;

int iLoopVar=0;
long iArraySizeInc=0;

BYTE bOutput;

// First Byte to be send

bOutput='A';

objOutputBuffer.PutElement(&iArraySizeInc,(void *) &bOutput);
objOutputBuffer.ResizeOneDim(iArraySizeInc+2);
iArraySizeInc++;

// Secondt Byte to be send


bOutput='B';

objOutputBuffer.PutElement(&iArraySizeInc,(void *) &bOutput);
objOutputBuffer.ResizeOneDim(iArraySizeInc+2);
iArraySizeInc++;


// Third Byte to be send


bOutput='C';
objOutputBuffer.PutElement(&iArraySizeInc,(void *) &bOutput);
objOutputBuffer.ResizeOneDim(iArraySizeInc+2);
iArraySizeInc++;

//sending "ABC" through comm port #1

m_objMSComm.SetOutput((VARIANT)objOutputBuffer);



The above code will send "ABC" through comm port number 1.

If you have any clarifications please let me know.

Regards
Ramamurthi.N


 
The above example is for VC++ or VB pls.tell me
if it is for VC++ how can i Add and draw MScom control in my project
 
Top