/// <summary> /// Executes when WriteToComPortDelegate1 completes. /// </summary> /// <param name="ar"> the value returned by the delegate's BeginInvoke method </param> internal void WriteCompleted(IAsyncResult ar) { WriteToComPortDelegate deleg = null; string msg = null; bool success = false; // Extract the value returned by BeginInvoke (optional). msg = System.Convert.ToString(ar.AsyncState); // Get the value returned by the delegate. deleg = (( WriteToComPortDelegate )((( AsyncResult )(ar)).AsyncDelegate)); success = deleg.EndInvoke(ar); if (success) { if (null != UserInterfaceData) { UserInterfaceData("UpdateStatusLabel", "", Color.Black); } } // Add any actions that need to be performed after a write to the COM port completes. // This example displays the value passed to the BeginInvoke method // and the value returned by EndInvoke. Console.WriteLine("Write operation began: " + msg); Console.WriteLine("Write operation succeeded: " + success); }
/// <summary> /// Method that is called after write to COM port is finished. /// </summary> /// <param name="ar"></param> public void WriteCompleted(IAsyncResult ar) { WriteToComPortDelegate deleg = null; string msg = null; bool success = false; //Extract the value returned by BeginInvoke (optional) msg = ar.AsyncState.ToString(); //Get the value returned by the delegate. deleg = ((WriteToComPortDelegate)(((AsyncResult)(ar)).AsyncDelegate)); msg = ar.AsyncState.ToString(); success = deleg.EndInvoke(ar); if (UserInterfaceData != null) { if (success) { UserInterfaceData(ComPortEvent.ReportSerialSuccess, msg); } else { UserInterfaceData(ComPortEvent.ReportSerialError, "Write operation started " + msg + " did not return success"); } } }
public void WriteDataToGate(string textToWrite) { writeToGateDelegate = new WriteToComPortDelegate(_WriteToGate); IAsyncResult iar = writeToGateDelegate.BeginInvoke(textToWrite, new AsyncCallback(_WriteToGateCompleted), DateTime.Now.ToString()); }