Beispiel #1
0
        /// <summary>
        /// <p>
        /// Sends <paramref name="buf"/> byte array command to the PLC asynchronously.
        /// </p>
        /// <p>
        /// This method returns immediately. When the response is received <paramref name="cb"/>
        /// will be invoked.
        /// </p>
        /// </summary>
        ///
        /// <example>
        /// <code>
        ///
        ///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");
        ///    }
        ///}
        ///
        ///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);
        ///}
        ///
        /// </code>
        /// </example>
        /// <param name="buf">
        /// </param>/// <param name="cb">Callback to be called when the operation is complete.</param>
        /// <param name="state">Any state to be passed to <paramref name="cb"/> when invoked, it's a good idea to use the PLC instance as state.</param>
        /// <returns></returns>
        public IAsyncResult BeginCmd(byte[] buf, AsyncCallback cb, object state)
        {
            log.Debug("BeginCmd");
            CmdByteDelegate m_cmdFunc = Cmd;

            return(m_cmdFunc.BeginInvoke(buf, cb, state));
        }
Beispiel #2
0
        /// <summary>
        /// Ends a BeginCmd asynchronous call.
        /// </summary>
        /// <param name="ar"></param>
        /// <returns>Response of the sent command</returns>
        /// <seealso cref="BeginCmd"/>
        public Response EndCmd(IAsyncResult ar)
        {
            log.Debug("EndCmd");
            AsyncResult     a = (AsyncResult)ar;
            CmdByteDelegate d = (CmdByteDelegate)a.AsyncDelegate;

            return(d.EndInvoke(ar));
        }