大家好
我想在规定3秒内udp控件发数据 超过3秒则提示超时
请问怎么做timer
ir := MilliSecondsBetween(now, dtBegin) mod 1000;
if (ir >= 0) and (ir <= iInterval) then
begin
。
end
这样做不对
请问该怎么做?
我想在规定3秒内udp控件发数据 超过3秒则提示超时
请问怎么做timer
ir := MilliSecondsBetween(now, dtBegin) mod 1000;
if (ir >= 0) and (ir <= iInterval) then
begin
。
end
这样做不对
请问该怎么做?
begin
超时
end
可能我写的不对, 情况是这样的:
上位机发udp 数据包到底层设备 因为有些设备需要识别一定的数据格式,所以设备没有返回信息,那么UDPUDPRead 事件是接收不到任何信息 所以没法判断 所以我现在需要在3秒内发送, 超过3秒 则提示超时
贴代码:timer 事件:
ir := MilliSecondsBetween(now, dtBegin) mod 1000; if MilliSecondsBetween(now, dtBegin) >= Trunc(10000 * iTimeOver) then
begin
if not OrderEdThePIC then
begin
Timer2.Enabled := False;
OrderEdThePIC := True;
end;
end
else
if (ir >= 0) and (ir <= 3000) then
begin
if (Device_Type <>'00') then
begin c :=MakeComm(Char(StrToHex(Device_Type)));
UDP.Send('255.255.255.255',HIS_PORT,c); end else
begin
//如果指定为
c:=MakeComm(Char(StrToHex('11')));
UDP.Send('255.255.255.255',HIS_PORT,c); c:=MakeComm(Char(StrToHex('12')));
UDP.Send('255.255.255.255',HIS_PORT,c); end;
begin
超时处理
end else
begin
没有超时处理
end;
就是这个逻辑 具体的,只能你自己处理 一般超时处理 可设一个全局变量 icount
比如登录程序 再设一个全局变量 biSLogin
当登录成功是 biSLogin :=True;
把timer 设为1秒
在timer 事件中
if biSLogin then exit;
inc(icount );
if icount>2 then
begin
超时处理
终止timer
end else
begin
重发登录信息
end;
begin
终止timer
exit;
end;