Пример #1
0
        private void menuItemComm_Click(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild != null)
            {
                frmDevice        frmDev      = (frmDevice)(this.ActiveMdiChild);
                ModBusDevice     device      = frmDev._device;
                frmDeviceSetting commSetting = new frmDeviceSetting(device);
                commSetting.ShowDialog();
                if (commSetting._bOk)
                {
                    if (commSetting.PortIsChanged())
                    {
                        bool bCurMonitorStatus = device._bMonitor;
                        bool bPortIsOpen       = (device._port != null) ? device._port.IsOpen : false;
                        device._bMonitor = false;
                        device.ClosePort();
                        commSetting.GetDeviceInfo(ref device);

                        if (bPortIsOpen)
                        {
                            device.OpenPort();
                        }

                        device._bMonitor = bCurMonitorStatus;
                    }
                    device._bModified = true;
                }
            }
        }
Пример #2
0
        private void ShowDeviceForm(ModBusDevice device)
        {
            frmDevice frmDev = new frmDevice(device);

            frmDev.MdiParent  = this;
            frmDev.SetBarText = InvokeSetBarText;
            frmDev.Show();
        }
Пример #3
0
        private void UpdateInputStatus(int nAddr, byte[] data, ModBusDevice device)
        {
            frmDevice chFrmDev = GetFormByDeviceName(device.Name);

            if (chFrmDev._device != null)
            {
                chFrmDev.InvokeUpdateInputStatus(nAddr, data);
            }
        }
Пример #4
0
        private bool SaveCurrentDevice()
        {
            frmDevice frmDev = (frmDevice)this.ActiveMdiChild;

            if (frmDev._device._bModified || frmDev._device._bCreatNew)
            {
                int nRet = (int)MessageBox.Show("是否保存当前设备数据?", "设备" + frmDev._device.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (nRet == (int)DialogResult.Yes)
                {
                    if (frmDev._device._bCreatNew)
                    {
                        SaveDevice(frmDev._device);
                    }
                    else
                    {
                        try
                        {
                            XmlSerializer xs       = new XmlSerializer(typeof(ModBusDevice));
                            Stream        myStream = new FileStream(frmDev._device._strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                            xs.Serialize(myStream, frmDev._device);
                            frmDev._device._bModified = false;
                            myStream.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "保存设备" + frmDev._device.Name + "到文件失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else if (nRet != (int)DialogResult.No)
                {
                    return(false);
                }
            }
            return(true);
        }