public override bool Poll(out byte[] buf) {
buf=null;
var now=DateTime.Now;
if(_waitError && _rt<now) {
_pins[16].value=true;
_waitError=false;
}
if(_waitResp) {
if(_pt<now) { // read timeout
Reset();
_busy=false;
}
return true;
} else if(_pt<now && (_pins[16].value || _rt<now)) {
if((_flags & 4)!=0) {
_flags&=3;
buf=new byte[] { ADDR, 0x01, 0x03, 0x00, 0x06, (byte)_iodir, (byte)(_iodir>>8) }; // Access to IODIR
_pt=now.AddMilliseconds(30);
_busy=true;
if(!_waitError) {
_rt=now.AddMilliseconds(500);
_waitError=true;
}
} else if((_flags & 2)!=0) {
_flags&=5;
buf=new byte[] { ADDR, 0x01, 0x03, 0x00, 0x04, (byte)_ipol, (byte)(_ipol>>8) }; // Access to IPOL
_pt=now.AddMilliseconds(30);
_busy=true;
if(!_waitError) {
_rt=now.AddMilliseconds(500);
_waitError=true;
}
} else if((_flags & 1)!=0) {
_flags&=6;
buf=new byte[] { ADDR, 0x01, 0x03, 0x00, 0x00, (byte)_gpo, (byte)(_gpo>>8) }; // Access to GP
_pt=now.AddMilliseconds(30);
_busy=true;
if(!_waitError) {
_rt=now.AddMilliseconds(500);
_waitError=true;
}
} else if(_inps!=0) {
buf=new byte[] { ADDR, 0x03, 0x01, 0x02, 0x00 }; // Access to GP
_pt=DateTime.Now.AddMilliseconds(500);
_busy=true;
_waitResp=true;
} else {
_busy=false;
_pt=DateTime.Now.AddSeconds(_rand.Next(45, 75));
}
}
return _busy;
}
public override void Reset() {