示例#1
0
        private void buttonOpenClose_Click(object sender, EventArgs e)
        {
            if (_serial_modbus == null)
            {
                _serial_driver = new PackedSerialPort();
                _serial_driver.StateIsChanged += this.serialPortStateIsChanged;
                _serial_modbus = new SerialModbusDevice(_serial_driver, 1);
                _table_shell   = new MiniModbusDeviceTableShell(_serial_modbus);
                _table_shell.TablesWereCreated   += deviceWasChanged;
                _serial_modbus.readingIsComplete += readingIsComplete;
            }

            if (_serial_driver.IsOpen())
            {
                _serial_modbus.StopCommunication();
                _serial_driver.Close();
            }
            else
            {
                if (comboBoxAvailablePortList.SelectedItem != null)
                {
                    _serial_driver.Open(comboBoxAvailablePortList.SelectedItem.ToString(), 115200);
                }
            }
        }
示例#2
0
        private void buttonOpenClose_Click(object sender, EventArgs e)
        {
            if (_serial_modbus == null)
            {
                _serial_driver = new PackedSerialPort();
                _serial_driver.StateIsChanged += this.serialPortStateIsChanged;

                byte id = Convert.ToByte(textBoxNetId.Text);
                _serial_modbus = new SerialModbusDevice(_serial_driver, id);
                _table_shell   = new MiniModbusDeviceTableShell(_serial_modbus);
                _table_shell.TablesWereCreated += deviceWasChanged;
            }

            if (_serial_driver.IsOpen())
            {
                _serial_modbus.StopCommunication();
                _serial_driver.Close();
                textBoxNetId.Enabled = true;
            }
            else
            {
                if (comboBoxAvailablePortList.SelectedItem != null)
                {
                    int speed = Utility.ConvertSpeed(comboBoxAvailableSpeeds.SelectedItem.ToString());
                    if (speed >= 0)
                    {
                        byte id = Convert.ToByte(textBoxNetId.Text);
                        _serial_modbus.ChangeID(id);
                        _serial_driver.Open(comboBoxAvailablePortList.SelectedItem.ToString(), speed);
                        textBoxNetId.Enabled = false;
                    }
                }
            }
        }
示例#3
0
        private void start_serial_communication()
        {
            _serial_driver = new PackedSerialPort();
            _serial_driver.StateIsChanged += this.serialPortStateIsChanged;
            _serial_modbus = new SerialModbusDevice(_serial_driver, (byte)board_settings.__bus_id);

            _table_shell = new MiniModbusDeviceTableShell_ExternalControl(_serial_modbus, board_settings);
            _table_shell.TablesWereCreated += deviceWasChanged;

            _serial_driver.Open(board_settings.serial_port, 115200);
        }
示例#4
0
        private void deviceWasChanged(object sender, EventArgs e)
        {
            MiniModbusDeviceTableShell table_shell = (MiniModbusDeviceTableShell)sender;

            this.Invoke(new some_action(() =>
            {
                dataGridGeneralData.DataSource = table_shell.GeneralInfo.Table;
                dataGridROData.DataSource      = table_shell.ROInfo.Table;
                dataGridRWData.DataSource      = table_shell.RWInfo.Table;
                dataGridFlashData.DataSource   = table_shell.RWFlashInfo.Table;
                DebugBox.Text = DebugBox.Text + "Обнаружено устройство - " + table_shell.Name + "\r\n";
            }));
        }