Beispiel #1
0
        public TSessionError DataReq(object portID, ISesDBuffer tXmsg)
        {
            if (!CAPI_Interface.IsRegistered)
            {
                return(TSessionError.Session_NotRegistered);
            }
            if (portID == null)
            {
                return(TSessionError.NotConnected);
            }
            C_PLCIState port = (C_PLCIState)portID;

            if (!port.IsConnected)
            {
                return(TSessionError.NotConnected);
            }
            if (port.TxDataSet(tXmsg))
            {
                port.SM_PLCI(CAPI_Wrapper.comsub.DATA_B3_REQ);
            }
            else
            {
                return(TSessionError.NotConnected);
            }
            return(TSessionError.Success);
        }
Beispiel #2
0
        /// <summary>
        /// Waits for incomming data
        /// </summary>
        /// <param name="portID">Class that represents the logical connection</param>
        /// <param name="rXMsg">Buffer for received data</param>
        /// <param name="timeout">Desired time to wait</param>
        /// <returns>Success if data was received, otherwise appropriate error code</returns>
        public TSessionError DataInd
            (object portID, out ISesDBuffer rXMsg, int timeout)
        {
            rXMsg = null;
            if (!CAPI_Interface.IsRegistered)
            {
                return(TSessionError.Session_NotRegistered);
            }
            if (portID == null)
            {
                return(TSessionError.NotConnected);
            }
            ;
            C_PLCIState port   = (C_PLCIState)portID;
            bool        isData = port.RxDataGet(out rXMsg, timeout);

            if (isData)
            {
                return(TSessionError.Success);
            }
            else
            {
                if (!port.IsConnected)
                {
                    return(TSessionError.NotConnected);
                }
                else
                {
                    return(TSessionError.DataInd_NoDat);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Used by a user to return an empty envelope to the common pool. It also resets the message content.
        /// </summary>
        public void ReturnEmptyEnvelope()
        {
            ISesDBuffer var = (ISesDBuffer)this;

            ResetContent();
            this.pool.ReturnEmptyISesDBuffer(ref var);
        }
Beispiel #4
0
        /// <summary>
        /// Returns an empty envelope to the common pool.
        /// </summary>
        /// <param name="mess">Envelope to return</param>
        public void ReturnEmptyISesDBuffer(ref ISesDBuffer mess)
        {
            IEnvelope ieMess = mess;

            mess = null;
            myPool.ReturnEmptyEnvelope(ref ieMess);
        }
Beispiel #5
0
 /// <summary>
 /// Retrieves the data from CAPI message
 /// </summary>
 /// <param name="rxMess">Buffer to get data to</param>
 /// <param name="timeout">Desired tim to wait</param>
 /// <returns>True if data received, otherwise false</returns>
 internal override bool RxDataGet(out ISesDBuffer rxMess, int timeout)
 {
     lock (this)
     {
         return(base.RxDataGet(out rxMess, timeout));
     }
 }
Beispiel #6
0
 /// <summary>
 /// Adds data to queue
 /// </summary>
 /// <param name="txMess">Buffer with data to send</param>
 /// <returns>True if success, otherwise false</returns>
 internal override bool TxDataSet(ISesDBuffer txMess)
 {
     lock (this)
     {
         return(base.TxDataSet(txMess));
     }
 }
Beispiel #7
0
            /// <summary>
            /// Adds data to the send data queue
            /// </summary>
            /// <param name="callingMonitor"></param>
            /// <param name="txMess">Data buffer to send</param>
            /// <returns>True if success, otherwise false</returns>
            internal bool TxDataSet(object callingMonitor, ISesDBuffer txMess)
            {
                bool res = true;

                while (buff_TxMess != null)
                {
                    res = buff_TxMessFree.Wait(callingMonitor, TxDateSendTO);
                }
                res = res & isConnected;
                if (res)
                {
                    buff_TxMess = txMess;
                }
                else
                {
                    txMess.ReturnEmptyEnvelope();
                }
                return(res);
            }
Beispiel #8
0
        /// <summary>
        /// Retrieves data from the data queue
        /// </summary>
        /// <param name="rxMess">Buffer for the data</param>
        /// <param name="timeout">Desired time to wait</param>
        /// <returns></returns>
        internal virtual bool RxDataGet(out ISesDBuffer rxMess, int timeout)
        {
            IEnvelope mess = null;
            bool      ret  = true;

            if ((buff_RxMess.Count == 0) & !IsConnected)
            {
                ret = false;
            }
            else
            {
                buff_RxMess.WaitMsg(this, out mess, timeout);
            }
            if (mess == null)
            {
                ret = false;
            }
            rxMess = (ISesDBuffer)mess;
            return(ret);
        }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 internal void TxDataRelease()
 {
     buff_TxMess.ReturnEmptyEnvelope();
     buff_TxMess = null;
     buff_TxMessFree.Notify();
 }
Beispiel #10
0
        /// <summary>
        /// Logical connection protocol machine.
        /// Handles all events concerning logical connection states.
        /// </summary>
        /// <param name="CAPImsg">CAPI message to operate on</param>
        /// <param name="Protocol_Event">Last protocol event that occured during application's activity</param>
        protected void SM_NCCI(ref CAPI.CAPI_Message CAPImsg, ref CAPI_Wrapper.comsub Protocol_Event)
        {
            //zmienna zwi¹zana z obslug¹ odrzuconego DISCONNECT_B3_REQ
            NCCI_States previousState = NCCI_States.N_ACT;

            switch (NCCIPCurrState)
            {
            case NCCI_States.N0:
                #region N0
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.CONNECT_B3_REQ:
                    #region CONNECT_B3_REQ
                    Manager.Assert(CAPI_Interface.Send_msg_connect_b3_req(ref CAPImsg, 1, PLCI, out info));
                    NCCIPCurrState = NCCI_States.N01;
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                    #endregion
                case CAPI_Wrapper.comsub.CONNECT_B3_IND:
                    #region CONNECT_B3_IND
                    NCCI   = CAPImsg.ncci;
                    accept = true;
                    //MPNI tu trzeba zrobic sprawdzenie czy oczekujemy na konkretny protokol
                    Disconnect_B3_Pending = false;
                    NCCIPCurrState        = NCCI_States.N1;
                    Protocol_Event        = CAPI_Wrapper.comsub.CONNECT_B3_RESP;
                    break;

                    #endregion
                default:
                    Manager.Assert(false);
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N01:
                #region N01
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.CONNECT_B3_CONF:
                    if (info != 0)
                    {
                        NCCIPCurrState = NCCI_States.N0;
                    }
                    else
                    {
                        NCCIPCurrState = NCCI_States.N2;
                        NCCI           = CAPImsg.ncci;
                    }
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                default:
                    Manager.Assert(false);
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N1:
                #region N1
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.CONNECT_B3_RESP:
                    #region CONNECT_B3_RESP
                    Manager.Assert(
                        CAPI_Interface.Send_msg_connect_b3_resp(
                            ref CAPImsg, 1, PLCI, NCCI, accept, out info));
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    if (accept)
                    {
                        NCCIPCurrState = NCCI_States.N2;
                    }
                    else
                    {
                        NCCIPCurrState = NCCI_States.N4;
                    }
                    break;

                    #endregion
                    #region N1_DISCONNECT
                // wspolne dla N-1, N-2, N-3, N-ACT
                case CAPI_Wrapper.comsub.DISCONNECT_B3_REQ:
                    Manager.Assert(false);
                    break;

                case CAPI_Wrapper.comsub.DISCONNECT_B3_IND:
                    NCCIPCurrState = NCCI_States.N5;
                    Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_B3_RESP;
                    break;

                    #endregion
                default:
                    Manager.Assert(false);
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N2:
                #region N2
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.CONNECT_B3_ACTIVE_IND:
                    Manager.Assert(CAPI_Interface.Send_msg_connect_b3_active_resp(ref CAPImsg, 1, PLCI, NCCI, out info));
                    NCCIPCurrState = NCCI_States.N_ACT;
                    buff_TxMess.redyToSend();
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    IsConnectedCon.Notify();
                    break;

                // wspolne dla N-1, N-2, N-3, N-ACT
                case CAPI_Wrapper.comsub.DISCONNECT_B3_REQ:
                    Manager.Assert(false);
                    break;

                case CAPI_Wrapper.comsub.DISCONNECT_B3_IND:
                    NCCIPCurrState = NCCI_States.N5;
                    Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_B3_RESP;
                    break;

                default:
                    Manager.Assert(false);
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N3:
                #region N3
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.RESET_B3_IND:
                    //MPNI - TU TRZEBA WYS£AÆ res
                    NCCIPCurrState = NCCI_States.N_ACT;
                    buff_TxMess.redyToSend();
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    IsConnectedCon.Notify();
                    break;

                    #region N3_DISCONNECT
                // wspolne dla N-1, N-2, N-3, N-ACT
                case CAPI_Wrapper.comsub.DISCONNECT_B3_REQ:
                    Manager.Assert(false);
                    break;

                case CAPI_Wrapper.comsub.DISCONNECT_B3_IND:
                    NCCIPCurrState = NCCI_States.N5;
                    Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_B3_RESP;
                    break;

                    #endregion
                default:
                    Manager.Assert(false);
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N4:
                #region N4
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.DISCONNECT_B3_CONF:
                    if (info != 0)
                    {
                        Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                        NCCIPCurrState = previousState;
                    }
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                case CAPI_Wrapper.comsub.DISCONNECT_B3_IND:
                    NCCIPCurrState = NCCI_States.N5;
                    Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_B3_RESP;
                    break;

                default:
                    Manager.Assert(false);
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N5:
                #region N5
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.DISCONNECT_B3_RESP:
                    Manager.Assert
                    (
                        CAPI_Interface.Send_msg_disconnect_b3_resp
                            (ref CAPImsg, 1, PLCI, NCCI, out info)
                    );
                    NCCI           = 0;
                    NCCIPCurrState = NCCI_States.N0;
                    if (Disconnect_B3_Pending)
                    {
                        Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_REQ;
                    }
                    else
                    {
                        Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    }
                    break;

                default:
                    Manager.Assert(false);
                    break;
                }
                ;
                break;

                #endregion
            case NCCI_States.N_ACT:
                #region N_ACT
                switch (Protocol_Event)
                {
                case CAPI_Wrapper.comsub.DATA_B3_REQ:
                    Manager.Assert
                    (
                        CAPI_Interface.Send_msg_data_b3_req
                        (
                            ref CAPImsg, 1, PLCI, NCCI, buff_TxMess.TxDataGet, out info
                        )
                    );
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                case CAPI_Wrapper.comsub.DATA_B3_CONF:
                    Manager.Assert(info == 0);
                    buff_TxMess.TxDataRelease();
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                case CAPI_Wrapper.comsub.DATA_B3_RESP:
                    Manager.Assert
                    (
                        CAPI_Interface.Send_msg_data_b3_resp(ref CAPImsg, 1, PLCI, NCCI, out info)
                    );
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                case CAPI_Wrapper.comsub.DATA_B3_IND:
                    ISesDBuffer newBuffor = myDBufferPool.GetEmptyISesDBuffer();
                    CAPImsg.Get_Data(newBuffor);
                    IEnvelope newIEBuffor = (IEnvelope)newBuffor;
                    newBuffor = null;
                    buff_RxMess.SendMsg(ref newIEBuffor);
                    Protocol_Event = CAPI_Wrapper.comsub.DATA_B3_RESP;
                    break;

                case CAPI_Wrapper.comsub.RESET_B3_REQ:
                    //MPNI sprawdziæ co robi Reset - w stanie N3 nie s¹ przyjmowane dane
                    //MPNI zaimplementowac funkcje reset
                    Manager.Assert(CAPI_Interface.Send_msg_reset_b3_req(ref CAPImsg, 1, PLCI, NCCI, out info)
                                   );
                    NCCIPCurrState = NCCI_States.N3;
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                case CAPI_Wrapper.comsub.RESET_B3_IND:
                    //mpni - TU TRZEBA WYS£AÆ res
                    NCCIPCurrState = NCCI_States.N_ACT;
                    Protocol_Event = CAPI_Wrapper.comsub.NO_ONE;
                    break;

                    #region DISCONNECT
                // wspolne dla N-1, N-2, N-3, N-ACT
                case CAPI_Wrapper.comsub.DISCONNECT_B3_REQ:
                    Manager.Assert
                        (CAPI_Interface.Send_msg_disconnect_b3_req(ref CAPImsg, 1, PLCI, NCCI, out info));
                    Disconnect_B3_Pending = true;
                    previousState         = NCCI_States.N_ACT;
                    NCCIPCurrState        = NCCI_States.N4;
                    Protocol_Event        = CAPI_Wrapper.comsub.NO_ONE;
                    buff_TxMess.TxDataClear();
                    buff_RxMess.Close();
                    break;

                case CAPI_Wrapper.comsub.DISCONNECT_B3_IND:
                    NCCIPCurrState = NCCI_States.N5;
                    Protocol_Event = CAPI_Wrapper.comsub.DISCONNECT_B3_RESP;
                    buff_TxMess.TxDataClear();
                    buff_RxMess.Close();
                    break;

                    #endregion
                default:
                    Manager.Assert(false);
                    break;
                }
                ; //switch
                break;
                #endregion
            }
            ; //switch (NCCIPCurrState)
        } //public void SM_NCCI
Beispiel #11
0
 /// <summary>
 /// Adds data to the send data queue
 /// </summary>
 /// <param name="txMess">Data buffer to send</param>
 /// <returns>True if success, otherwise false</returns>
 internal virtual bool TxDataSet(ISesDBuffer txMess)
 {
     return(buff_TxMess.TxDataSet(this, txMess) & IsConnected);
 }