Ejemplo n.º 1
0
        public bool UpdateFW(string path)
        {
            plc.Cmd("program enable");

            Console.Out.WriteLine("Programming enabled.");
            TcpClient downloader = new TcpClient();

            downloader.Connect(m_ip.Address, 61163);
            Socket sock = downloader.Client;

            byte[] data = new byte[16];
            sock.Receive(data);
            string str = ASCIIEncoding.ASCII.GetString(data);

            if (!str.StartsWith("Access granted"))
            {
                Console.Error.WriteLine("Access not granted");
                downloader.Close();
                return(false);
            }

            Console.Out.Write("Sending firmware ");
            FileStream fs = new FileStream(path, FileMode.Open);

            data = new byte[1024];
            int r = 0;

            while ((r = fs.Read(data, 0, data.Length)) != 0)
            {
                downloader.Client.Send(data, r, 0);
                Console.Out.Write(".");
            }
            data = new byte[22];
            sock.Receive(data);
            str = ASCIIEncoding.ASCII.GetString(data);
            if (!str.StartsWith("Firmware programmed"))
            {
                Console.Error.WriteLine("Could not program firmware.");
                downloader.Close();
                return(false);
            }
            Console.Out.WriteLine("\nProgrammed. Rebooting.");
            Cmd("reboot");
            return(true);
        }
Ejemplo n.º 2
0
        private void infoP_Enter(object sender, EventArgs e)
        {
            PLC p = SelectedPLC;

            if (p == null)
            {
                return;
            }
            Response resp = p.Cmd("info");

            infoL.Text = resp.String;
        }
Ejemplo n.º 3
0
        public void CmdTest()
        {
            IPEndPoint ip       = null;                  // TODO: Initialize to an appropriate value
            string     password = string.Empty;          // TODO: Initialize to an appropriate value
            PLC        target   = new PLC(ip, password); // TODO: Initialize to an appropriate value

            byte[]   buf      = null;                    // TODO: Initialize to an appropriate value
            Response expected = null;                    // TODO: Initialize to an appropriate value
            Response actual;

            actual = target.Cmd(buf);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 4
0
        private void cmdTB_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                PLC p = SelectedPLC;
                if (p == null)
                {
                    return;
                }

                if (cmdAsyncCB.Checked)
                {
                    p.BeginCmd(ASCIIEncoding.ASCII.GetBytes(cmdTB.Text + "\r"), new AsyncCallback(cmdAsyncHandler), p);
                }
                else
                {
                    Response resp = p.Cmd(cmdTB.Text + "\r");
                    // Let's convert UNIX line endings to Windows.
                    string respStr = resp.String.Replace("\n", "\r\n");
                    // And append a new line, just in case.
                    respStr += "\r\n";
                    cmdRespTB.AppendText(respStr);
                }
                m_cmdHist.Add(cmdTB.Text);
                cmdTB.Text = "";
                m_cmdIdx   = 0;
            }
            else if (e.KeyCode == Keys.Up)
            {
                if (m_cmdIdx < m_cmdHist.Count)
                {
                    cmdTB.Text = m_cmdHist[m_cmdHist.Count - ++m_cmdIdx];
                }
            }
            else if (e.KeyCode == Keys.Down)
            {
                if (m_cmdIdx > 1)
                {
                    cmdTB.Text = m_cmdHist[m_cmdHist.Count - --m_cmdIdx];
                }
                else
                {
                    m_cmdIdx   = 0;
                    cmdTB.Text = "";
                }
            }
        }
Ejemplo n.º 5
0
 public void CmdTest()
 {
     IPEndPoint ip = null; // TODO: Initialize to an appropriate value
     string password = string.Empty; // TODO: Initialize to an appropriate value
     PLC target = new PLC(ip, password); // TODO: Initialize to an appropriate value
     byte[] buf = null; // TODO: Initialize to an appropriate value
     Response expected = null; // TODO: Initialize to an appropriate value
     Response actual;
     actual = target.Cmd(buf);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }