/// <summary> /// 设置界面参数 /// </summary> /// <param name="para"></param> public virtual void SetUIParameter(IO_SERVER server, IO_DEVICE device, IO_PARA para) { Server = server; Device = device; Para = para; ParaString = para.IO_PARASTRING; }
public IORealListViewItem(IO_PARA para) : base(para.IO_ID) { Para = para; this.SubItems.Add(para.IO_NAME); this.SubItems.Add(para.IO_LABEL); this.SubItems.Add(para.RealValue); this.SubItems.Add(para.RealDate); this.SubItems.Add(para.RealQualityStamp.ToString()); this.SubItems.Add(para.IO_UNIT); }
public IOListViewItem(IO_PARA d) : base(d.IO_ID) { Para = d; this.SubItems.Add(Para.IO_NAME); this.SubItems.Add(Para.IO_LABEL); this.SubItems.Add(Para.IO_PARASTRING); this.SubItems.Add(Para.IO_DATATYPE); this.SubItems.Add(Para.IO_OUTLIES); this.SubItems.Add(Para.IO_INITALVALUE); this.SubItems.Add(Para.IO_MINVALUE); this.SubItems.Add(Para.IO_MAXVALUE); if (Para.IO_ENABLERANGECONVERSION == 1) { this.SubItems.Add("是"); } else { this.SubItems.Add("否"); } this.SubItems.Add(Para.IO_RANGEMIN); this.SubItems.Add(Para.IO_RANGEMAX); this.SubItems.Add(Para.IO_POINTTYPE); this.SubItems.Add(Para.IO_ZERO); this.SubItems.Add(Para.IO_ONE); this.SubItems.Add(Para.IO_UNIT); if (Para.IO_HISTORY == 1) { this.SubItems.Add("是"); } else { this.SubItems.Add("否"); } this.SubItems.Add(Para.IO_ADDRESS); if (Para.IO_ENABLEALARM == 1) { this.SubItems.Add("是"); } else { this.SubItems.Add("否"); } if (Para.IO_SYSTEM == 1) { this.SubItems.Add("是"); } else { this.SubItems.Add("否"); } }
public void RemoveListViewItem(IO_PARA para) { for (int i = this.listView.Items.Count - 1; i >= 0; i--) { IOListViewItem item = this.listView.Items[i] as IOListViewItem; if (item.Para == para) { this.listView.Items.Remove(item); break; } } }
public IOListViewItem GetListViewItem(IO_PARA para) { for (int i = 0; i < ioListView.ListView.Items.Count; i++) { IOListViewItem item = ioListView.ListView.Items[i] as IOListViewItem; if (item.Para == para) { return(item); } } return(null); }
private void listBoxSeries_SelectedIndexChanged(object sender, EventArgs e) { if (listBoxSeries.SelectedItem != null) { IO_PARA para = listBoxSeries.SelectedItem as IO_PARA; SwitchChart(); IOParaSeries series = IOSeries.Find(x => x.Name.Trim() == para.IO_NAME.Trim()); if (series != null) { this.RealChart.Series.Add(series); } } }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device, IO_PARA para) { base.SetUIParameter(server, device, para); if (para.IO_PARASTRING != null && para.IO_PARASTRING != "") { ParaPack paraPack = new ParaPack(para.IO_PARASTRING); paraPack.SetCtrlValue(tb_JsonName, paraPack.GetValue("IO标识")); paraPack.SetCtrlValue(nudTime, paraPack.GetValue("时间值索引")); paraPack.SetCtrlValue(cbDataType, paraPack.GetValue("数据类型")); paraPack.SetCtrlValue(nud_valueIndex, paraPack.GetValue("采集值索引")); paraPack.SetCtrlValue(tbCmdValue, paraPack.GetValue("命令默认值")); } this.ParaString = para.IO_PARASTRING; }
private void listView_SelectedIndexChanged(object sender, EventArgs e) { if (listView.SelectedItems.Count < 0) { return; } try { IO_PARA para = listView.SelectedItems[0].Tag as IO_PARA; MonitorFormManager.SetIOPara(this.Server, this.Communication, this.Device, para); } catch (Exception ex) { MonitorFormManager.DisplyException(ex); } }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device, IO_PARA para) { base.SetUIParameter(server, device, para); if (para.IO_PARASTRING != null && para.IO_PARASTRING != "") { ParaPack paraPack = new ParaPack(para.IO_PARASTRING); paraPack.SetCtrlValue(tb_JsonName, paraPack.GetValue("JSON名称")); paraPack.SetCtrlValue(nud_boardAddress, paraPack.GetValue("版子地址")); paraPack.SetCtrlValue(nud_boardIndex, paraPack.GetValue("版子索引号")); paraPack.SetCtrlValue(nud_port, paraPack.GetValue("端口号")); paraPack.SetCtrlValue(nud_PortIndex, paraPack.GetValue("端口索引号")); paraPack.SetCtrlValue(cb_DataType, paraPack.GetValue("数据类型")); paraPack.SetCtrlValue(nud_valueIndex, paraPack.GetValue("采集值索引号")); paraPack.SetCtrlValue(cbParaType, paraPack.GetValue("是否命令参数")); } this.ParaString = para.IO_PARASTRING; }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device, IO_PARA para) { ParaPack paraPack = new ParaPack(device.IO_DEVICE_PARASTRING); paraPack.SetCtrlValue(cbo_functioncode, paraPack.GetValue("内存区")); paraPack.SetCtrlValue(ndOffset, paraPack.GetValue("偏置")); paraPack.SetCtrlValue(cbo_StoreType, paraPack.GetValue("数据类型")); paraPack.SetCtrlValue(cbo_datatype, paraPack.GetValue("存储位置")); paraPack.SetCtrlValue(ndCharSize, paraPack.GetValue("字节长度")); paraPack.SetCtrlValue(cbPosition, paraPack.GetValue("按位存取")); paraPack.SetCtrlValue(ndPosition, paraPack.GetValue("数据位")); if (paraPack.GetValue("读写状态") == "可读可写") { paraPack.SetCtrlValue(rb_rw, "1"); } if (paraPack.GetValue("读写状态") == "可读") { paraPack.SetCtrlValue(rb_r, 1); } if (paraPack.GetValue("读写状态") == "可写") { paraPack.SetCtrlValue(rb_w, 1); } }
protected override bool InitDeviceKernel(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para, SCADA_DEVICE_DRIVER driver) { if (IsCreateControl) { if (para != null) { this.ParaCtrl = new IOParaCtrl(); this.ParaCtrl.SetUIParameter(server, device, para); } this.DeviceCtrl = new IODeviceCtrl(); this.DeviceCtrl.SetUIParameter(server, device); } if (para != null) { this.ParaString = para.IO_PARASTRING; } this.DeviceParaString = device.IO_DEVICE_PARASTRING; return(true); }
public override void InitDrive(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, IO_PARA para, DEVICE_DRIVER driver) { base.InitDrive(server, Communication, device, para, driver); }
public override byte[] GetSendValueBytes(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, IO_PARA para, string setvalue) { return(base.GetSendValueBytes(server, Communication, device, para, setvalue)); }
public override List <byte[]> GetDataCommandBytes(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, List <IO_PARA> paras, IO_PARA currentpara) { return(base.GetDataCommandBytes(server, Communication, device, paras, currentpara)); }
public override bool SendCommand(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value) { return(base.SendCommand(server, comm, device, para, value)); }
public IOParaSeries(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para) { this.Name = para.IO_NAME; this.LegendText = para.IO_LABEL; this.ChartType = SeriesChartType.Line; this.BorderWidth = 4; this.MarkerSize = 4; this.MarkerStep = 1; this.MarkerStyle = MarkerStyle.Circle; this.MarkerColor = System.Drawing.Color.Black; this.ChartArea = "IOChartArea"; this.Para = para; this.Server = server; this.Communication = communication; this.Device = device; this.XValueType = ChartValueType.Time; this.YValueType = ChartValueType.Double; this.Color = System.Drawing.Color.FromArgb(155 + IOCenterManager.QueryFormManager.MainRandom.Next(100), 155 + IOCenterManager.QueryFormManager.MainRandom.Next(100), IOCenterManager.QueryFormManager.MainRandom.Next(255)); }
/// <summary> /// 传入的是实际的数据包,并不包含头标识和尾标识 /// </summary> /// <param name="receivebytes"></param> /// <param name="count"></param> /// <param name="c"></param> private void SplitReceivePack(byte[] receivebytes, int count, AsyncTcpClient c) { //将实际字节转化成字符串 string message = Encoding.UTF8.GetString(receivebytes); //心跳包,不做处理 if (message == c.HeartBeat) { return; } #region 处理实际数据体 byte opeartor = receivebytes[0]; ScadaTcpOperator operatorEnum = (ScadaTcpOperator)opeartor; if (c.IsOperator(opeartor)) { switch (operatorEnum) { case ScadaTcpOperator.登录反馈: { try { #region 处理采集器端登录 TcpData tcpData = new TcpData(); byte[] narra = new byte[count - 1]; System.Array.Copy(receivebytes, 1, narra, 0, count - 1); tcpData.BytesToTcpItem(narra); if (tcpData == null) { if (OnUserLogined != null) { OnUserLogined(c, false, "登录失败"); } return; } STATION_TCP_INFO loginInfo = new STATION_TCP_INFO(); try { loginInfo.IO_SERVER_ID = tcpData.GetItemValue("IO_SERVER_ID"); loginInfo.IO_SERVER_IP = tcpData.GetItemValue("IO_SERVER_IP"); loginInfo.PASSWROD = tcpData.GetItemValue("PASSWROD"); loginInfo.USER = tcpData.GetItemValue("USER"); loginInfo.RESULT = tcpData.GetItemValue("RESULT"); loginInfo.MSG = tcpData.GetItemValue("MSG"); loginInfo.FUNCTION = tcpData.GetItemValue("FUNCTION"); //判断是否已经存在有发布的采集站工程 if (loginInfo.RESULT == "true") { if (OnUserLogined != null) { OnUserLogined(c, true, loginInfo.MSG); } } else { if (OnUserLogined != null) { OnUserLogined(c, false, loginInfo.MSG); } } } catch { if (OnUserLogined != null) { OnUserLogined(c, false, "登录失败"); } return; } tcpData.Dispose(); #endregion } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERR10024" + ex.Message)); } } break; case ScadaTcpOperator.更新采集站报警: //接收到服务器端更新采集站中报警配置通知 { try { #region 更新采集站报警 TcpData tcpData = new TcpData(); byte[] narra = new byte[count - 1]; System.Array.Copy(receivebytes, 1, narra, 0, count - 1); tcpData.BytesToTcpItem(narra); if (tcpData == null) { //解析字符串失败 return; } IO_ALARM_CONFIG alarmConfig = new IO_ALARM_CONFIG(); try { alarmConfig.IO_ALARM_LEVEL = tcpData.GetItemValue("IO_ALARM_LEVEL"); alarmConfig.IO_ALARM_NUMBER = int.Parse(tcpData.GetItemValue("IO_ALARM_NUMBER")); alarmConfig.IO_ALARM_TYPE = tcpData.GetItemValue("IO_ALARM_TYPE"); alarmConfig.IO_COMM_ID = tcpData.GetItemValue("IO_COMM_ID"); alarmConfig.IO_CONDITION = tcpData.GetItemValue("IO_CONDITION"); alarmConfig.IO_DEVICE_ID = tcpData.GetItemValue("IO_DEVICE_ID"); alarmConfig.IO_ENABLE_MAX = int.Parse(tcpData.GetItemValue("IO_ENABLE_MAX")); alarmConfig.IO_ENABLE_MAXMAX = int.Parse(tcpData.GetItemValue("IO_ENABLE_MAXMAX")); alarmConfig.IO_ENABLE_MIN = int.Parse(tcpData.GetItemValue("IO_ENABLE_MIN")); alarmConfig.IO_ENABLE_MINMIN = int.Parse(tcpData.GetItemValue("IO_ENABLE_MINMIN")); alarmConfig.IO_ID = tcpData.GetItemValue("IO_ID"); alarmConfig.IO_MAXMAX_TYPE = tcpData.GetItemValue("IO_MAXMAX_TYPE"); alarmConfig.IO_MAXMAX_VALUE = int.Parse(tcpData.GetItemValue("IO_MAXMAX_VALUE")); alarmConfig.IO_MAX_TYPE = tcpData.GetItemValue("IO_MAX_TYPE"); alarmConfig.IO_MAX_VALUE = int.Parse(tcpData.GetItemValue("IO_MAX_VALUE")); alarmConfig.IO_MINMIN_TYPE = tcpData.GetItemValue("IO_MINMIN_TYPE"); alarmConfig.IO_MINMIN_VALUE = int.Parse(tcpData.GetItemValue("IO_MINMIN_VALUE")); alarmConfig.IO_MIN_TYPE = tcpData.GetItemValue("IO_MIN_TYPE"); alarmConfig.IO_MIN_VALUE = int.Parse(tcpData.GetItemValue("IO_MIN_VALUE")); alarmConfig.IO_SERVER_ID = tcpData.GetItemValue("IO_SERVER_ID"); alarmConfig.UPDATE_DATE = ""; alarmConfig.UPDATE_RESULT = ""; alarmConfig.UPDATE_UID = ""; } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERROR20102 " + ex.Message)); alarmConfig = null; } if (alarmConfig != null) { if (alarmconfigBll.Update(alarmConfig)) { byte[] sendbytes = tcpData.StringToTcpByte(tcpData.TcpItemToString(), ScadaTcpOperator.更新采集站报警反馈); this.Send(new ArraySegment <byte>(sendbytes)); IO_DEVICE device = MonitorDataBaseModel.IODevices.Find(x => x.IO_DEVICE_ID == alarmConfig.IO_DEVICE_ID); if (device != null) { IO_PARA para = device.IOParas.Find(x => x.IO_ID == alarmConfig.IO_ID); if (para != null) { para.AlarmConfig = alarmConfig; AddLogToMainLog("管理员更新" + device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "]//" + para.IO_NAME + "[" + para.IO_LABEL + "]" + "报警配置成功! "); } } } else { AddLogToMainLog("管理员更新" + alarmConfig.IO_ID + "报警配置失败! "); } } tcpData.Dispose(); #endregion } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERR10029" + ex.Message)); } } break; case ScadaTcpOperator.置命令: //接收到用户要下置命令 { try { byte[] contentbytes = new byte[receivebytes.Length - 1]; System.Array.Copy(receivebytes, 1, contentbytes, 0, receivebytes.Length - 1); TcpData tcpData = new TcpData(); tcpData.BytesToTcpItem(contentbytes); IO_COMMANDS command = new IO_COMMANDS() { COMMAND_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), COMMAND_ID = tcpData.GetItemValue("COMMAND_ID"), COMMAND_RESULT = tcpData.GetItemValue("COMMAND_RESULT"), COMMAND_USER = tcpData.GetItemValue("COMMAND_USER"), COMMAND_VALUE = tcpData.GetItemValue("COMMAND_VALUE"), IO_COMM_ID = tcpData.GetItemValue("IO_COMM_ID"), IO_DEVICE_ID = tcpData.GetItemValue("IO_DEVICE_ID"), IO_ID = tcpData.GetItemValue("IO_ID"), IO_LABEL = tcpData.GetItemValue("IO_LABEL"), IO_NAME = tcpData.GetItemValue("IO_NAME"), IO_SERVER_ID = tcpData.GetItemValue("IO_SERVER_ID") }; Scada.Model.IO_COMMUNICATION _COMMUNICATION = MonitorDataBaseModel.IOCommunications.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID); Scada.Model.IO_DEVICE device = MonitorDataBaseModel.IODevices.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID && x.IO_DEVICE_ID == command.IO_DEVICE_ID); if (_COMMUNICATION != null && device != null) { Scada.Model.IO_PARA para = device.IOParas.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID && x.IO_DEVICE_ID == command.IO_DEVICE_ID && x.IO_ID == command.IO_ID); if (para == null) { AddLogToMainLog(device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "] 设备下参数 " + para.IO_ID + " " + para.IO_LABEL + " " + para.IO_NAME + " 参数不存在"); return; } if (_COMMUNICATION.DriverInfo == null) { AddLogToMainLog("请在采集站中设置该通讯通道驱动!"); return; } try { if (_COMMUNICATION.CommunicateDriver == null) { AddLogToMainLog("请在采集站中设置该通讯通道驱动!"); return; } else { ((ScadaCommunicateKernel)_COMMUNICATION.CommunicateDriver).IsCreateControl = false; } ScadaCommunicateKernel driverDll = (ScadaCommunicateKernel)_COMMUNICATION.CommunicateDriver; driverDll.SetUIParameter(_COMMUNICATION.IO_COMM_PARASTRING); driverDll.IsCreateControl = false; driverDll.InitKernel(MonitorDataBaseModel.IOServer, _COMMUNICATION, _COMMUNICATION.Devices, _COMMUNICATION.DriverInfo); try { driverDll.SendCommand(MonitorDataBaseModel.IOServer, _COMMUNICATION, device, para, command.COMMAND_VALUE); AddLogToMainLog(device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "] 设备下参数 " + para.IO_ID + " " + para.IO_LABEL + " " + para.IO_NAME + " 已经下置成功,下置值" + command.COMMAND_VALUE); } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERROR600002" + ex.Message)); } } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERROR600001" + ex.Message)); } } } catch (Exception ex) { ThrowExceptionToMain(new Exception("ERR10030" + ex.Message)); } } break; case ScadaTcpOperator.重新启动: break; } } #endregion }
//用户发送下置命令 public override bool SendCommand(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para, string value) { try { Dtu_Data data = new Dtu_Data(); data.DeviceID = device.IO_DEVICE_ID; //获取value 的字节数组 DeviceDrive driver = DeviceDrives.Find(x => x.DeviceDriverID == device.DEVICE_DRIVER_ID); if (driver != null) { data.datas = driver.GetSendValueBytes(server, this.IOCommunication, device, para, value); this.DeviceException("error=10011," + device.IO_DEVICE_ADDRESS + "设备驱动不存在"); } data.ParaID = para.IO_ID; data.DtuID = device.IO_DEVICE_ADDRESS; data.DataStatus = DataStatus.WriterData; string error = ""; bool result = false; Thread.Sleep(100);//停止10秒,保证之前发送命令已经发送出去 if (!svr.Send(data.DtuID, data.datas, out error, false)) { this.DeviceException("error=10010" + error); result = false; } else { result = true; } //信息发送完成的事件 DataSended(server, this.IOCommunication, device, para, value, result); return(true); ///接收的数据 } catch (Exception emx) { return(false); } finally { } }
private bool ResponseData(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value) { if (para == null) { return(false); } if (para.IO_POINTTYPE == "计算值" || para.IO_POINTTYPE == "关系数据库值") { return(false); } //设备地址不能为空 if (device.IO_DEVICE_ADDRESS == "") { return(false); } try { //通过设备驱动进行数据解析,并生成下置的数据bytes if (device.DeviceDrive != null) { ScadaDeviceKernel Driver = (ScadaDeviceKernel)device.DeviceDrive; //获取参数中的 if (udpClient != null && master != null) { ParaPack paraPack = new ParaPack(para.IO_PARASTRING); if (paraPack.Count > 0) { ushort offset = ushort.Parse(paraPack.GetValue("偏置")); switch (paraPack.GetValue("内存区")) { case "01": { if (ushort.Parse(value) > 0) { master.WriteSingleCoil(byte.Parse(device.IO_DEVICE_ADDRESS), offset, true); } else { master.WriteSingleCoil(byte.Parse(device.IO_DEVICE_ADDRESS), offset, false); } } break; case "02": //此类型只能查询,不能写入 { } break; case "03": { Modbus_Type datatype = (Modbus_Type)Enum.Parse(typeof(Modbus_Type), paraPack.GetValue("数据类型")); bool ishigh = paraPack.GetValue("存储位置") == "高八位" ? true : false; int charsize = int.Parse(paraPack.GetValue("字节长度")); bool isposition = paraPack.GetValue("按位存取") == "1" ? true : false; int dataposition = int.Parse(paraPack.GetValue("数据位")); switch (datatype) { case Modbus_Type.单精度浮点数32位: { ushort[] buff = new ushort[2]; float WriteValue = float.Parse(value); ModbusConvert.SetReal(buff, 0, WriteValue); master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff); } break; case Modbus_Type.双精度浮点数64位: { ushort[] buff = new ushort[4]; double WriteValue = double.Parse(value); ModbusConvert.SetDouble(buff, 0, WriteValue); master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff); } break; case Modbus_Type.字符型: { ushort[] buff = new ushort[charsize]; string WriteValue = value; if (value.Length > charsize) { WriteValue = value.Substring(0, charsize); } if (value.Length < charsize) { WriteValue = value.PadRight(charsize, ' '); } ModbusConvert.SetString(buff, 0, WriteValue); master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff); } break; case Modbus_Type.无符号整数8位: { ushort[] buff = new ushort[1]; byte WriteValue = byte.Parse(value); ModbusConvert.SetByte(buff, 0, WriteValue, ishigh); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]); } break; case Modbus_Type.符号整数8位: { ushort[] buff = new ushort[1]; sbyte WriteValue = sbyte.Parse(value); ModbusConvert.SetSByte(buff, 0, WriteValue, ishigh); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]); } break; case Modbus_Type.无符号整数16位: { if (isposition) { //获取当前寄存器的值 ushort[] datas = master.ReadHoldingRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, 1); ushort dataValue = ModbusConvert.GetUShort(datas, 0); if (short.Parse(value) > 0) { dataValue = Convert.ToUInt16(dataValue >> dataposition & 1); } else { dataValue = Convert.ToUInt16(dataValue >> dataposition & 0); } //新发送的值 ushort[] datas2 = new ushort[1]; ModbusConvert.SetUShort(datas2, 0, dataValue); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, datas2[0]); } else { ushort WriteValue = ushort.Parse(value); ushort[] buff = new ushort[1]; ModbusConvert.SetUShort(buff, 0, WriteValue); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]); } } break; case Modbus_Type.符号整数16位: { if (isposition) { //获取当前寄存器的值 ushort[] datas = master.ReadHoldingRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, 1); short dataValue = ModbusConvert.GetShort(datas, 0); if (short.Parse(value) > 0) { dataValue = Convert.ToInt16(dataValue >> dataposition & 1); } else { dataValue = Convert.ToInt16(dataValue >> dataposition & 0); } //新发送的值 ushort[] datas2 = new ushort[1]; ModbusConvert.SetShort(datas2, 0, dataValue); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, datas2[0]); } else { Int16 WriteValue = Int16.Parse(value); ushort[] buff = new ushort[1]; ModbusConvert.SetShort(buff, 0, WriteValue); master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]); } } break; case Modbus_Type.无符号整数32位: { uint WriteValue = uint.Parse(value); ushort[] buff = new ushort[2]; ModbusConvert.SetUInt(buff, 0, WriteValue); master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff); } break; case Modbus_Type.符号整数32位: { int WriteValue = int.Parse(value); ushort[] buff = new ushort[2]; ModbusConvert.SetInt(buff, 0, WriteValue); master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff); } break; } } break; } } } } } catch { return(false); } return(true); }
protected override IOData Analysis(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, IO_PARA para, byte[] datas, DateTime datatime) { return(base.Analysis(server, Communication, device, para, datas, datatime)); }
public void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) { if (Device != null) { try { if (this.IsHandleCreated) { this.listView.BeginInvoke(new EventHandler(delegate { if (copyIds.Count > 0) { if (MessageBox.Show(this.FindForm(), "是否要粘贴复制的IO点?", "粘贴提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { for (int i = copyIds.Count - 1; i >= 0; i--) { IO_PARA newPara = copyIds[i].Copy(); string oldName = newPara.IO_NAME; newPara.IO_DEVICE_ID = Device.IO_DEVICE_ID; newPara.IO_COMM_ID = Device.IO_COMM_ID; newPara.IO_SERVER_ID = Device.IO_SERVER_ID; newPara.IO_ID = Scada.DBUtility.GUIDTo16.GuidToLongID().ToString();//分配新的ID bool existName = false; for (int p = 0; p < Device.IOParas.Count; p++) { if (newPara.IO_NAME.Trim() == Device.IOParas[p].IO_NAME.Trim()) { existName = true; break; } } //出现相同名称的时候要重新命名 if (existName) { newPara.IO_NAME = newPara.IO_NAME + "_C" + DateTime.Now.ToString("yyyyMMddHHmmss"); } //不是同一个设备的时候要考虑驱动参数 this.AddListViewItem(new IOListViewItem(newPara)); FormManager.mediator.IOLogForm.AppendText("从设备" + copyDevice.IO_DEVICE_NAME + "复制IO点" + oldName + " 到设备" + Device.IO_DEVICE_NAME + "成功,新IO名称是" + newPara.IO_NAME); Device.IOParas.Add(newPara); Thread.Sleep(400); } } } if (cutIds.Count > 0) { if (copyDevice == Device) { MessageBox.Show("不能剪贴到同一设备下"); return; } if (MessageBox.Show(this.FindForm(), "是否要粘贴剪贴的IO点?", "粘贴提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { for (int i = cutIds.Count - 1; i >= 0; i--) { IO_PARA newPara = cutIds[i].Copy(); string oldName = newPara.IO_NAME; newPara.IO_DEVICE_ID = Device.IO_DEVICE_ID; newPara.IO_COMM_ID = Device.IO_COMM_ID; newPara.IO_SERVER_ID = Device.IO_SERVER_ID; newPara.IO_ID = Scada.DBUtility.GUIDTo16.GuidToLongID().ToString();//分配新的ID bool existName = false; for (int p = 0; p < Device.IOParas.Count; p++) { if (newPara.IO_NAME.Trim() == Device.IOParas[p].IO_NAME.Trim()) { existName = true; break; } } //出现相同名称的时候要重新命名 if (existName) { newPara.IO_NAME = newPara.IO_NAME + "_C" + DateTime.Now.ToString("yyyyMMddHHmmss"); } //不是同一个设备的时候要考虑驱动参数 if (copyDevice != Device) { newPara.IO_PARASTRING = ""; this.AddListViewItem(new IOListViewItem(newPara)); FormManager.mediator.IOLogForm.AppendText("从设备" + copyDevice.IO_DEVICE_NAME + "剪贴IO点" + oldName + " 到设备" + Device.IO_DEVICE_NAME + "成功,新IO名称是" + newPara.IO_NAME + "。由于设备驱动不同,需要重新配置此IO点驱动信息"); } else { this.AddListViewItem(new IOListViewItem(newPara)); FormManager.mediator.IOLogForm.AppendText("从设备" + copyDevice.IO_DEVICE_NAME + "剪贴IO点" + oldName + " 到设备" + Device.IO_DEVICE_NAME + "成功,新IO名称是" + newPara.IO_NAME); } //增加新的IO点 Device.IOParas.Add(newPara); //删除原来的点表信息 copyDevice.IOParas.Remove(cutIds[i]); if (copyDevice == Device) { this.RemoveListViewItem(cutIds[i]); } Thread.Sleep(400); } copyDevice = null; cutIds.Clear(); copyIds.Clear(); } } })); } } catch (Exception ex) { FormManager.DisplayException(ex); } } }
//由于此处Para里面设置的可能是不同命令的IO参数,所以需要返回不同命令的实时获取的数据,此处不需要返回Byte字节数组 public List <byte[]> GetDataCommandBytes(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, List <IO_PARA> paras, IO_PARA currentpara, ref object sender) { List <byte[]> cmmdBytes = new List <byte[]>(); //必须Read的IO参数 List <ModbusFragmentStore> modbusCodes = new List <ModbusFragmentStore>(); for (int i = 0; i < paras.Count; i++) { ParaPack paraPack = new ParaPack(paras[i].IO_PARASTRING); if (!modbusCodes.Exists(x => x.StoredCode != paraPack.GetValue("内存区")) && paraPack.GetValue("内存区") != "") { ModbusFragmentStore stored = new ModbusFragmentStore(); stored.StoredCode = paraPack.GetValue("内存区"); stored.Fragments = new List <ModbusFragment>(); stored.Units = new List <ushort>(); } paraPack.Dispose(); paraPack = null; } for (int i = 0; i < paras.Count; i++) { ParaPack paraPack = new ParaPack(paras[i].IO_PARASTRING); if (paraPack.GetValue("内存区") != "") { if (modbusCodes.Exists(x => x.StoredCode != paraPack.GetValue("内存区")) && paraPack.GetValue("内存区") != "") { ModbusFragmentStore stored = modbusCodes.Find(x => x.StoredCode != paraPack.GetValue("内存区")); if (paraPack.GetValue("偏置") != "") { ushort offset = 0; if (ushort.TryParse(paraPack.GetValue("偏置"), out offset)) { if (!stored.Units.Contains(offset)) { stored.Units.Add(offset); } } } } } } ModbusFragmentStore mainStored = new ModbusFragmentStore(); //由于modbus获取寄存器最大数量是124个,所以要进行分段,最大线圈数量是1999个 foreach (ModbusFragmentStore stored in modbusCodes) { stored.MakeFragment(); mainStored.Fragments.AddRange(stored.Fragments); } //获取要解析的命令 sender = mainStored; return(cmmdBytes); }
/// <summary> /// 解析数据 /// </summary> /// <param name="server"></param> /// <param name="Communication"></param> /// <param name="device"></param> /// <param name="para"></param> /// <param name="datas"></param> /// <param name="datatime"></param> /// <param name="sender"></param> /// <returns></returns> protected override IOData Analysis(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, IO_PARA para, byte[] datas, DateTime datatime, object sender) { if (datas.Length > 0 && sender != null && para != null) { ParaPack paraPack = new ParaPack(para.IO_PARASTRING); ModbusFragmentStore modbusStore = (ModbusFragmentStore)sender; IOData data = new IOData(); data.CommunicationID = Communication.IO_COMM_ID; data.ID = device.IO_DEVICE_ADDRESS; data.ParaName = para.IO_NAME; data.ServerID = server.SERVER_ID; data.Date = DateTime.Now; Modbus_Type dataType = (Modbus_Type)Enum.Parse(typeof(Modbus_Type), paraPack.GetValue("数据类型")); switch (dataType) { case Modbus_Type.单精度浮点数32位: data.DataType = typeof(float); break; case Modbus_Type.双精度浮点数64位: data.DataType = typeof(double); break; case Modbus_Type.字符型: data.DataType = typeof(string); break; case Modbus_Type.无符号整数16位: data.DataType = typeof(UInt16); break; case Modbus_Type.无符号整数32位: data.DataType = typeof(UInt32); break; case Modbus_Type.无符号整数8位: data.DataType = typeof(byte); break; case Modbus_Type.符号整数16位: data.DataType = typeof(Int16); break; case Modbus_Type.符号整数8位: data.DataType = typeof(sbyte); break; case Modbus_Type.符号整数32位: data.DataType = typeof(int); break; } data.datas = datas; data.ParaString = para.IO_PARASTRING; //获取数据值高八位,低八位 int startaddr = int.Parse(paraPack.GetValue("偏置")); int charsize = int.Parse(paraPack.GetValue("字节长度")); string code = paraPack.GetValue("内存区"); bool bitSave = paraPack.GetValue("按位存取") == "1" ? true : false; bool ishigh = paraPack.GetValue("存储位置") == "高八位" ? true : false; ModbusFragment fragment = modbusStore.Fragments.Find(x => x.Code == code && startaddr >= x.StartRegister && startaddr <= x.StartRegister + x.RegisterNum); if (fragment != null) { switch (code) { case "01": //线圈 { byte[] vdatas = new byte[fragment.Length]; Array.Copy(datas, fragment.StartIndex, vdatas, 0, fragment.Length); data.ParaValue = vdatas[startaddr].ToString(); } break; case "02": //线圈只读 { byte[] vdatas = new byte[fragment.Length]; Array.Copy(datas, fragment.StartIndex, vdatas, 0, fragment.Length); data.ParaValue = vdatas[startaddr].ToString(); } break; case "03": //寄存器可读可写 { //注意是否按位读取, byte[] vdatas = new byte[fragment.Length]; Array.Copy(datas, fragment.StartIndex, vdatas, 0, fragment.Length); ushort[] vals = ModbusConvert.Bytes2Ushorts(vdatas); //将字节数组转为ushort switch (dataType) { case Modbus_Type.单精度浮点数32位: { data.ParaValue = ModbusConvert.GetReal(vals, 0).ToString(); } break; case Modbus_Type.双精度浮点数64位: { data.ParaValue = ModbusConvert.GetDouble(vals, 0).ToString(); } break; case Modbus_Type.字符型: { data.ParaValue = ModbusConvert.GetString(vals, 0, charsize).ToString(); } break; case Modbus_Type.无符号整数16位: { data.ParaValue = ModbusConvert.GetUShort(vals, 0).ToString(); } break; case Modbus_Type.无符号整数32位: { data.ParaValue = ModbusConvert.GetUInt(vals, 0).ToString(); } break; case Modbus_Type.无符号整数8位: { data.ParaValue = ModbusConvert.GetSByte(vals, 0, ishigh).ToString(); } break; case Modbus_Type.符号整数16位: { data.ParaValue = ModbusConvert.GetShort(vals, 0).ToString(); } break; case Modbus_Type.符号整数8位: { data.ParaValue = ModbusConvert.GetByte(vals, 0, ishigh).ToString(); } break; case Modbus_Type.符号整数32位: { data.ParaValue = ModbusConvert.GetInt(vals, 0).ToString(); } break; } } break; case "04": //寄存器只读 { //注意是否按位读取, byte[] vdatas = new byte[fragment.Length]; Array.Copy(datas, fragment.StartIndex, vdatas, 0, fragment.Length); ushort[] vals = ModbusConvert.Bytes2Ushorts(vdatas); //将字节数组转为ushort switch (dataType) { case Modbus_Type.单精度浮点数32位: { data.ParaValue = ModbusConvert.GetReal(vals, 0).ToString(); } break; case Modbus_Type.双精度浮点数64位: { data.ParaValue = ModbusConvert.GetDouble(vals, 0).ToString(); } break; case Modbus_Type.字符型: { data.ParaValue = ModbusConvert.GetString(vals, 0, charsize).ToString(); } break; case Modbus_Type.无符号整数16位: { data.ParaValue = ModbusConvert.GetUShort(vals, 0).ToString(); } break; case Modbus_Type.无符号整数32位: { data.ParaValue = ModbusConvert.GetUInt(vals, 0).ToString(); } break; case Modbus_Type.无符号整数8位: { data.ParaValue = ModbusConvert.GetSByte(vals, 0, ishigh).ToString(); } break; case Modbus_Type.符号整数16位: { data.ParaValue = ModbusConvert.GetShort(vals, 0).ToString(); } break; case Modbus_Type.符号整数8位: { data.ParaValue = ModbusConvert.GetByte(vals, 0, ishigh).ToString(); } break; case Modbus_Type.符号整数32位: { data.ParaValue = ModbusConvert.GetInt(vals, 0).ToString(); } break; } } break; } } } return(null); }
public override bool InitDrive(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para, SCADA_DEVICE_DRIVER driver) { bool res = base.InitDrive(server, communication, device, para, driver); if (res) { if (IsCreateControl) { if (para != null) { this.ParaCtrl = new TCP_IOParaCtrl(); } this.DeviceCtrl = new TCP_IODeviceCtrl(); } } return(res); }
protected override ScadaResult IOSendCommand(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value) { ScadaResult res = new ScadaResult(); if (device == null) { res = new ScadaResult(false, "设备对象不存在"); } //用户发送一条命令后要及时获取最新的数据,主要是因为有些命令需要及时判断命令是否成功, if (ResponseData(server, comm, device, para, value)) { RealData realData = this.RealDevices.Find(x => x.Device == device); string error = ""; if (RequestData(realData.Device, realData, out error, realData.Fragment)) { res = new ScadaResult(true, "请求数据成功"); } } DataSended(server, comm, device, para, value, res.Result); return(res); }
protected override ScadaResult IOSendCommand(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value) { try { ParaPack deviceparaPack = new ParaPack(device.IO_DEVICE_PARASTRING); ParaPack paraPack = new ParaPack(para.IO_PARASTRING); ///向指定客户端的指定设备发送下置命令的数据 Task.Run(async() => { if (deviceparaPack.GetValue("数据格式") == "江苏协昌环保股份有限公司") { string paraType = paraPack.GetValue("是否命令参数"); string cmdJson = ""; switch (paraType) { case "采集参数": cmdJson = "{\"uid\":\"" + device.IO_DEVICE_ADDRESS + "\",\"paraname\":\"" + para.IO_NAME + "\",\"value\":\"" + value + "\",\"jsonname\":\"" + paraPack.GetValue("JSON名称") + "\",\"defaultvalue\":\"null\"}"; break; case "升级命令": cmdJson = "{\"uid\":\"" + device.IO_DEVICE_ADDRESS + "\",\"paraname\":\"" + para.IO_NAME + "\",\"value\":\"" + value + "\",\"jsonname\":\"oa\",\"defaultvalue\":\"null\"}"; break; case "开关量扫描": break; case "复合采集扫描": break; case "脉宽扫描": break; case "电流扫描": break; case "重启命令": break; } string topic = deviceparaPack.GetValue("命令主题").Trim(); // 将字符串转换为字符数组 await this._mqttServer.PublishAsync(new MqttApplicationMessage() { Topic = topic, QualityOfServiceLevel = MessageQulity, Retain = true, Payload = Scada.Kernel.ScadaHexByteOperator.StringToAsciiByte(cmdJson) }); } else if (deviceparaPack.GetValue("数据格式") == "通用MQTT解析") { string cmdJson = "{\"uid\":\"" + device.IO_DEVICE_ADDRESS + "\",\"paraname\":\"" + para.IO_NAME + "\",\"value\":\"" + value + "\",\"jsonname\":\"" + paraPack.GetValue("IO标识") + "\",\"defaultvalue\":\"" + paraPack.GetValue("命令默认值") + "\"}"; string topic = deviceparaPack.GetValue("下置命令主题").Trim(); // 将字符串转换为字符数组 await this._mqttServer.PublishAsync(new MqttApplicationMessage() { Topic = topic, QualityOfServiceLevel = MessageQulity, Retain = true, Payload = Scada.Kernel.ScadaHexByteOperator.StringToAsciiByte(cmdJson) }); } }); return(new ScadaResult()); } catch (Exception emx) { return(new ScadaResult(false, emx.Message)); } }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device, IO_PARA para) { base.SetUIParameter(server, device, para); }
//低限和超低限报警 private void MakeDownAlarm(ref IO_PARAALARM alarm, decimal dvalue, string IO_CONDITION, List <IO_PARA> deviceParas, IOData dataValue, string AlarmLevel, string AlarmType, decimal AlarmTypeValue) { alarm.IO_ALARM_LEVEL = AlarmType; alarm.IO_ALARM_TYPE = AlarmLevel; if (dvalue < AlarmTypeValue) { //是否有前置条件,如果没有前置条件,则报警,否则不报警 if (IO_CONDITION == "") { alarm.IO_ALARM_DISPOSALIDEA = ""; alarm.IO_ALARM_DISPOSALUSER = ""; alarm.IO_ALARM_VALUE = dataValue.ParaValue; return; } else { alarm.IO_ALARM_DISPOSALIDEA = ""; alarm.IO_ALARM_DISPOSALUSER = ""; alarm.IO_ALARM_VALUE = dataValue.ParaValue; string[] condition = IO_CONDITION.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (condition.Length <= 0) { return; } else { bool isInvalid = true; #region 前置条件判断 for (int i = 0; i < condition.Length; i++) { string[] cond_values = condition[i].Split(new char[3] { '>', '=', '<' }, StringSplitOptions.RemoveEmptyEntries); if (cond_values.Length == 2) { IO_PARA conditonPara = deviceParas.Find(x => x.IO_NAME == cond_values[0]); if (conditonPara != null && conditonPara.IORealData != null && conditonPara.IORealData.QualityStamp == QualityStamp.GOOD && conditonPara.IORealData.ParaValue != "-9999" && conditonPara.IORealData.ParaValue != "") { #region 条件判断 if (condition[i].Contains(">")) { decimal pvalue = -9999; decimal cvalue = -9999; if (decimal.TryParse(conditonPara.IORealData.ParaValue, out pvalue) && decimal.TryParse(cond_values[1], out cvalue)) { isInvalid = pvalue > cvalue ? true : false; if (isInvalid == false)//条件不满足报警要求,则停止判断 { break; } } } else if (condition[i].Contains("=")) { decimal pvalue = -9999; decimal cvalue = -9999; if (decimal.TryParse(conditonPara.IORealData.ParaValue, out pvalue) && decimal.TryParse(cond_values[1], out cvalue)) { isInvalid = pvalue == cvalue ? true : false; if (isInvalid == false)//条件不满足报警要求,则停止判断 { break; } } } else if (condition[i].Contains("<")) { decimal pvalue = -9999; decimal cvalue = -9999; if (decimal.TryParse(conditonPara.IORealData.ParaValue, out pvalue) && decimal.TryParse(cond_values[1], out cvalue)) { isInvalid = pvalue < cvalue ? true : false; if (isInvalid == false)//条件不满足报警要求,则停止判断 { break; } } } #endregion } } } #endregion if (!isInvalid) { alarm = null; } } } } else { alarm = null; } }
public void SetPara(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para) { this.lbID.Text = para.IO_ID; this.lbAddress.Text = para.IO_ADDRESS; this.lbDataType.Text = para.IO_DATATYPE; if (para.IO_ENABLERANGECONVERSION == 1) { this.lbEnableConvertionRange.Text = "是"; } else { this.lbEnableConvertionRange.Text = "否"; } if (para.IO_HISTORY == 1) { this.lbHistory.Text = "是"; } else { this.lbHistory.Text = "否"; } this.lbDefault.Text = para.IO_INITALVALUE; this.lbDecimalPlace.Text = para.IO_OUTLIES; this.lbLabel.Text = para.IO_LABEL; this.lbName.Text = para.IO_NAME; this.lbMinValue.Text = para.IO_MINVALUE; this.lbMaxValue.Text = para.IO_MAXVALUE; this.lbOne.Text = para.IO_ONE; this.lbParaString.Text = para.IO_PARASTRING; this.lbIOType.Text = para.IO_POINTTYPE; this.lbRangeMax.Text = para.IO_RANGEMAX; this.lbRangeMin.Text = para.IO_RANGEMIN; this.lbUnit.Text = para.IO_UNIT; this.lbZero.Text = para.IO_ZERO; if (para.IO_ENABLEALARM == 1) { this.lbAlarmEnable.Text = "是"; } else { this.lbAlarmEnable.Text = "否"; } if (para.AlarmConfig.IO_ENABLE_MAX == 1) { this.lbMaxEnable.Text = "是"; } else { this.lbMaxEnable.Text = "否"; } if (para.AlarmConfig.IO_ENABLE_MAXMAX == 1) { this.lbMaxMaxEnable.Text = "是"; } else { this.lbMaxMaxEnable.Text = "否"; } if (para.AlarmConfig.IO_ENABLE_MINMIN == 1) { this.lbMinMinEnable.Text = "是"; } else { this.lbMinMinEnable.Text = "否"; } if (para.AlarmConfig.IO_ENABLE_MIN == 1) { this.lbMinEnable.Text = "是"; } else { this.lbMinEnable.Text = "否"; } this.lbMaxAlarmType.Text = para.AlarmConfig.IO_MAX_TYPE; this.lbMaxMaxAlarmType.Text = para.AlarmConfig.IO_MAXMAX_TYPE; this.lbMinAlarmType.Text = para.AlarmConfig.IO_MIN_TYPE; this.lbMinMinAlarmType.Text = para.AlarmConfig.IO_MINMIN_TYPE; this.lbMaxMaxAlarmValue.Text = para.AlarmConfig.IO_MAXMAX_VALUE.ToString(); this.lbMaxAlarmValue.Text = para.AlarmConfig.IO_MAX_VALUE.ToString(); this.lbMinAlarmValue.Text = para.AlarmConfig.IO_MIN_VALUE.ToString(); this.lbMinMinAlarmValue.Text = para.AlarmConfig.IO_MINMIN_VALUE.ToString(); lbAlarmCondition.Text = para.AlarmConfig.IO_CONDITION.ToString(); //加载通道信息 this.lbCommID.Text = comm.IO_COMM_ID; this.lbCommLabel.Text = comm.IO_COMM_LABEL; this.lbCommName.Text = comm.IO_COMM_NAME; this.lbCommDriver.Text = comm.IO_COMM_PARASTRING.ToString(); this.lbDeviceIAddress.Text = device.IO_DEVICE_ADDRESS; this.lbDeviceID.Text = device.IO_DEVICE_ID; this.lbDeviceILabel.Text = device.IO_DEVICE_LABLE; this.lbDeviceIName.Text = device.IO_DEVICE_NAME; this.lbDeviceTimeout.Text = device.IO_DEVICE_OVERTIME.ToString(); this.lbDeviceUpdateCirycle.Text = device.IO_DEVICE_UPDATECYCLE.ToString(); this.lbDeviceDriver.Text = device.IO_DEVICE_PARASTRING; }
/// <summary> /// 生成报警,这个传入值必须是量程转换后的(如果开启量程转换) /// </summary> /// <param name="para"></param> /// <param name="dataValue"></param> /// <returns></returns> public IO_PARAALARM MakeAlarm(List <IO_PARA> deviceParas, IO_PARA para, IOData dataValue, string devicename) { // IO_PARAALARM maxmaxAlarm = null; IO_PARAALARM maxAlarm = null; IO_PARAALARM minAlarm = null; IO_PARAALARM minminAlarm = null; if (para == null) { return(null); } if (para.IO_POINTTYPE != "模拟量") { return(null); } if (dataValue == null) { return(null); } if (dataValue.QualityStamp != QualityStamp.GOOD) { return(null); } if (dataValue.ParaValue == "-9999") { return(null); } if (dataValue.ParaValue == "") { return(null); } decimal dvalue = -9999; if (!decimal.TryParse(dataValue.ParaValue, out dvalue)) { return(null); } if (para.AlarmConfig == null) { return(null); } if (para.IO_ENABLEALARM == 1) { //高级报警 if (para.AlarmConfig.IO_ENABLE_MAX.Value == 1) { maxAlarm = new IO_PARAALARM(); maxAlarm.DEVICE_NAME = devicename; maxAlarm.IO_ALARM_ID = ""; maxAlarm.IO_ALARM_DATE = dataValue == null ? "" : dataValue.Date.Value.ToString("yyyy-MM-dd HH:mm:ss"); maxAlarm.IO_ID = para.IO_ID; maxAlarm.IO_LABEL = para.IO_LABEL; maxAlarm.IO_NAME = para.IO_NAME; maxAlarm.IO_SERVER_ID = para.IO_SERVER_ID; maxAlarm.IO_DEVICE_ID = para.IO_DEVICE_ID; maxAlarm.IO_COMM_ID = para.IO_COMM_ID; maxAlarm.IO_ALARM_LEVEL = para.AlarmConfig.IO_MAX_TYPE; maxAlarm.IO_ALARM_TYPE = "高限报警"; MakeUpAlarm(ref maxAlarm, dvalue, para.AlarmConfig.IO_CONDITION, deviceParas, dataValue, maxAlarm.IO_ALARM_LEVEL, "高限报警", para.AlarmConfig.IO_MAX_VALUE.Value); } //超高限报警 if (para.AlarmConfig.IO_ENABLE_MAXMAX.Value == 1) { maxmaxAlarm = new IO_PARAALARM(); maxmaxAlarm.DEVICE_NAME = devicename; maxmaxAlarm.IO_ALARM_ID = ""; maxmaxAlarm.IO_ALARM_DATE = dataValue == null ? "" : dataValue.Date.Value.ToString("yyyy-MM-dd HH:mm:ss"); maxmaxAlarm.IO_ID = para.IO_ID; maxmaxAlarm.IO_LABEL = para.IO_LABEL; maxmaxAlarm.IO_NAME = para.IO_NAME; maxmaxAlarm.IO_SERVER_ID = para.IO_SERVER_ID; maxmaxAlarm.IO_DEVICE_ID = para.IO_DEVICE_ID; maxmaxAlarm.IO_COMM_ID = para.IO_COMM_ID; maxmaxAlarm.IO_ALARM_LEVEL = para.AlarmConfig.IO_MAXMAX_TYPE; maxmaxAlarm.IO_ALARM_TYPE = "超高限报警"; MakeUpAlarm(ref maxmaxAlarm, dvalue, para.AlarmConfig.IO_CONDITION, deviceParas, dataValue, maxmaxAlarm.IO_ALARM_LEVEL, "超高限报警", para.AlarmConfig.IO_MAXMAX_VALUE.Value); } //低限报警 if (para.AlarmConfig.IO_ENABLE_MIN.Value == 1) { minAlarm = new IO_PARAALARM(); minAlarm.DEVICE_NAME = devicename; minAlarm.IO_ALARM_ID = ""; minAlarm.IO_ALARM_DATE = dataValue == null ? "" : dataValue.Date.Value.ToString("yyyy-MM-dd HH:mm:ss"); minAlarm.IO_ID = para.IO_ID; minAlarm.IO_LABEL = para.IO_LABEL; minAlarm.IO_NAME = para.IO_NAME; minAlarm.IO_SERVER_ID = para.IO_SERVER_ID; minAlarm.IO_DEVICE_ID = para.IO_DEVICE_ID; minAlarm.IO_COMM_ID = para.IO_COMM_ID; minAlarm.IO_ALARM_LEVEL = para.AlarmConfig.IO_MIN_TYPE; minAlarm.IO_ALARM_TYPE = "低限报警"; MakeDownAlarm(ref minAlarm, dvalue, para.AlarmConfig.IO_CONDITION, deviceParas, dataValue, minAlarm.IO_ALARM_LEVEL, "低限报警", para.AlarmConfig.IO_MIN_VALUE.Value); } //超低限报警 if (para.AlarmConfig.IO_ENABLE_MINMIN.Value == 1) { minminAlarm = new IO_PARAALARM(); minminAlarm.DEVICE_NAME = devicename; minminAlarm.IO_ALARM_ID = ""; minminAlarm.IO_ALARM_DATE = dataValue == null ? "" : dataValue.Date.Value.ToString("yyyy-MM-dd HH:mm:ss"); minminAlarm.IO_ID = para.IO_ID; minminAlarm.IO_LABEL = para.IO_LABEL; minminAlarm.IO_NAME = para.IO_NAME; minminAlarm.IO_SERVER_ID = para.IO_SERVER_ID; minminAlarm.IO_DEVICE_ID = para.IO_DEVICE_ID; minminAlarm.IO_COMM_ID = para.IO_COMM_ID; minminAlarm.IO_ALARM_LEVEL = para.AlarmConfig.IO_MINMIN_TYPE; minminAlarm.IO_ALARM_TYPE = "超低限报警"; MakeDownAlarm(ref minminAlarm, dvalue, para.AlarmConfig.IO_CONDITION, deviceParas, dataValue, minminAlarm.IO_ALARM_LEVEL, "超低限报警", para.AlarmConfig.IO_MINMIN_VALUE.Value); } } if (maxmaxAlarm != null) { return(maxmaxAlarm); } if (maxAlarm != null) { return(maxAlarm); } if (minminAlarm != null) { return(minminAlarm); } if (minAlarm != null) { return(minAlarm); } return(null); }