コード例 #1
0
ファイル: Form1.cs プロジェクト: hamwich3/WinPLCChangeIP
        private void ChangeIP_Click(object sender, EventArgs e)
        {
            PingTimer.Stop();
            Ping      ping  = new Ping();
            PingReply reply = ping.Send(plcIPAddressBox.IPAddress, 1500);

            Console.WriteLine(reply.Status.ToString() + " " + plcIPAddressBox.IPAddress.ToString());
            if (reply.Status == IPStatus.Success)
            {
                DialogResult result = MessageBox.Show("Detected another device with this IP address. Use this address anyway?",
                                                      "IP Address in Use!", MessageBoxButtons.OKCancel);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            if (PLCGrid.SelectedRows.Count <= 0)
            {
                MessageBox.Show("Select PLC from List.", "Error!");
                return;
            }
            DetectedPLC plc = (DetectedPLC)DiscoverPLC.PLCbs.Current;

            if (plc == null)
            {
                MessageBox.Show("Null PLC Exception!", "Error!");
                return;
            }
            DiscoverPLC.changeIP(plc, plcIPAddressBox.IPAddress);
            FindPLCs();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: hamwich3/WinPLCChangeIP
        // Set row color
        private void PLCGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridViewRow  row  = PLCGrid.Rows[e.RowIndex];
            DataGridViewCell cell = row.Cells[e.ColumnIndex];
            DetectedPLC      plc  = (DetectedPLC)row.DataBoundItem;

            try
            {
                if (!plc.Connected)
                {
                    row.DefaultCellStyle.BackColor = Color.Red;
                    cell.ToolTipText = "PLC Disconnected!";
                }
                else if (plc.IP.ToString() != plc.InternalIP.ToString())
                {
                    row.DefaultCellStyle.BackColor          = Color.LightPink;
                    row.DefaultCellStyle.SelectionForeColor = Color.LightPink;
                    cell.ToolTipText = "Cycle PLC power to change IP Address!";
                }
                else
                {
                    cell.ToolTipText = null;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Row not bound to PLC!", "Error!");
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: hamwich3/WinPLCChangeIP
 void plcReconnected(DetectedPLC plc, bool newIP)
 {
     if (newIP)
     {
         plc.IP = plc.InternalIP;
     }
     DiscoverPLC.PLCbs.ResetBindings(false);
     PLCGrid.ClearSelection();
 }
コード例 #4
0
ファイル: Catch.cs プロジェクト: hamwich3/WinPLCChangeIP
        void catchPLC()
        {
            Thread c = new Thread(delegate()
            {
                while (!stopThread)
                {
                    try
                    {
                        DetectedPLC plc = DiscoverPLC.DiscoverNew();
                        if (plc != null)
                        {
                            DiscoverPLC.changeIP(plc, plcAddressBox.IPAddress);
                            DiscoverPLC.getPLCInfo(plc);
                            plc.Connected = false;
                            this.BeginInvoke(new Action(delegate()
                            {
                                DiscoverPLC.PLCbs.Add(plc);
                                label3.Visible = true;
                                label2.Visible = false;
                            }));
                            PLCFound = true;
                            sw.Reset();
                            stopThread = true;
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                        break;
                    }
                }
            });

            c.Start();
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: hamwich3/WinPLCChangeIP
 void plcDisconnected(DetectedPLC plc)
 {
     DiscoverPLC.PLCbs.ResetBindings(false);
     PLCGrid.ClearSelection();
 }