public static ParsingParameter ParsingContent(byte[] by) { ParsingParameter parameter = new ParsingParameter(); parameter.FunctionAddress = by[1]; parameter.DeviceAddress = (byte)HexadecimalConversion.HexToInt(by[2], by[3]); parameter.Command = (byte)HexadecimalConversion.HexToInt(by[4], by[5]); byte[] newby = new byte[by.Length - 9]; if (newby.Length > 0) { Array.Copy(by, 6, newby, 0, newby.Length); } parameter.DataContent = newby; return(parameter); }
public static void SerialPortDataReceived(int port) { try { Thread.Sleep(10); byte[] by = sp.Read(sp.GetIqueue); if (by == null) { return; } List <byte[]> bylist = _dataValidation.Validation(by); foreach (byte[] item in bylist) { ParsingParameter param = DataParsing.ParsingContent(item); OnDataReceived(param); } } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); //MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void OnDataReceived(ParsingParameter param) { DataReceived?.Invoke(param); }