|
From: Bolek V. <vr...@pa...> - 2001-04-26 20:12:48
|
I had written a non-overlapped serial communication in C++ some time
ago. It uses Win32 API, but it didn't work under Dev-CPP 4.0. It works
under Borland's free C++ compiler 5.5. I guess there is an error in
Dev-CPP (or in my code? - I just read the Win32 API help from Microsoft
and wrote something). It will hang at somewhere at GetCommState in open(
) under DevCPP 4.
I send it to you. It is a part of a much greater work that controls a
scientific device. The device can be controlled with serial port or GPIB
- that's why I created an abstract class TCommunicator. Just changing
the communicator used from TSerialComm to TGPIBComm will make the
program use GPIB instead of serial.
The device reads a command, obeys it and sends a response. The response
always ends with a special char - the end char. No end char means the
response didn't come. So I wait for it to come and then read the
response.
comm->send( ....);
comm->wait( ....);
comm->read( ....);
That's how I use it. TNessyException is a special class of exceptions
defined in the program and errCommError and errMemory mean an error in
communication or error in memory allocation occured. id is device id -
forget it.
The WinAPI functions used are explained in the Microsoft's Win32 API
help file. I think you can download it at Dev-CPP's web site.
--
============================================================
Ing. Boleslav Vrany
Stanice techniku DDM hl. m. Prahy
Pod Juliskou 2a
Praha 6 - Dejvice
16000
Czech Republic
tel. (420 2) 243 10 240 |