public CAPI_Session() { CAPI_Interface.Register(); ListenState = new C_ListenState(); T_Receiver = Processes.Manager.StartProcess(new System.Threading.ThreadStart(Receiver)); }
/// <summary> /// Main thread that handles protocol machines /// </summary> private void Receiver() { T_ReceiverWork = true; TStateM callSM = TStateM.SM_no; C_ListenState.Listen_Events Listen_LastEv; CAPI_Wrapper.comsub lastFrameCmd; CAPI.CAPI_Message CAPImsg = new CAPI.CAPI_Message(); C_PLCIState port; while (T_ReceiverWork) { Listen_LastEv = C_ListenState.Listen_Events.Listen_NONE; while (true) { if (!T_ReceiverWork) { return; } CAPI_Interface.Get_msg(ref CAPImsg, out lastFrameCmd, out info); if (lastFrameCmd == CAPI_Interface.comsub.NO_ONE) { Processes.Timer.Wait(Processes.Timer.TInOneSecond / 20); } else { break; } } ; port = null; switch (lastFrameCmd) { case CAPI_Interface.comsub.LISTEN_CONF: callSM = TStateM.SM_listen; if (info == 0) { if (ListenState.start_listen == false) { Listen_LastEv = C_ListenState.Listen_Events.LISTEN_CONF_INFO_0_CIP_0; } else { Listen_LastEv = C_ListenState.Listen_Events.LISTEN_CONF_INFO_O_CIP_N0; } } else { Listen_LastEv = C_ListenState.Listen_Events.LISTEN_CONF_INFO_N0; } callSM = TStateM.SM_listen; break; case CAPI_Interface.comsub.ALERT_CONF: // nie uwzglêdniony w SM callSM = TStateM.SM_no; break; case CAPI_Interface.comsub.CONNECT_IND: port = Connections.FindWaitingFConnIndPort(); callSM = TStateM.SM_plci; break; case CAPI_Interface.comsub.CONNECT_CONF: port = Connections.FindPortNum(CAPImsg.number); callSM = TStateM.SM_plci; break; case CAPI_Interface.comsub.CONNECT_ACTIVE_IND: case CAPI_Interface.comsub.CONNECT_B3_IND: case CAPI_Interface.comsub.CONNECT_B3_ACTIVE_IND: case CAPI_Interface.comsub.CONNECT_B3_CONF: case CAPI_Interface.comsub.DATA_B3_IND: case CAPI_Interface.comsub.DATA_B3_CONF: case CAPI_Interface.comsub.DISCONNECT_B3_IND: case CAPI_Interface.comsub.DISCONNECT_B3_CONF: case CAPI_Interface.comsub.RESET_B3_CONF://MPNI event nie obs³ugiwany przez SM case CAPI_Interface.comsub.RESET_B3_IND: case CAPI_Interface.comsub.DISCONNECT_IND: case CAPI_Interface.comsub.DISCONNECT_CONF: case CAPI_Interface.comsub.INFO_IND: case CAPI_Interface.comsub.INFO_CONF: //MPNI event nie obs³ugiwany przez SM port = Connections.FindPLCIPort((byte)CAPImsg.plci); callSM = TStateM.SM_plci; break; default: Manager.Assert(false); break; } //do switch (CAPI...... switch (callSM) { case TStateM.SM_no: break; case TStateM.SM_listen: ListenState.SM_Listen(Listen_LastEv); break; case TStateM.SM_plci: port.SM_PLCI(CAPImsg, lastFrameCmd); break; } } }
/// <summary> /// Stops the protocol machine and unregisters application from CAPI /// </summary> public void Close() { T_ReceiverWork = false; T_Receiver.Join(10000); CAPI_Interface.Unregister(); }