/// <summary> /// 获取绕带机对象列表 /// </summary> /// <param name="deviceInfoList">设备基本信息列表</param> /// <param name="port">端口号</param> /// <param name="startAddress">读取数据的开始地址</param> /// <param name="numRegister">需要读取的寄存器数量</param> /// <param name="deviceTemplateList">RDJ数据模板</param> /// <param name="isHour">是否整点,把设备状态写入数据库,true表示写入,默认值为false</param> /// <returns></returns> public static List <RDJ> GetRDJList(List <DeviceInfo> deviceInfoList, int port, short startAddress, short numRegister, List <DeviceTemplate> deviceTemplateList, bool isHour = false) { //获取错误状态解析词典 Dictionary <int, string> errorStringDic = GetErrorStringDic(); //创建连接对象列表 List <ConnectData> ConnectDataList = GetConnetData(deviceInfoList, port, startAddress, numRegister); //错误ip列表 List <String> ErrorIPS; //获取设备源数据 List <byte[]> ResultDataList = Read(ConnectDataList, out ErrorIPS); //创建绕带机对象列表 List <RDJ> RDJList = new List <RDJ>(); //判断是否有数据,有则处理。 if (ResultDataList.Count > 0) { //循环遍历数据列表,获取每台设备的数据 foreach (byte[] resultData in ResultDataList) { //创建RDJ实例对象 RDJ rdj = RDJConvertData(resultData, deviceTemplateList); //添加到列表中 RDJList.Add(rdj); } } //判断是否有出现读取错误的设备,有则处理 if (ErrorIPS.Count > 0) { //遍历错误对象列表 for (int i = 0; i < ErrorIPS.Count; i++) { DeviceInfo deviceInfo = BL_DeviceInfo.GetDeviceInfoByIP(ErrorIPS[i]); RDJ errorRDJ = new RDJ(); errorRDJ.SBBH = deviceInfo.DeviceID; errorRDJ.SBYXZT = (short)9; errorRDJ.SBZDXX = "网络故障"; //添加到RDJ对象列表的后面 RDJList.Add(errorRDJ); } } //生成设备状态对象添加到数据库 foreach (RDJ rdj in RDJList) { //创建设备状态对象 DeviceState ds = GetDeviceState(rdj, errorStringDic); //调用胡老师的状态判断函数 if (isHour) { BL_DeviceState.AddDeviceState(ds, DateTime.Now); } else { BL_DeviceState.AddDeviceState(ds); } } return(RDJList); }
/// <summary> /// 获取绕带机对象列表 /// </summary> /// <param name="deviceInfoList">设备基本信息列表</param> /// <param name="port">端口号</param> /// <param name="startAddress">读取数据的开始地址</param> /// <param name="numRegister">需要读取的寄存器数量</param> /// <param name="deviceTemplateList">RDJ数据模板</param> /// <param name="isHour">是否整点,把设备状态写入数据库,true表示写入,默认值为false</param> /// <returns></returns> public static List <RSJ> GetRSJList(List <DeviceInfo> deviceInfoList, int port, short startAddress, short numRegister, List <DeviceTemplate> deviceTemplateList, bool isHour = false) { //1.获取错误状态解析词典 Dictionary <int, string> errorStringDic = GetErrorStringDic(); //2.创建连接对象列表 List <ConnectData> ConnectDataList = GetConnetData(deviceInfoList, port, startAddress, numRegister); //3.错误ip列表 List <String> ErrorIPS; //4.获取设备源数据 List <byte[]> ResultDataList = Read(ConnectDataList, out ErrorIPS); //5.创建绕带机对象列表 List <RSJ> RSJList = new List <RSJ>(); //6.判断是否有数据,有则处理。 if (ResultDataList.Count > 0) { //循环遍历数据列表,获取每台设备的数据 foreach (byte[] resultData in ResultDataList) { //创建RDJ实例对象 RSJ rsj = RSJConvertData(resultData, deviceTemplateList); //根据控制字改变设备运行状态 rsj = SetKZZ(rsj); //添加到列表中 RSJList.Add(rsj); } } //7.判断是否有出现读取错误的设备,有则处理 if (ErrorIPS.Count > 0) { //遍历错误对象列表 for (int i = 0; i < ErrorIPS.Count; i++) { DeviceInfo deviceInfo = BL_DeviceInfo.GetDeviceInfoByIP(ErrorIPS[i]); RSJ errorRSJ = new RSJ(); errorRSJ.RGS = new List <RG>(); //如果染色机链接不上,则添加5个钢对象,全部设置为9网络无法链接 for (int n = 0; n < 5; n++) { RG r = new RG(); r.RGBH = (short)(n + 1); r.SBYXZT = (short)9; errorRSJ.RGS.Add(r); } errorRSJ.SBBH = deviceInfo.DeviceID; errorRSJ.SBZDXX = "网络故障"; //添加到RDJ对象列表的后面 RSJList.Add(errorRSJ); } } //8.将状态添加到数据库 foreach (RSJ rsj in RSJList) { List <DeviceState> errorList = GetDeviceState(rsj, errorStringDic); //调用胡老师的状态判断函数 foreach (DeviceState errords in errorList) { //如果为真,表明调用整点数据直接写到数据库 if (isHour) { BL_DeviceState.AddDeviceState(errords, DateTime.Now); } else { BL_DeviceState.AddDeviceState(errords); } } } return(RSJList); }