Hi.
Is it easy to read from and write to the com port using C++? Is there a library for it?
Thanks,
Kuphryn
Hi.
Is it easy to read from and write to the com port using C++? Is there a library for it?
Thanks,
Kuphryn
no real need for a library you can do it with basic file functions.
THis will open the com port, just open it for read and write, you can write characters to it using fputc
int main (void)
{
transfer();
}
int transfer ()
{
FILE *comport;
if ((comport = fopen("COM1", "wt")) == NULL)
{
printf("Failed to open the communication port COM2\n");
printf("The port may be disabled or in use\n");
int wait=getch();
return 1;
}
printf("COM2 opended successfully\n");
fputc(CTRLZ, comport);
fflush(comport);
fclose(comport);
return 0;
}
Monday - what a way to spend a seventh of your life
Okay. Thanks.
Some members recommended MSDN's Create, Read and Write functions.
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
Last edited by kuphryn; 12-27-2001 at 12:08 PM.