Read/Write Com Port :: C++
Hi.
Is it easy to read from and write to the com port using C++? Is there a library for it?
Thanks,
Kuphryn
Most communications is OS specific
Sometimes you can open a file to com1, com2, etc...
But this doesn''t give you must control over how it''s opened etc...
Sometimes you can open a file to com1, com2, etc...
But this doesn''t give you must control over how it''s opened etc...
Thanks.
What do you mean "open to?"
ifstream readCOM;
readCOM.open(com1, ios::in | ios::binary);
readCOM << ''test'';
Is that you are talking about?
Kuphryn
What do you mean "open to?"
ifstream readCOM;
readCOM.open(com1, ios::in | ios::binary);
readCOM << ''test'';
Is that you are talking about?
Kuphryn
more or less, I''m used to seeing fopen with that, but I guess the iostreams should kinda-sort work.
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 (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
Edited by - kuphryn on December 27, 2001 1:12:10 PM
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 (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
Edited by - kuphryn on December 27, 2001 1:12:10 PM
The biggest problem is that you have no control over the baud rate, secondly you can''t check the modem/line status bits.
You need to look into the Win32 communication functions
You need to look into the Win32 communication functions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement