Example #1
0
 public void setIOServer(IOServer io)
 {
     ios = io;
     ios.add(m_left);
     ios.add(m_right);
     ios.add(m_speed);
 }
Example #2
0
        private void verbinden_Click(object sender, EventArgs e)
        {
            if (ios != null && ios.isConnected())
            {
                ios.disconnect();
                verbinden.Text = "Verbinden";
                status.Text    = "Verbindung getrennt";
                this.statusStrip1.BackColor = Color.White;
                verbinden.BackColor         = Color.PaleGreen;
                modell.stop();
                ghost(true);
            }
            else
            {
                if (modbus.Checked)
                {
                    verbinden.Enabled           = false;
                    this.statusStrip1.BackColor = Color.Yellow;

                    status.Text = "Try to connect to Modbus Server!";
                    this.Update();
                    ios = new IOServerModbus(ipadr.Text, Int32.Parse(ipPort.Text));
                    ios.setListener(this);

                    bool res = ios.connect();
                    verbinden.Enabled = true;
                    if (res)
                    {
                        ios.add(plc_h1);
                        ios.add(plc_h2);
                        ios.add(plc_h3);
                        ios.add(plc_h4);
                        ios.setBoolean(4, 0, s0Pressed);
                        ios.setBoolean(4, 3, handSteuerung);
                        modell.setIOServer(ios);
                        verbinden.Text = "Trennen";
                        status.Text    = "Verbunden!";
                        this.statusStrip1.BackColor = Color.Green;
                        verbinden.BackColor         = Color.Red;
                        ghost(false);
                        modell.cont();
                        tabControl1.SelectedIndex = 0;
                    }
                    else
                    {
                        status.Text = "Verbindung fehlgeschlagen!";
                        this.statusStrip1.BackColor = Color.Red;
                    }
                }
                else if (codesys.Checked)
                {
                    verbinden.Enabled           = false;
                    this.statusStrip1.BackColor = Color.Yellow;

                    status.Text = "Try to connect to CoDeSys DDE Server!";
                    this.Update();
                    ios = new IOServerDDECodeSys(new DdeClient("CODESYS", codesysPfad.Text));
                    ios.setListener(this);

                    bool res = ios.connect();
                    verbinden.Enabled = true;
                    if (res)
                    {
                        ios.add(plc_h1);
                        ios.add(plc_h2);
                        ios.add(plc_h3);
                        ios.add(plc_h4);
                        ios.setBoolean(4, 2, s0Pressed);
                        ios.setBoolean(4, 5, handSteuerung);

                        modell.setIOServer(ios);
                        verbinden.Text = "Trennen";
                        status.Text    = "Verbunden!";
                        this.statusStrip1.BackColor = Color.Green;
                        verbinden.BackColor         = Color.Red;
                        ghost(false);
                        //modell.cont();
                        tabControl1.SelectedIndex = 0;
                    }
                    else
                    {
                        status.Text = "Verbindung fehlgeschlagen!";
                        this.statusStrip1.BackColor = Color.Red;
                    }
                }
                else if (fluidsim.Checked)
                {
                    verbinden.Enabled           = false;
                    this.statusStrip1.BackColor = Color.Yellow;

                    status.Text = "Try to connect to FluidSim DDE Server!";
                    this.Update();
                    ios = new IOServerDDEFluidSim(new DdeClient(fluidsimServer.Text, fluidsimTopic.Text), fludsimOutMarke.Text, fluidsimInMarke.Text);
                    ios.setListener(this);
                    bool res = ios.connect();
                    verbinden.Enabled = true;
                    if (res)
                    {
                        ios.add(plc_h1);
                        ios.add(plc_h2);
                        ios.add(plc_h3);
                        ios.add(plc_h4);
                        ios.setBoolean(4, 2, s0Pressed);
                        ios.setBoolean(4, 5, handSteuerung);

                        modell.setIOServer(ios);
                        verbinden.Text = "Trennen";
                        status.Text    = "Verbunden!";
                        this.statusStrip1.BackColor = Color.Green;

                        verbinden.BackColor = Color.Red;
                        ghost(false);
                        //modell.cont();
                        tabControl1.SelectedIndex = 0;
                    }
                    else
                    {
                        status.Text = "Verbindung fehlgeschlagen!";
                        this.statusStrip1.BackColor = Color.Red;
                    }
                }
                else
                {
                    /*
                     * status.Text = "Try to connect to S7 via Profinet";
                     * verbinden.Enabled = false;
                     * this.statusStrip1.BackColor = Color.Yellow;
                     *
                     * axS7TCP1.CP_IP = ipadr.Text;
                     * axS7TCP1.Tzeit = 80000;
                     * axS7TCP1.TsapE = "1.0";
                     * if (comboBox1.Text == "S7-300")
                     * {
                     *  axS7TCP1.TsapF = "3.2";
                     * }
                     * else
                     * {
                     *  axS7TCP1.TsapF = "3.3";
                     * }
                     * status.Text = "verbinde...";
                     * ios = new IOServerS7TCP(axS7TCP1);
                     * ios.setListener(this);
                     * ios.add(plc_h1);
                     * ios.add(plc_h2);
                     * ios.add(plc_h3);
                     * ios.add(plc_h4);
                     * ios.setBoolean(4, 2, s0Pressed);
                     * ios.setBoolean(4, 5, handSteuerung);
                     *
                     * res = ios.connect();
                     * verbinden.Enabled = true;
                     * if (res)
                     * {
                     *  modell.setIOServer(ios);
                     *  verbinden.Text = "Trennen";
                     *  status.Text = "Verbunden!";
                     *  this.statusStrip1.BackColor = Color.Green;
                     *
                     *  verbinden.BackColor = Color.Red;
                     *  modell.cont();
                     *  ghost(false);
                     *  tabControl1.SelectedIndex = 0;
                     * }
                     * else
                     * {
                     *  status.Text = "Verbindung fehlgeschlagen!";
                     *  verbinden.BackColor = Color.PaleGreen;
                     *  this.statusStrip1.BackColor = Color.Red;
                     *
                     * }
                     */
                }
            }
        }