Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial Communication

Status
Not open for further replies.

Raven078

Programmer
Jan 14, 2003
22
NL
Since the keyword search on the forum doesn't work for now...

I want to read a string from a comport and used the readfile function, but i don't know how many bits i will recieve (eihter 0 or 2). ReadFile has to know this in front. If it didn't recieve the right amount of bits yet, the app (or function) keeps waiting for them. How do i prevent this?
 
Hi,

In fact, the length of information that you will receive doesn't matter. Whether the Readfile function will keep waiting or not depends on the timeout parameters which you set to the port when it was opened.

...
with CommTimeOuts do
begin
ReadIntervalTimeOut:=MAXDWORD;
ReadTotalTimeOutMultiplier:=0;
ReadTotalTimeOutConstant:=0;
end;
if SetCommTimeOuts(Temp,CommTimeOuts) then
begin
...

Search the key word "Serial Communication" in MSDN, you will get some useful articles as well.

Hope this helps.
 
I had to find other values for my timeoutparameters.
I used it like this now:
Code:
TimeOut.ReadIntervalTimeout         := 0;
TimeOut.ReadTotalTimeoutMultiplier  := 10;
TimeOut.ReadTotalTimeoutConstant    := 1000;
SetCommTimeouts(hPort,TimeOut);
Now it stops reading after 1s, for some reasons it didn't work with other values.
 
Check out this website:


and


It contains a SUPER comport utility, which works very well but is a little tricky to install. I use it with Delphi 5 (scales and barcode scanners), but could not install it in Delphi 6 or later (installation errors).

If you get it installed it works great.

Andrew

"if it is stupid and works, then it isn't stupid"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top