public static ExperimentTable GetTable(byte[] sourceBytes, bool checkCrc = false) { if (sourceBytes == null) { throw new ArgumentNullException(nameof(sourceBytes)); } if (sourceBytes.Length < 30) { throw new ArgumentException($"{nameof(sourceBytes)}.Length < 30"); } if (checkCrc && sourceBytes.Length < 32) { throw new ArgumentException("crc not found"); } var result = new ExperimentTable(); var count = sourceBytes.Length / sizeof(ushort); var words = new ushort[count]; for (int i = 0, j = 0; i < sourceBytes.Length; i += 2, j++) { words[j] = BitConverter.ToUInt16(sourceBytes, i); } if (checkCrc && !ChekCrc(words)) { throw new ArgumentException("Crc is incorrect!"); } result.SetArray(words); return(result); }
public static byte[] GetBytes(ExperimentTable table, bool crcFlag = true) { if (table == null) { throw new ArgumentNullException(nameof(table)); } var result = new List <byte>(32); var array = table.GetArray(); foreach (var item in array) { result.AddRange(BitConverter.GetBytes(item)); } if (crcFlag) { var crc = CalculateCrc(array); result.AddRange(BitConverter.GetBytes(crc)); } return(result.ToArray()); }