using InSituLaboratory.Entities.ExperimentalStationEntities; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InSituLaboratory.Common { /// /// 基站返回的数据解析 /// public class TXTDataParsing { //连接钥匙 private static readonly string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["db"].ConnectionString; //获取当前程序运行路径 private string Save_Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"数据记录\"; //系统状态表 public SysStatus sysStatus = new SysStatus(); //当前工作设备 0-待机 1-工作 public CurrentWorkEquipment currentWorkEquipment = new CurrentWorkEquipment(); //当前故障设备 0-正常 1-故障 public CurrentFaultyEquipment currentFaultyEquipment = new CurrentFaultyEquipment(); //包头 string head = "AABB"; //包尾 string tail = "EEFF"; //版本号 -固定 byte version = 0x01; //crc static byte nr_crc = 0; /// /// 数据解析 /// /// public void ParsingData(List byteList) { //如果数组长度为0 舍弃 if (byteList.Count() == 0) return; //将报文中的内容截取出来 并保存至本地TXT文件内 string NR_TXT = ""; for (int i = 0; i < byteList.Count; i++) { NR_TXT += byteList[i].ToString("X2") + " "; } //SqlSugar配置文件 ConnectionConfig connectionConfig = new ConnectionConfig() { ConnectionString = ConnStr, IsAutoCloseConnection = true, DbType = DbType.Sqlite }; //包头包尾校验 if ((byteList[0].ToString("X2") + byteList[1].ToString("X2")) != head || (byteList[byteList.Count -1].ToString("X2") + byteList[byteList.Count -2].ToString("X2")) != tail) return; } } }