• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Read/Write Com Port :: C++

kuphryn

Senior member
Hi.
Is it easy to read from and write to the com port using C++? Is there a library for it?

I heard of functions CreateFile, ReadFile and WriteFile from members at a couple of forums. There are functions inp() and outp() from conio.h too. Does anyone know the difference between these functions?

Thanks,
Kuphryn
 
C++ Style:

ifstream readCOM;
readCOM.open(com1, ios::in | ios::binary)

char *ptrStore;

try
{
ptrStore = new char[SIZE];
}
catch (bad_alloc error)
{
cerr << error.what();
exit(1);
}

readCOM.read(reinterpret_cast<char *> (ptrStore), SIZE);

How do you get the exact size of whatever you're reading from the COM port? It is not a measurable storage container.

Do I have to use an MFC class? What is the major difference if I were to use the ifstream and ofstream instead of an MFC class? I have no experience with MFC or windows programming.

Kuphryn
 
Maybe it's just my lack of C++ expertise, but why not just use read() and write()? They return how many bytes they processed.
 
Back
Top