/* * public MBController() * : this("default") { * } */ #endregion /// <summary> /// Que a new message in the buffer /// </summary> /// <param name="nUnitID"></param> /// <param name="nFuncID"></param> /// <param name="pMsgData"></param> /// <param name="cmd"></param> public void QueMsg(byte nUnitID, MBFunctionType nFuncID, byte[] pMsgData, MBCommand cmd) { MBMsg msg; lock (lockQue) { //create a message if (IsRTU) { msg = new MBMsgRTU(nUnitID, nFuncID, pMsgData); } else { msg = new MBMsgTCP(nUnitID, nFuncID, pMsgData) { TransactionID = _nTransactionID } }; _nTransactionID++; //increment transaction id //add to que _que.Add(new MBMsgCmdItem(msg, cmd)); if (_que.Count > MAX_QUE) { int nRemove = _rnd.Next(MAX_QUE - 1) + 1; _que.RemoveAt(nRemove); //remove at random to avoid any kind of pattern, not 0, since 0 may be in the process of beeing send. 1 never is (due to lock on buffer) _OnError("Buffer full, removing item " + nRemove.ToString()); } } }
public MBMsgCmdItem(MBMsg m, MBCommand c) { Msg = m; Cmd = c; _TimeStamp = null; }