private void backgroundWorkerDevice_DoWork(object sender, DoWorkEventArgs e) { this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_MONIOR_OUTPUT, "Device BGW Started"); ProtocolCommunicationsTiger nProtoCommsTiger = new ProtocolCommunicationsTiger(); DateTime lastRXReportTime = DateTime.Now; while (!this.backgroundWorkerDevice.CancellationPending) { List <byte> dataIn = new List <byte>(); //look for data from Device if (serialPort1.BytesToRead > 0) { int nByte = this.serialPort1.ReadByte(); bool result = nProtoCommsTiger.BuildFrame((byte)nByte); dataIn.Add((byte)nByte); if (result == true) { //got a valid frame byte[] nData = nProtoCommsTiger.GetFrameAsByteArray(); this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_MONIOR_OUTPUT, "New Frame:" + SupportFunctions.ByteArrayToString(nData, nData.Count())); } //update status term every 100ms DateTime nTime = DateTime.Now; TimeSpan lastReportTimePassed = nTime.Subtract(lastRXReportTime); if (lastReportTimePassed.TotalMilliseconds >= 100) { String rxData = SupportFunctions.ByteListToString(dataIn); dataIn.Clear(); this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_TERM_RX_UPDATE, rxData); } } else { //CPU Rest System.Threading.Thread.Sleep(10); } } }
private void buttonManualSend_Click(object sender, EventArgs e) { //Manual send //get input List <byte> inputData = SupportFunctions.ASCIIHexStringToByteList(this.richTextBoxManualInput.Text); if (inputData == null) { this.UpdateStatusTerminal("Input Error - check input data", true); return; } if (this.checkBoxApplyTigerProtocol.Checked == true) { //apply Tiger inputData = ProtocolCommunicationsTiger.GeneratePacketForTx(inputData); } //Send this.SendToOpenSerialPort(inputData); }