Beispiel #1
0
        private void OnAddStation(object sender, EventArgs e)
        {
            string var = GetUniqueStationName();
            int    row = stationGrid.RowsCount;
            string ip  = "127.0.0.1";
            int    po  = 502;
            string com = "COM1";

            AddStationForm asf = new AddStationForm();

            if (asf.ShowDialog() == DialogResult.OK)
            {
                if (asf.stationTypeComboBox.SelectedItem != null)
                {
                    switch ((ModbusStationType)asf.stationTypeComboBox.SelectedItem)
                    {
                    case ModbusStationType.TCPMaster:
                        ModbusTCPClientStation     stat = new ModbusTCPClientStation(var, plugin, ip, po, 100, 1000, 3, 20);
                        ModifyTCPClientStationForm mtc  = new ModifyTCPClientStationForm(stat, null);
                        if (mtc.ShowDialog() == DialogResult.OK)
                        {
                            AddTCPClientStation(stat);
                            stationGrid.Selection.ResetSelection(true);
                            stationGrid.Selection.SelectRow(row, true);
                        }
                        break;

                    case ModbusStationType.SerialMaster:
                        ModbusSerialClientStation     stat2 = new ModbusSerialClientStation(var, plugin, com, 100, 1000, 3, 20);
                        ModifySerialClientStationForm msc   = new ModifySerialClientStationForm(stat2, null);
                        if (msc.ShowDialog() == DialogResult.OK)
                        {
                            AddSerialClientStation(stat2);
                            stationGrid.Selection.ResetSelection(true);
                            stationGrid.Selection.SelectRow(row, true);
                        }
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        void stationGrid_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            SourceGrid.Grid stationGrid    = (SourceGrid.Grid)sender;
            int []          rows           = stationGrid.Selection.GetSelectionRegion().GetRowsIndex();
            IModbusStation  stat           = (IModbusStation)stationGrid[rows[0], stationGridColName].Tag;
            string          oldname        = stat.Name;
            List <string>   forbiddenNames = new List <string>();

            for (int i = 1; i < stationGrid.RowsCount; i++)
            {
                if (i != rows[0])
                {
                    forbiddenNames.Add(stationGrid[i, stationGridColName].DisplayText);
                }
            }
            if (stat is ModbusTCPClientStation)
            {
                ModifyTCPClientStationForm mtc = new ModifyTCPClientStationForm((ModbusTCPClientStation)stat, forbiddenNames);
                if (mtc.ShowDialog() == DialogResult.OK)
                {
                    stationGrid[rows[0], stationGridColName].Value   = (stat as ModbusTCPClientStation).Name;
                    stationGrid[rows[0], stationGridColActive].Value = stat.StationActive;
                    stationGrid[rows[0], stationGridColAddr].Value   = "MODBUS/TCP, " + (stat as ModbusTCPClientStation).IPAddress;
                    stationGrid[rows[0], stationGridColPara].Value   = "TCPport = " + (stat as ModbusTCPClientStation).TCPPort;
                    stationGrid.Invalidate();
                }
                else
                {
                    return;
                }
            }
            if (stat is ModbusSerialClientStation)
            {
                ModifySerialClientStationForm msc = new ModifySerialClientStationForm((ModbusSerialClientStation)stat, forbiddenNames);
                if (msc.ShowDialog() == DialogResult.OK)
                {
                    stationGrid[rows[0], stationGridColName].Value   = (stat as ModbusSerialClientStation).Name;
                    stationGrid[rows[0], stationGridColActive].Value = stat.StationActive;
                    stationGrid[rows[0], stationGridColAddr].Value   =
                        "MODBUS/" + (stat as ModbusSerialClientStation).SerialType.ToString() + ", "
                        + (stat as ModbusSerialClientStation).ComPort;
                    stationGrid[rows[0], stationGridColPara].Value =
                        (stat as ModbusSerialClientStation).BaudRate.ToString() + ","
                        + (stat as ModbusSerialClientStation).DataBits.ToString() + ","
                        + (stat as ModbusSerialClientStation).Parity.ToString() + ","
                        + (stat as ModbusSerialClientStation).StopBits.ToString();
                    stationGrid.Invalidate();
                }
                else
                {
                    return;
                }
            }
            if (oldname != stat.Name)
            {
                for (int i = 1; i < grid.RowsCount; i++)
                {
                    if (grid[i, gridColStation].DisplayText == oldname)
                    {
                        (grid[i, gridColName].Tag as ModbusChannelImp).ModbusStation = stat.Name;
                        grid[i, gridColStation].Value = stat.Name;
                        grid.Invalidate();
                    }
                }
            }
        }