public IODeviceNode() { Device = new IO_DEVICE(); mContextMenu = new ContextMenu(); mContextMenu.MenuItems.Add(new MenuItem("删除设备") { Tag = 1 }); mContextMenu.MenuItems.Add(new MenuItem("修改设备") { Tag = 2 }); mContextMenu.MenuItems.Add(new MenuItem("编辑IO表") { Tag = 3 }); mContextMenu.MenuItems[0].Click += DeviceNode_Click; mContextMenu.MenuItems[1].Click += DeviceNode_Click; mContextMenu.MenuItems[2].Click += DeviceNode_Click; this.ContextMenu = mContextMenu; Device.IO_DEVICE_ID = GUIDTo16.GuidToLongID().ToString(); this.SelectedImageIndex = 2; this.StateImageIndex = 2; this.ImageIndex = 2; ChangedNode(); }
public void InitDevice(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device) { Device = device; Server = server; Communication = communication; SeriesIndex = -1; InitSeires(); InitListView(); if (Device != null) { //获取读取实时值 IOCenterManager.QueryFormManager.ReadRealDevice(this.Server, this.Communication, this.Device); TreeNode[] finders = this.hsComboBox.TreeView.Nodes.Find(Device.IO_DEVICE_ID, true); if (finders.Length > 0) { IoDeviceTreeNode node = finders[0] as IoDeviceTreeNode; this.hsComboBox.ShowItem(node); } realtimer.Interval = Device.IO_DEVICE_UPDATECYCLE * 1000; } if (Device != null) { realtimer.Interval = this.Device.IO_DEVICE_UPDATECYCLE * 1000; realtimer.Tick += Realtimer_Tick; realtimer.Start(); } }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device) { try { this.ParaString = device.IO_DEVICE_PARASTRING; string[] strs = this.ParaString.Split(new char[2] { ':', ',' }); if (strs.Length == 4) { for (int i = 0; i < cbo_modbusType.Items.Count; i++) { if (cbo_modbusType.Items[i].ToString() == strs[1]) { cbo_modbusType.SelectedIndex = i; break; } } for (int i = 0; i < cbStored.Items.Count; i++) { if (cbStored.Items[i].ToString() == strs[3]) { cbStored.SelectedIndex = i; break; } } } } catch { } }
public static string GetAlarmCacheString(IO_DEVICE device, out List <IO_PARAALARM> alarms) { alarms = new List <IO_PARAALARM>(); IODeviceParaMaker paraMaker = new IODeviceParaMaker(); string alarmString = ""; for (int i = 0; i < device.IOParas.Count; i++) { try { IO_PARAALARM alarm = paraMaker.MakeAlarm(device.IOParas, device.IOParas[i], device.IOParas[i].IORealData, device.IO_DEVICE_LABLE); if (alarm != null && !string.IsNullOrEmpty(alarm.IO_ALARM_DATE)) { alarmString += "^" + alarm.GetCommandString(); alarms.Add(alarm); } } catch { continue; } } return(alarmString); }
public bool InitKernel(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para, SCADA_DEVICE_DRIVER driver) { try { this.ParaString = ""; this.DeviceParaString = ""; this.IOServer = server; this.IOCommunication = communication; this.IODevice = device; this.Driver = driver; if (para != null) { this.ParaString = para.IO_PARASTRING; } if (device != null) { this.DeviceParaString = device.IO_DEVICE_PARASTRING; } return(InitDeviceKernel(server, communication, device, para, driver)); } catch { return(false); } }
public void LoadProject() { Task.Run(() => { DataBaseFileName = Application.StartupPath + "\\IOProject\\IOCenterServer.station"; //设置数据库数据源 DbHelperSQLite.connectionString = "Data Source=" + DataBaseFileName; IO_SERVER serverBll = new IO_SERVER(); IO_COMMUNICATION commBll = new IO_COMMUNICATION(); IO_DEVICE deviceBll = new IO_DEVICE(); AddLog("初始化采集站数据......"); Servers = serverBll.GetModelList(""); AddLog("采集站数据已经完成!"); AddLog("加载通道数据......"); Communications = commBll.GetModelList(""); AddLog("通道数据已经完成!"); AddLog("加载设备及其IO点表......"); Devices = deviceBll.GetModelList(""); AddLog("加载设备及其IO点表已经完成"); for (int i = 0; i < Communications.Count; i++) { Communications[i].Devices = Devices.FindAll(x => x.IO_COMM_ID == Communications[i].IO_COMM_ID && x.IO_SERVER_ID == Communications[i].IO_SERVER_ID); } }); }
/// <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 void InitDevice(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device) { InitSeriesListBox(device); Device = device; Server = server; Communication = communication; this.search.StartDate = DateTime.Now.AddDays(-10); this.search.EndDate = DateTime.Now; this.listBoxSeries.Items.Clear(); //此处只增加模拟量的IO点 for (int i = 0; i < Device.IOParas.Count; i++) { if (Device.IOParas[i].IO_POINTTYPE == "模拟量") { this.listBoxSeries.Items.Add(Device.IOParas[i]); } } if (Device != null) { ///设置下拉菜单选中项 this.search.SetSelectItem(this.Server, this.Communication, this.Device); ReadHistory(); } }
public void ChangedBinds(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device) { if (IOMonitorManager.IsBackRun) { return; } if (this.IsHandleCreated) { listView.BeginInvoke(new EventHandler(delegate { if (device != null) { ucRollText.Text = "IO路径: /" + server.SERVER_NAME + "/" + comm.IO_COMM_NAME + "[" + comm.IO_COMM_LABEL + "]/" + device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "]"; this.listView.Items.Clear(); foreach (IO_PARA para in device.IOParas) { ListViewItem lvItem = new ListViewItem(para.IO_ID); lvItem.Text = para.IO_ID; lvItem.Tag = para; lvItem.SubItems.Add(para.IO_NAME); lvItem.SubItems.Add(para.IO_LABEL); lvItem.SubItems.Add(para.RealValue); lvItem.SubItems.Add(para.IO_UNIT); lvItem.SubItems.Add(para.RealDate); lvItem.SubItems.Add(para.RealQualityStamp.ToString()); lvItem.SubItems.Add(para.IO_POINTTYPE.ToString()); this.listView.Items.Add(lvItem); } } })); } }
/// <summary> /// 发送数据完成的事件 /// </summary> /// <param name="server"></param> /// <param name="device"></param> /// <param name="para"></param> /// <param name="value"></param> protected void DataSended(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value, bool result) { if (DeviceSended != null) { DeviceSended(server, comm, device, para, value, result); } }
public void CloseForm() { Server = null; Communication = null; Device = null; this.DialogResult = DialogResult.Cancel; }
private void btnCancel_BtnClick(object sender, EventArgs e) { Server = null; Communication = null; Device = null; this.DialogResult = DialogResult.Cancel; }
/// <summary> /// /// </summary> /// <param name="server"></param> /// <param name="comm"></param> /// <param name="device"></param> /// <param name="receivedatas">接收的数据的字节</param> /// <param name="date">接收数据的日期</param> /// <param name="sender">接收数据的其它限定参数</param> protected void ReceiveData(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, byte[] receivedatas, string date, object sender = null) { Task.Run(() => { if (OnDataReceived != null) { OnDataReceived(server, comm, device, receivedatas, date, sender); } }); }
/// <summary> /// 设备通讯状态变化的时候修改对应的界面显示效果,树结构中的参数 /// </summary> /// <param name="server"></param> /// <param name="device"></param> /// <param name="para"></param> /// <param name="tag"></param> protected void DeviceStatus(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, object tag) { if (device != null) { if (DeviceStatusChanged != null) { DeviceStatusChanged(server, comm, device, para, tag); } } }
/// <summary> /// 用户点击查询按钮进行数据查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Search_SearchClick(object sender, EventArgs e) { if (sender != null) { IO_DEVICE selectDevice = sender as IO_DEVICE; //初始化多选框 Device = selectDevice; ReadAlarmHistory(); } }
/// <summary> /// 用户点击查询按钮进行数据查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Search_SearchClick(object sender, EventArgs e) { if (sender != null) { IO_DEVICE selectDevice = sender as IO_DEVICE; //初始化多选框 InitSeriesListBox(selectDevice); Device = selectDevice; ReadHistory(); } }
/// <summary> /// 模拟量 ///开关量 ///字符串量 ///计算值 ///关系数据库值 /// </summary> /// <param name="device"></param> public void InitDevice(IO_DEVICE device) { cbIo.Items.Clear(); for (int i = 0; i < device.IOParas.Count; i++) { if (device.IOParas[i].IO_POINTTYPE != "字符串量" && device.IOParas[i].IO_POINTTYPE != "计算值") { cbIo.Items.Add(device.IOParas[i].IO_NAME); } } }
private void Search_SelectedIndexChanged(object sender, EventArgs e) { if (this.search.Server != null && this.search.Communication != null && this.search.Device != null) { this.Text = this.search.Server.SERVER_NAME + "//" + this.search.Communication.IO_COMM_NAME + "//" + this.search.Device.IO_DEVICE_NAME; IO_DEVICE selectDevice = sender as IO_DEVICE; //初始化多选框 Device = selectDevice; ReadAlarmHistory(); } }
public void SetSelectItem(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device) { Device = device; Communication = communication; Server = server; TreeNode[] finders = this.hsComboBoxDevices.TreeView.Nodes.Find(device.IO_DEVICE_ID, true); if (finders.Length > 0) { IoDeviceTreeNode node = finders[0] as IoDeviceTreeNode; this.hsComboBoxDevices.ShowItem(node); } }
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; }
public void 剪贴toolStripMenuItem_Click(object sender, EventArgs e) { if (Device != null) { copyDevice = null; cutIds.Clear(); copyIds.Clear(); for (int i = this.listView.SelectedItems.Count - 1; i >= 0; i--) { IOListViewItem lvi = this.listView.SelectedItems[i] as IOListViewItem; cutIds.Add(lvi.Para); } copyDevice = Device; } }
public override void SetUIParameter(IO_SERVER server, IO_DEVICE device) { ParaPack paraPack = new ParaPack(device.IO_DEVICE_PARASTRING); paraPack.SetCtrlValue(tbIdentification, paraPack.GetValue("注册标识")); paraPack.SetCtrlValue(txtAddress, device.IO_DEVICE_ADDRESS); paraPack.SetCtrlValue(cbModbusType, paraPack.GetValue("Modbus类型")); paraPack.SetCtrlValue(nbReadTimeout, paraPack.GetValue("读超时")); paraPack.SetCtrlValue(nbWriteTimeout, paraPack.GetValue("写超时")); paraPack.SetCtrlValue(ndReadBuffSize, paraPack.GetValue("读缓存")); paraPack.SetCtrlValue(ndWriteBufferSize, paraPack.GetValue("写缓存")); paraPack.SetCtrlValue(cbRetries, paraPack.GetValue("失败重试")); paraPack.SetCtrlValue(ndRetiresNum, paraPack.GetValue("重试次数")); paraPack.SetCtrlValue(nbRetiresInternal, paraPack.GetValue("重试间隔")); }
/// <summary> /// 当前实时设备状态改变信息 /// </summary> /// <param name="device"></param> /// <returns></returns> public void DeviceStatus(string IO_SERVER_ID, IO_DEVICE device, bool status) { if (this.IsHandleCreated && IOTreeView.InvokeRequired) { IOTreeView.BeginInvoke(new EventHandler(delegate { if (this.IOTreeView.Nodes.Count < 0) { return; } for (int i = 0; i < this.IOTreeView.Nodes[0].Nodes.Count; i++) { TreeNode[] tn = this.IOTreeView.Nodes[0].Nodes.Find(device.IO_DEVICE_ID.ToString(), true); for (int j = 0; j < tn.Length; j++) { if (tn.Length == 1 && tn[j] is Controls.IoDeviceTreeNode) { Controls.IoDeviceTreeNode deviceNode = tn[j] as Controls.IoDeviceTreeNode; if (deviceNode != null && deviceNode.Device.IO_SERVER_ID == IO_SERVER_ID) { deviceNode.status = status; if (deviceNode.status) { deviceNode.ForeColor = Color.Green; deviceNode.Parent.ForeColor = Color.Green; deviceNode.Parent.Parent.ForeColor = Color.Green; deviceNode.SelectedImageIndex = 5; deviceNode.ImageIndex = 5; deviceNode.Tag = null; } else { deviceNode.ForeColor = Color.Red; deviceNode.SelectedImageIndex = 4; deviceNode.ImageIndex = 4; deviceNode.Tag = DateTime.Now.ToString("yyyy-MM-dd"); } } } } } })); } IOCenterManager.QueryFormManager.Mediator.IOTreeForm.DeviceStatus(IO_SERVER_ID, device, status); }
private bool Send(IO_DEVICE device, byte[] datas, out string error) { error = ""; try { if (_serialPort != null && _serialPort.IsOpen) { master.WriteMultipleRegisters(device.IO_DEVICE_ADDRESS) } return(true); } catch { return(false); } }
//发送下置命令,没有返回结构的值 public ScadaResult SendCommand(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value) { try { ScadaResult result = IOSendCommand(server, comm, device, para, value); if (DeviceSended != null) { DeviceSended(server, comm, device, para, value, false); } return(result); } catch { return(new ScadaResult(false, "发送数据失败")); } }
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 void InitDevice(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device) { Device = device; Server = server; Communication = communication; this.search.StartDate = DateTime.Now.AddDays(-10); this.search.EndDate = DateTime.Now; if (Device != null) { ///设置下拉菜单选中项 this.search.SetSelectItem(this.Server, this.Communication, this.Device); ReadAlarmHistory(); } }
public IOData AnalysisData(IO_SERVER server, IO_COMMUNICATION Communication, IO_DEVICE device, IO_PARA para, byte[] datas, DateTime datatime, object sender) { try { return(Task <IOData> .Run(() => { IOData data = Analysis(server, Communication, device, para, datas, datatime, sender); return data; }).Result); } catch (Exception emx) { DeviceException(emx.Message); return(null); } }
public void InitForm() { FormManager.IODeviceDriveCombox(cb_Driver, Communication.IO_COMM_DRIVER_ID); if (Device == null) { Device = new IO_DEVICE(); Device.IO_DEVICE_ID = GUIDTo16.GuidToLongID().ToString(); IOCommunicationNode commNode = FormManager.mediator.IOTreeForm.IoTree.GetCommunicationNode(Server, Communication); if (commNode != null) { int num = commNode.DeviceNumber; Device.IO_DEVICE_NAME = "Device" + num; Device.IO_DEVICE_LABLE = Device.IO_DEVICE_NAME; Device.IO_DEVICE_OVERTIME = 120; Device.IO_DEVICE_UPDATECYCLE = 120; Device.IO_DEVICE_ADDRESS = num.ToString(); } Device.IO_DEVICE_STATUS = 0; } Device.IO_COMM_ID = Communication.IO_COMM_ID; Device.IO_SERVER_ID = Server.SERVER_ID; this.txtID.Text = Device.IO_DEVICE_ID; this.txtLabel.Text = Device.IO_DEVICE_LABLE; this.txtName.Text = Device.IO_DEVICE_NAME; this.txtRemark.Text = Device.IO_DEVICE_REMARK; this.txtAddress.Text = Device.IO_DEVICE_ADDRESS; this.nd_timeout.Value = Device.IO_DEVICE_OVERTIME; this.nd_updatecycle.Value = Device.IO_DEVICE_UPDATECYCLE; for (int i = 0; i < this.cb_Driver.Items.Count; i++) { Scada.Model.SCADA_DEVICE_DRIVER driver = this.cb_Driver.Items[i] as Scada.Model.SCADA_DEVICE_DRIVER; if (driver.Id == Device.DEVICE_DRIVER_ID) { this.cb_Driver.SelectedIndex = i; break; } } if (this.cb_Driver.SelectedIndex <= 0 && this.cb_Driver.Items.Count > 0) { this.cb_Driver.SelectedIndex = 0; } }
private void hsComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (hsComboBoxDevices.SelectedItem != null) { IoDeviceTreeNode node = hsComboBoxDevices.SelectedItem as IoDeviceTreeNode; //如果选择的还是同一个设备,就不做处理 if (this.Device != node.Device) { this.Server = node.Server; this.Communication = node.Communication; this.Device = node.Device; if (SelectedIndexChanged != null) { SelectedIndexChanged(sender, e); } } } }