コード例 #1
0
ファイル: Plc.cs プロジェクト: somapatrik/S7-Dimat
        public Plc(string Adrress, S7Type Plc)
        {
            PlcType = Plc;
            switch (Plc)
            {
            case S7Type.S7300:
                SetPlc(Adrress, 0, 2);
                break;

            case S7Type.S7400:
            case S7Type.S71200:
            case S7Type.S71500:
                SetPlc(Adrress, 0, 0);
                break;
            }
        }
コード例 #2
0
ファイル: NewPLC.cs プロジェクト: somapatrik/S7-Dimat
        private Boolean Test()
        {
            Boolean res    = false;
            Ping    pinger = null;

            try
            {
                if (!string.IsNullOrEmpty(txt_ip.Text))
                {
                    pinger = new Ping();
                    PingReply reply = pinger.Send(txt_ip.Text, 3000);
                    if (reply.Status == IPStatus.Success)
                    {
                        string msg = "PLC is reachable";

                        S7Type type = S7Type.S7300;

                        switch (combo_typ.SelectedValue)
                        {
                        case "s7-300":
                            type = S7Type.S7300;
                            break;

                        case "s7-400":
                            type = S7Type.S7400;
                            break;

                        case "s7-1200":
                            type = S7Type.S71200;
                            break;

                        case "s7-1500":
                            type = S7Type.S71500;
                            break;
                        }

                        Plc plc = null;

                        try
                        {
                            plc = new Plc(txt_ip.Text, type);
                            plc.Connect();
                            if (plc.Connected)
                            {
                                msg += "\r\nPLC connection is ok";
                                res  = true;
                            }
                            else
                            {
                                msg += "\r\nUnable to connect to PLC";
                                MessageBox.Show(msg, "PLC connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                res = false;
                            }
                        }
                        catch (Exception ex0)
                        {
                            msg += "\r\nPLC connection exception\r\n " + ex0.Message;
                            MessageBox.Show(msg, "PLC connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            res = false;
                        }
                        finally
                        {
                            plc.Disconnect();
                            plc = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show("PLC unreachable", "PLC connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        res = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "PLC connection exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                res = false;
            }
            finally
            {
                if (pinger != null)
                {
                    pinger.Dispose();
                }
            }

            return(res);
        }