MScomm and VC++ Sample Code needed

S

Thread Starter

Suranga Manage

MSDN does not describe how to use "MSComm" with VC++. I would like to see some sample code of how to use MSComm and VC++ together.
 
W

Wallinius Mattias

COM ports in Windows are treated as File I/O so look in the Platform SDK, (MSDN library,) for File I/O and under communications. There you
will find all the sample code needed.
This is cut from MSDN

"About Communications

The file input and output (I/O) functions (CreateFile, CloseHandle, ReadFile, ReadFileEx, WriteFile, and WriteFileEx) provide the basic
interface for opening and closing a communications resource handle and for performing read and write operations. The Microsoft=AE Win32=AE API also includes a set of communications functions that provide access to
communications resources. This overview describes the use of file I/O and communications functions.

Communications Resource Handles
Modification of Communications Resource Settings
Communications Resource Configuration
Modem Configuration
Read and Write Operations
Communications Events
Extended Functions"

/Mattias Wallinius
 
R
> MSDN does not describe how to use "MSComm" with VC++. I would like to
> see some sample code of how to use MSComm and VC++ together.

There is no special 'WinCommObject', you use the api calls as documented in the MSDN.

Build your own class. I have a basic one which I modify as per requirements for different projects, the reason being that it is difficult
to create standard comms objects, needs differ so widely, and the API behaves differently depending on the OS.

The Automation List does not handle code snippets as attachments, but somebody did send me a site were automation code snippets could be put, and I
cannot find it! If they tell me again maybe I will post!

<Moderator's note: www.control.com allows attachments.>

BTW, Probably it is just me, but I always had difficulty doing anything with VC++, I find C++ Builder is far easier to work with.
 
R

Richard A. Higginbotham, II

>> MSDN does not describe how to use "MSComm" with VC++. I would like to
>> see some sample code of how to use MSComm and VC++ together.

>There is no special 'WinCommObject', you use the api calls as
>documented in the MSDN.

Actually, IIRC there is a "MSComm" object that comes with Visual Basic. Perhaps this is what he is referring to. You could use the ActiveX MSComm control from VC++ as you would any other ActiveX control (I would think). There is a MSComm sample app for VB if you have VB. I've never tried it, but it sounds plausable.

Richard Higginbotham
 
M

Michael Griffin

At 12:24 27/10/00 -0400, roger Irwin wrote:
<clip>
>Build your own class. I have a basic one which I modify as per
>requirements for different projects,
<clip>
>This list does not handle code snippets as attachments, but somebody
>did send me a site were automation code snippets could be put, and I
>cannot find it! If they tell me again maybe I will post!
<clip>
Perhaps the PLC archive would be suitable for this? This may not be PLC code per say, but it is "automation" related.

http://www.control.com/control_com/PLCArchive/


**********************
Michael Griffin
London, Ont. Canada
[email protected]
**********************
 
G
> MSDN does not describe how to use "MSComm" with VC++. I would like to see some sample code of how to use MSComm and VC++ together. I found it's tough to use MSComm in VC++, after trying several times under checking books talking about activex. The thing I found maybe something for reference: Using the ActiveX Test Container available in VC++, I can't find any export method from this control.(So strange, is anyone know why?) My ugly solution is to call the execute built by VB from VC++ to solve my demo program.
 
S

Simon Guerrero

I have been struggling with MSComm in VC++ too. But I've managed to get something working. Here are snippets. Let me know if you need more. BTW, the problem I have at the moment is the buffer overflows and I stop receiving 'OnComm' events. Simon ------- This is the body of a thread which runs while a modal dialog is up with a 'connecting...' message and a cancel button. It's actually a connection routine between a BBC micro and a PC. The messages it is posting are just my own WM_APP+n messages: ignore them. In this example I'm using the GetInput function, but you can get a notification from the control by using the VC++ ClassWizard to add an 'OnComm' event to your code, and calling GetInput from there. Would be interested to hear from anyone re: my problems with OnComm, though. Forgive any 'nasties': I'm not a Windows programmer, but a UNIX man ;-) ====<snip> CConnectingDlg * pThisDlg = (CConnectingDlg *)pParam; CString toBBC = ""; CString fromBBC = ""; CString expectedReply = ""; int bytes = 0; int tries = 20; COleVariant vfromBBC; expectedReply.Format("BBCPCHELLO%c%c", 0x0a, 0x0d); do { // Send initialisation string toBBC.Format("PCBBCHELLO%c", 0x0d); pThisDlg->m_pComm->SetInBufferCount(0); pThisDlg->m_pComm->SetOutput(COleVariant(toBBC)); bytes = 0; tries = 20; // Have 20 goes at getting something while (bytes < expectedReply.GetLength() && tries != 0 && pThisDlg->m_terminate_thread == FALSE) { bytes = pThisDlg->m_pComm->GetInBufferCount(); Sleep(1000); tries--; } vfromBBC = pThisDlg->m_pComm->GetInput(); fromBBC = pThisDlg->m_pComm->GetStringValue(vfromBBC); } while (strcmp(fromBBC, expectedReply) != 0 && pThisDlg->m_terminate_thread == FALSE); if (pThisDlg->m_terminate_thread == TRUE) { pThisDlg->PostMessage(BBC_CONNECT_FAILURE); } else { pThisDlg->PostMessage(BBC_CONNECT_SUCCESS); } return(0); ====<snip>
 
>>Hi! I'm recently doing a project using VC++, where serial communication is needed. > > MSDN does not describe how to use "MSComm" with VC++. >> I would like to see some sample code of how to use MSComm and VC++ together. >>sorry 4 any inconvenience.....
 
> > MSDN does not describe how to use "MSComm" with VC++. I would like to
> see some sample code of how to use MSComm and VC++ together.

There is no special 'WinCommObject', you use the api calls as documented in the MSDN.

Build your own class. I have a basic one which I modify as per requirements for different projects, the reason being that it is difficult
to create standard comms objects, needs differ so widely, and the API behaves differently depending on the OS.

The Automation List does not handle code snippets as attachments, but somebody did send me a site were automation code snippets could be put, and I cannot find it! If they tell me again maybe I will post!

<Moderator's note: www.control.com allows attachments.>

BTW, Probably it is just me, but I always had difficulty doing anything with VC++, I find C++ Builder is far easier to work with.

 
U
As all we know that there is no help in msdn abt vc++ and MScomm . so plz if any have any code in ti then plz send it .
 
> MSDN does not describe how to use "MSComm" with VC++. I would like to
> see some sample code of how to use MSComm and VC++ together. <

There is no special 'WinCommObject', you use the api calls as documented in the MSDN.

Build your own class. I have a basic one which I modify as per requirements for different projects, the reason being that it is difficult
to create standard comms objects, needs differ so widely, and the API behaves differently depending on the OS.

The Automation List does not handle code snippets as attachments, but somebody did send me a site were automation code snippets could be put, and I cannot find it! If they tell me again maybe I will post!

<Moderator's note: www.control.com allows attachments.>

BTW, Probably it is just me, but I always had difficulty doing anything with VC++, I find C++ Builder is far easier to work with.
 
Top