Click to See Complete Forum and Search --> : read buffer(Serial comm)


gadi
February 25th, 2003, 04:56 PM
I m trying to write a program sending text file when the user can select the Rate-Serial Communication.
How can i read all of the data in the buffer at once (not byte by byte) when the size of the data changes every time-according to the size of the file which was sent?
*Sorry for this , but i m just a junior in the business!

KingTermite
February 26th, 2003, 08:02 AM
Probably the easiest way is to attempt to read the size of the internal uart buffer. The buffer size was defined in the SetupComm() function shortly after OpenFile() is called to get the handle.

If you define the buffer to be, say 2k, then try to read 2k. It will give you the entire buffer up to amount of data. If nothing is there, you'll get a -1 returned from ReadFile().

Scyla
February 27th, 2003, 04:28 AM
So let me see if i understood well, u wanna read the buffer at the same time the data is coming? If so u can do it by detecting the new char arrived at the port.
Tell me if this i s ur question, if not i ll try to answer later ur question.
Regards!

gadi
February 27th, 2003, 05:30 AM
I m trying to read from the serial port data when the size of it is not constant(depends on the size of the file wich was sent)
all i want is not to deal with COMMTIMEOUTS - i have lots of problems with it!
once again thanks for ur reply.

Scyla
February 27th, 2003, 05:39 AM
ok, so one possibility is to read data at the same time u receive it from the device.then, the different size does not matter.
About Commtimeouts, i have not worked with them.
i created my own serial app not using comms functions.
the serial settings i made, were at the dcb struct parameters.no timeouts used.

gadi
February 27th, 2003, 07:28 AM
Sorry again,
1.But how did u read from the buffer without timeouts setting (dont u have to use them?)
2. Did u raed byte by byte or something else?
Thanks,

Scyla
February 27th, 2003, 08:42 AM
Sorry if i didn't explain me well.
i only defined some of the DCB parameters like parity, stopb and that. the others remain by default.
and i read every time there is an event

Caronte
February 27th, 2003, 09:06 AM
If you are using Win32 API, why donīt you use ClearCommError to determine how many bytes are waiting for reading on the serial buffer?

gadi
February 27th, 2003, 12:22 PM
Sorry, but can u give an example or a link to this idea?