Esempio n. 1
0
        public void CmdAsyncTest()
        {
            IAsyncResult ar = plc.BeginCmd(ASCIIEncoding.ASCII.GetBytes("help"), null, null);

            ar.AsyncWaitHandle.WaitOne();
            Response resp = plc.EndCmd(ar);
            string   str  = resp.String;

            Assert.AreEqual(true, resp.String.StartsWith("Available commands:"));
        }
Esempio n. 2
0
        private void runB_Click(object sender, EventArgs e)
        {
            Object i = plcLB.SelectedItem;

            if (i == null)
            {
                return;
            }
            PLC plc = (PLC)i;

            plc.BeginCmd(ASCIIEncoding.ASCII.GetBytes("run"), new AsyncCallback(ResponseHandler), plc);
        }
Esempio n. 3
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 = "";
                }
            }
        }