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 ResponseHandler(IAsyncResult ar)
        {
            PLC      plc  = (PLC)ar.AsyncState;
            Response resp = plc.EndCmd(ar);

            if (resp.String.Contains("OK!"))
            {
                MessageBox.Show("Run command succesfull");
            }
            else
            {
                MessageBox.Show("Run command failed");
            }
        }
Esempio n. 3
0
        private void cmdAsyncHandler(IAsyncResult ar)
        {
            if (InvokeRequired)
            {
                // We'll update GUI, so we need to pass the async call back processing
                // to the GUI thread.
                BeginInvoke(new AsyncCallback(cmdAsyncHandler), new object[] { ar });
                return;
            }
            PLC      p    = (PLC)ar.AsyncState;
            Response resp = p.EndCmd(ar);
            // 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);
        }