Serial Communication WIN 2000

T

Thread Starter

Thomas J. Byrne

Hi,

I'm a student in Ireland doing a project which involves:
1 LMS lazar scanner,
1 windows 2000 professional pc,
1 copy of MS visual studio 6.0 (I'm gona use VC++ from the studio).

Ok, right, the task at hand is to communicate between the scanner and the pc using the serial port (COM1) (Not too difficult, I have this part working, for anyone reading this who needs help doing this, I've found great articles here on control.com, and also the best one was at: http://www.robbayer.com/files//serial.doc hope this helps someone.) so back to my problem. I need write a program quite like the Hyper Terminal program that comes with windows.

1. The program needs to send settings (Data) to the scanner from the PC
2. Retrieve data from the scanner to the PC

This needs to be done using threads in c++, that's my BIG Problem :-(.

I've opened the com port using
...CreateFile( "COM1", GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)...

am able to read to the port using
...ReadFile(hSerial, szBuff, NUMBERBYTES, &dwBytesRead, NULL)...

am able to write to the port using
...WriteFile(....

BUT I don't know how to implement this using threads. Is there some way I can start a thread for reading (EG: _beginthread(ReadThread, 0, NULL); ) so it will continuously read the data coming in from the serial port for as long as the program runs, but can be stopped for a time to allow another thread to write to the port?

Some code examples would really help. Please Please Please Help!!

Thank you,

Regards,

Thomas Byrne
[email protected]
 
Hi,

i think you can use one of the synchronization methods to accomplish this. Otherwise use some flag; check it while reading and writing; say 1 for writing & 0 for reading.

Regards
Bijesh
 
Top