private void OnByteReceived(ConnectionByteReceivedEventArgs e) { if (ByteReceived != null) { ByteReceived(this, e); } }
void _conn_ByteReceived(object sender, ConnectionByteReceivedEventArgs e) { if (e.ByteData == 0x02) { _isPacketStart = true; _packet.Clear(); } else if (e.ByteData == 0x03) { _isPacketStart = false; // TODO: process packet string strPacket = Encoding.ASCII.GetString(_packet.ToArray()); string[] dataLine = strPacket.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); EventDetail detail = new EventDetail(); string[] dataFields = dataLine[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); detail.EventDateTime = DateTime.ParseExact(dataLine[0].Substring(0, 16), "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.GetCultureInfo("en-US")); detail.EventLocation = dataFields[2]; detail.EventType = Regex.Replace(dataLine[1].Trim(), " {2,}", " "); detail.Classcification = dataLine[2].Trim(); detail.DeviceMessage = dataLine[3].Trim(); Estring = detail.EventDateTime.ToString() + ","; Estring += detail.EventType + ","; Estring += detail.EventLocation + ","; Estring += detail.Classcification + ","; Estring += detail.DeviceMessage; this.Invoke(new EventHandler(DisplayText)); SendAlarmData(Estring); } else if (_isPacketStart) { _packet.Add(e.ByteData); } }