public override void HandleMsg(MBMsg msg) { byte[] pData = msg.Data; int nBytes = _nQuantity / 8; if (_nQuantity % 8 != 0) { nBytes++; } if (pData.Length >= nBytes + 1 && pData[0] == nBytes) //recieved right amount of data? { if ((byte)msg.FuncID < 0x80) //recieved an exception? //all is ok, copy data to buffers in Control { _bInputs = new bool[_nQuantity]; int nByteAdr = 0; int nBitAdr = 0; for (int i = 0; i < _nQuantity; i++) { nBitAdr = i % 8; nByteAdr = i / 8; _bInputs[i] = (pData[1 + nByteAdr] & (0x01 << nBitAdr)) == 0 ? false : true; } _OnDataUpdated(); } } }
public override void HandleMsg(MBMsg msg) { byte[] pData = msg.Data; //add some checking here, verify lengths ok and match the expected if (pData.Length >= 2 * _nQuantity + 1 && pData[0] == 2 * _nQuantity) //recieved right amount of data? { if ((byte)msg.FuncID < 0x80) //recieved an exception? //all is ok, copy data to buffers in Control { _nRegisters = new short[_nQuantity]; for (int i = 0; i < _nQuantity; i++) { _nRegisters[i] = MBMsg.GetShortFromByteSwappedBuffer(pData, 1 + i * 2); } _OnDataUpdated(); } } }
// Handle reply from server, set control register buffers if needed public override void HandleMsg(MBMsg msg) { short nStartAdr; short nCount; //add some checking here, verify lengths ok and match the expected if (msg.Data.Length >= 4) //recieved correct number of bytes? { if ((byte)msg.FuncID < 0x80) //recieved an exception? { nStartAdr = MBMsg.GetShortFromByteSwappedBuffer(msg.Data, 0); nCount = MBMsg.GetShortFromByteSwappedBuffer(msg.Data, 2); if (nStartAdr != _nStartAdr && nCount != _nQuantity) { //recieved incorect ACK from server } } } }
public MBMsgCmdItem(MBMsg m, MBCommand c) { Msg = m; Cmd = c; _TimeStamp = null; }
/* * public MBCommand() { * _control = MBController.GetController("default"); * } */ public virtual void HandleMsg(MBMsg msg) { }