/////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Syncronous Send. Sends a Esys protocol message over the serial port and waits for /// the response. Returns the reponse if successful, null otherwise. /// </summary> /////////////////////////////////////////////////////////////////////////////////////////// private Message Send(Message message, int timeout) { if (Connected) { lock (mSyncLock) { Esys.Protocol.Message result = null; int count = timeout / 20; mResult = null; mMsgNumber = (mMsgNumber >= 99999) ? 1 : mMsgNumber + 1; message.Number = mMsgNumber; mPort.Write(message.ToString()); for (int i = 0; i < count; i++) { result = mResult; if (result != null && result.Number == message.Number && result is Message) { break; } else { result = null; Thread.Sleep(20); } } return (Message)result; } } else { return null; } }
/////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Asyncronous Send. Sends a Esys protocol message over the serial port and immediately /// returns. /// </summary> /////////////////////////////////////////////////////////////////////////////////////////// private void Send(Message message) { if (Connected) { lock (mSyncLock) { mMsgNumber = (mMsgNumber >= 99999) ? 1 : mMsgNumber + 1; message.Number = mMsgNumber; mPort.Write(message.ToString()); } } }