private async void AutoReply(PrimaryMessageWrapper pmw) { try { // Get the Stream switch (pmw.Message.S) { case 1: { switch (pmw.Message.F) { case 1: await pmw.ReplyAsync(new SecsMessage(1, 2, "I am here", Item.L())); return; case 13: await pmw.ReplyAsync(new SecsMessage(1, 14, "Establish Communications Request Acknowledge", Item.L())); return; } break; } case 14: { if (pmw.Message.F == 1) { await pmw.ReplyAsync(txtReplySeconary.Text.ToSecsMessage()); return; } break; } } await pmw.ReplyAsync(new SecsMessage(pmw.Message.S, (byte)((int)pmw.Message.F + 1), "SuperResponse", Item.B(0))); } catch (Exception ee) { Invoke((MethodInvoker) delegate { richTextBox1.SelectionColor = Color.Red; richTextBox1.AppendText($"Exception AutoResponse\n{ee}\n"); }); } }
private async void PrimaryMsgHandler(object sender, PrimaryMessageWrapper e) { try { await e.ReplyAsync(SecsMessages[e.Message.S, (byte)(e.Message.F + 1)].FirstOrDefault()); if (_eventHandlers.TryGetValue(e.Message.GetKey(), out var handler)) { Parallel.ForEach(handler.GetInvocationList().Cast <Action <SecsMessage> >(), h => h(e.Message)); } } catch (Exception ex) { Console.WriteLine("Handle Primary SECS message Error", ex); } }