Exemple #1
0
        public E87RETURN_AM ChangeAccessMode(LoadPort lpObj, E87_AM newAccessMode)
        {
            E87RETURN_AM Return = E87RETURN_AM.SUCCESSFUL;

            if (lpObj.IsInTransfer)
            {
                Return = E87RETURN_AM.IN_TRANSFER;
            }
            if (lpObj.IsReserved == E87_RS.RESERVED)
            {
                Return = E87RETURN_AM.RESERVED;
            }
            if (newAccessMode == lpObj.AccessMode)
            {
                Return = E87RETURN_AM.IN_ACCESS_MODE_ALREADY;
            }

            if (Return == E87RETURN_AM.SUCCESSFUL || Return == E87RETURN_AM.IN_ACCESS_MODE_ALREADY)
            {
                lpObj.AccessMode = newAccessMode;
                //AccessModeFinishEvent?.Invoke(this, lpObj);
            }

            return(Return);
        }
Exemple #2
0
        //public event EventHandler<LoadPort> AccessModeFinishEvent;
        //public event EventHandler<LoadPort> ReservedFinishEvent;
        //public event EventHandler<LoadPort> AssociatedFinishEvent;

        private bool CheckLoadPortACK(byte accessmode, LoadPort loadObj, ref SanwaLoadPortACK lpACKObj)
        {
            E87RETURN_AM Return           = E87RETURN_AM.SUCCESSFUL;
            bool         allPTNSuccessful = true;

            if (accessmode == 0)    //Manual
            {
                Return = ChangeAccessMode(loadObj, E87_AM.MANUAL);
            }
            else                    //Auto
            {
                Return = ChangeAccessMode(loadObj, E87_AM.AUTO);
            }

            if (Return == E87RETURN_AM.SUCCESSFUL)
            {
                lpACKObj.PortNumber = loadObj.Number;
                lpACKObj.ErrCode    = SanwaACK.ERRCODE_NO_ERROR;
            }
            else if (Return == E87RETURN_AM.IN_ACCESS_MODE_ALREADY)
            {
                lpACKObj.PortNumber = loadObj.Number;
                lpACKObj.ErrCode    = SanwaACK.ERRCODE_NO_ERROR;
            }
            else
            {
                allPTNSuccessful = false;

                lpACKObj.PortNumber = loadObj.Number;
                lpACKObj.ErrCode    = SanwaACK.ERRCODE_LOAD_PORT_ALREADY_IN_USE;
            }

            return(allPTNSuccessful);
        }
Exemple #3
0
        private void ReplyCancelBindService(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg)
        {
            //    0. < DATAID >
            //    1. < CARRIERACTION >
            //    2. < CARRIERID >
            //    3. < PTN >
            string newReplyMsg = GetMessageName(replyMsg.ToSml());
            string carrierID   = e.Message.SecsItem.Items[2].GetString();
            Item   PTNItem     = e.Message.SecsItem.Items[3];

            LoadPort lpObj = _loadPortList.FirstOrDefault(x => x.Value.Number == PTNItem.GetValue <byte>()).Value;

            newReplyMsg += "< L[2]\r\n";

            _carrierList.TryGetValue(carrierID, out SanwaCarrier carrierObj);

            if (lpObj == null)
            {
                //無對應Load Port
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[2]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else if (carrierObj == null)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[2]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_UNKNOWN_OBJECT_INSTANCE.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else
            {
                _carrierList.Remove(carrierObj.ObjID);

                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";
                newReplyMsg += "<L[0]\r\n>\r\n";

                E87_HostCommand Obj = new E87_HostCommand
                {
                    Name        = "CancelBind",
                    MessageName = "S3F17",
                    lpObj       = lpObj,
                    carrierObj  = carrierObj
                };

                //S3F17CancelBindEvent?.Invoke(this, Obj);
                ThreadPool.QueueUserWorkItem(callback =>
                {
                    S3F17CancelBindEvent?.Invoke(this, Obj);
                });
            }

            newReplyMsg += ">\r\n";
            e.ReplyAsync(newReplyMsg.ToSecsMessage());
        }
Exemple #4
0
        public bool ChangeReserviceState(LoadPort lpObj, E87_RS ReserviceState)
        {
            bool Return = true;

            if (ReserviceState == E87_RS.RESERVED && ReserviceState == lpObj.Reserved)
            {
                Return = false;
            }

            if (Return)
            {
                lpObj.Reserved = ReserviceState;
                //ReservedFinishEvent?.Invoke(this, lpObj);
            }

            return(Return);
        }
Exemple #5
0
        public void LoadPortCarrierAssociated(LoadPort lpObj, SanwaCarrier carrierObj, E87_ASSOCIATED associated)
        {
            if (associated == E87_ASSOCIATED.ASSOCIATION)
            {
                lpObj.Carrier          = carrierObj;
                carrierObj.LoadPortObj = lpObj;
            }
            else
            {
                lpObj.Carrier          = null;
                carrierObj.LoadPortObj = null;
            }


            lpObj.Associated      = associated;
            carrierObj.Associated = associated;

            //AssociatedFinishEvent?.Invoke(this, lpObj);
        }
Exemple #6
0
        private void ReplyCarrierReCreate(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg)
        {
            //    0. < DATAID >
            //    1. < CARRIERACTION >
            //    2. < CARRIERID >
            //    3. < PTN >
            string newReplyMsg = GetMessageName(replyMsg.ToSml());

            string carrierID = e.Message.SecsItem.Items[2].GetString();
            Item   PTNItem   = e.Message.SecsItem.Items[3];

            LoadPort lpObj = _loadPortList.FirstOrDefault(x => x.Value.Number == PTNItem.GetValue <byte>()).Value;

            newReplyMsg += "< L[2]\r\n";

            _carrierList.TryGetValue(carrierID, out SanwaCarrier carrierObj);

            if (lpObj == null)
            {
                //無對應Load Port
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[2]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            //else if (lpObj.IsReserved == E87_RS.RESERVED)
            //{
            //    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
            //    newReplyMsg += "<L[2]\r\n";
            //    newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_ALREADY_IN_USE.ToString());
            //    newReplyMsg += "<A[0]>\r\n";
            //    newReplyMsg += ">\r\n";
            //}
            else if (carrierObj == null)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[2]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_UNKNOWN_OBJECT_INSTANCE.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else if (lpObj.CurrentState != E87_LPTS.READY_TO_UNLOAD)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[2]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_COMMAND_NOT_VALID_FOR_CURRENT_STATE.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else
            {
                Item  CattrList        = e.Message.SecsItem.Items[4];
                ulong CheckCattrReturn = CheckCattrList(CattrList);

                if (CheckCattrReturn != SanwaACK.ERRCODE_NO_ERROR)
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                    newReplyMsg += "<L[2]\r\n";
                    newReplyMsg += GetToSMLItem(SecsFormat.U1, CheckCattrReturn.ToString());
                    newReplyMsg += "<A[0]>\r\n";
                    newReplyMsg += ">\r\n";
                }
                else
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";
                    newReplyMsg += "<L[0]\r\n>\r\n";

                    _carrierList.Remove(carrierID);

                    SanwaCarrier newCarrierObj = new SanwaCarrier
                    {
                        ObjID = carrierID
                    };

                    SetCarrierAttribute(CattrList, ref newCarrierObj);

                    _carrierList.Add(newCarrierObj.ObjID, newCarrierObj);

                    //ChangeReserviceState(lpObj, E87_RS.NOT_RESERVED);

                    //LoadPortCarrierAssociated(lpObj, newCarrierObj, E87_ASSOCIATED.NOT_ASSOCIATION);

                    ////等效於Bind
                    //if (CattrList.Count > 0)
                    //{
                    //    ChangeReserviceState(lpObj, E87_RS.RESERVED);

                    //    LoadPortCarrierAssociated(lpObj, newCarrierObj, E87_ASSOCIATED.ASSOCIATION);
                    //}


                    E87_HostCommand Obj = new E87_HostCommand
                    {
                        Name        = "CarrierReCreate",
                        MessageName = "S3F17",
                        lpObj       = lpObj,
                        carrierObj  = newCarrierObj
                    };

                    //S3F17CarrierReCreateEvent?.Invoke(this, Obj);
                    ThreadPool.QueueUserWorkItem(callback =>
                    {
                        S3F17CarrierReCreateEvent?.Invoke(this, Obj);
                    });
                }
            }

            newReplyMsg += ">\r\n";
            e.ReplyAsync(newReplyMsg.ToSecsMessage());
        }
Exemple #7
0
        public void ReplyChangeServiceStatus(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg, bool inService)
        {
            string newReplyMsg = GetMessageName(replyMsg.ToSml());

            Item PTNItem = e.Message.SecsItem.Items[1];
            Item ServiceStatusList;

            if (e.Message.SecsItem.Count == 3)  //CHANGESERVICESTATUS
            {
                ServiceStatusList = e.Message.SecsItem.Items[2];

                if (ServiceStatusList.Count > 0)
                {
                    //0 :out of service
                    //1 :In service

                    Item PARAMVALItem = ServiceStatusList.Items[1];
                    switch (PARAMVALItem.Format)
                    {
                    case SecsFormat.ASCII:
                        inService = PARAMVALItem.GetString() == "0" ? false : true;
                        break;

                    case SecsFormat.Binary:
                        byte[] paramval = PARAMVALItem.GetValues <byte>();
                        inService = paramval[0] == 0x00 ? false : true;
                        break;

                    case SecsFormat.Boolean:
                        inService = PARAMVALItem.GetValue <bool>();
                        break;

                    case SecsFormat.F4:
                        inService = PARAMVALItem.GetValue <float>() == 0.0f ? false : true;
                        break;

                    case SecsFormat.F8:
                        inService = PARAMVALItem.GetValue <double>() == 0.0d ? false : true;
                        break;

                    case SecsFormat.I1:
                        inService = PARAMVALItem.GetValue <byte>() == 0 ? false : true;
                        break;

                    case SecsFormat.I2:
                        inService = PARAMVALItem.GetValue <short>() == 0 ? false : true;
                        break;

                    case SecsFormat.I4:
                        inService = PARAMVALItem.GetValue <int>() == 0 ? false : true;
                        break;

                    case SecsFormat.I8:
                        inService = PARAMVALItem.GetValue <long>() == 0 ? false : true;
                        break;

                    case SecsFormat.U1:
                        inService = PARAMVALItem.GetValue <sbyte>() == 0 ? false : true;
                        break;

                    case SecsFormat.U2:
                        inService = PARAMVALItem.GetValue <ushort>() == 0 ? false : true;
                        break;

                    case SecsFormat.U4:
                        inService = PARAMVALItem.GetValue <uint>() == 0 ? false : true;
                        break;

                    case SecsFormat.U8:
                        inService = PARAMVALItem.GetValue <ulong>() == 0 ? false : true;
                        break;
                    }
                }
            }

            LoadPort lpObj = _loadPortList.FirstOrDefault(x => x.Value.Number == PTNItem.GetValue <byte>()).Value;

            newReplyMsg += "< L[2]\r\n";

            if (lpObj == null)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[0]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";

                bool Return = true;


                if (inService)
                {
                    Return = ChangeLoadPortState(lpObj, E87_LPTS.IN_SERVICE);

                    if (Return)
                    {
                        E87_HostCommand hcObj = new E87_HostCommand
                        {
                            lpObj       = lpObj,
                            Name        = "INSERVICE",
                            MessageName = "S3F25"
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F25InServiceEvent?.Invoke(this, hcObj);
                        });
                    }
                }
                else
                {
                    Return = ChangeLoadPortState(lpObj, E87_LPTS.OUT_OF_SERVICE);

                    if (Return)
                    {
                        E87_HostCommand hcObj = new E87_HostCommand
                        {
                            lpObj       = lpObj,
                            Name        = "OUTOFSERVICE",
                            MessageName = "S3F25"
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F25OutOfServiceEvent?.Invoke(this, hcObj);
                        });
                    }
                }
                newReplyMsg += "<L[0]\r\n>\r\n";
            }


            newReplyMsg += ">\r\n";

            e.ReplyAsync(newReplyMsg.ToSecsMessage());
        }
Exemple #8
0
        public void ReplyChangeReservePortStatus(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg, bool reserveAtPort)
        {
            string   newReplyMsg = GetMessageName(replyMsg.ToSml());
            Item     PTNItem     = e.Message.SecsItem.Items[1];
            LoadPort lpObj       = _loadPortList.FirstOrDefault(x => x.Value.Number == PTNItem.GetValue <byte>()).Value;

            newReplyMsg += "< L[2]\r\n";

            if (lpObj == null)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[0]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else
            {
                bool Return = true;
                if (reserveAtPort)
                {
                    Return = ChangeReserviceState(lpObj, E87_RS.RESERVED);
                }
                else
                {
                    Return = ChangeReserviceState(lpObj, E87_RS.NOT_RESERVED);
                }

                if (Return)
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";
                    newReplyMsg += "<L[0]\r\n>\r\n";

                    if (reserveAtPort)
                    {
                        E87_HostCommand hcObj = new E87_HostCommand
                        {
                            lpObj       = lpObj,
                            Name        = "RESERVEATPORT",
                            MessageName = "S3F25"
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F25ReserveAtPortEvent?.Invoke(this, hcObj);
                        });
                    }
                    else
                    {
                        E87_HostCommand hcObj = new E87_HostCommand
                        {
                            lpObj       = lpObj,
                            Name        = "CANCELRESERVEATPORT",
                            MessageName = "S3F25"
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F25CancelReserveAtPortEvent?.Invoke(this, hcObj);
                        });
                    }
                }
                else
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                    newReplyMsg += "<L[0]\r\n";
                    newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_ALREADY_IN_USE.ToString());
                    newReplyMsg += "<A[0]>\r\n";
                    newReplyMsg += ">\r\n";
                }
            }

            newReplyMsg += ">\r\n";

            e.ReplyAsync(newReplyMsg.ToSecsMessage());
        }
Exemple #9
0
        public void ReplyChangeAccess(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg, bool autoMode)
        {
            string newReplyMsg = GetMessageName(replyMsg.ToSml());
            Item   PTNItem     = e.Message.SecsItem.Items[1];
            Item   ChangeAccessList;

            if (e.Message.SecsItem.Count == 3)  //CHANGESERVICESTATUS
            {
                ChangeAccessList = e.Message.SecsItem.Items[2];

                if (ChangeAccessList.Count > 0)
                {
                    //0 :Manual
                    //1 :Auto

                    Item PARAMVALItem = ChangeAccessList.Items[1];
                    switch (PARAMVALItem.Format)
                    {
                    case SecsFormat.ASCII:
                        autoMode = PARAMVALItem.GetString() == "0" ? false : true;
                        break;

                    case SecsFormat.Binary:
                        byte[] paramval = PARAMVALItem.GetValues <byte>();
                        autoMode = paramval[0] == 0x00 ? false : true;
                        break;

                    case SecsFormat.Boolean:
                        autoMode = PARAMVALItem.GetValue <bool>();
                        break;

                    case SecsFormat.F4:
                        autoMode = PARAMVALItem.GetValue <float>() == 0.0f ? false : true;
                        break;

                    case SecsFormat.F8:
                        autoMode = PARAMVALItem.GetValue <double>() == 0.0d ? false : true;
                        break;

                    case SecsFormat.I1:
                        autoMode = PARAMVALItem.GetValue <byte>() == 0 ? false : true;
                        break;

                    case SecsFormat.I2:
                        autoMode = PARAMVALItem.GetValue <short>() == 0 ? false : true;
                        break;

                    case SecsFormat.I4:
                        autoMode = PARAMVALItem.GetValue <int>() == 0 ? false : true;
                        break;

                    case SecsFormat.I8:
                        autoMode = PARAMVALItem.GetValue <long>() == 0 ? false : true;
                        break;

                    case SecsFormat.U1:
                        autoMode = PARAMVALItem.GetValue <sbyte>() == 0 ? false : true;
                        break;

                    case SecsFormat.U2:
                        autoMode = PARAMVALItem.GetValue <ushort>() == 0 ? false : true;
                        break;

                    case SecsFormat.U4:
                        autoMode = PARAMVALItem.GetValue <uint>() == 0 ? false : true;
                        break;

                    case SecsFormat.U8:
                        autoMode = PARAMVALItem.GetValue <ulong>() == 0 ? false : true;
                        break;
                    }
                }
            }

            LoadPort lpObj = _loadPortList.FirstOrDefault(x => x.Value.Number == PTNItem.GetValue <byte>()).Value;

            newReplyMsg += "< L[2]\r\n";

            if (lpObj == null)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                newReplyMsg += "<L[0]\r\n";
                newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST.ToString());
                newReplyMsg += "<A[0]>\r\n";
                newReplyMsg += ">\r\n";
            }
            else
            {
                E87RETURN_AM Return;

                if (autoMode)
                {
                    Return = ChangeAccessMode(lpObj, E87_AM.AUTO);
                }
                else
                {
                    Return = ChangeAccessMode(lpObj, E87_AM.MANUAL);
                }


                if (Return == E87RETURN_AM.SUCCESSFUL || Return == E87RETURN_AM.IN_ACCESS_MODE_ALREADY)
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";
                    newReplyMsg += "<L[0]\r\n>\r\n";

                    if (Return == E87RETURN_AM.SUCCESSFUL)
                    {
                        if (autoMode)
                        {
                            E87_HostCommand hcObj = new E87_HostCommand
                            {
                                lpObj       = lpObj,
                                Name        = "AUTOMODE",
                                MessageName = "S3F25"
                            };
                            S3F25AutoModeEvent?.Invoke(this, hcObj);
                        }
                        else
                        {
                            E87_HostCommand hcObj = new E87_HostCommand
                            {
                                lpObj       = lpObj,
                                Name        = "MANUALMODE",
                                MessageName = "S3F25"
                            };
                            S3F25ManualModeEvent?.Invoke(this, hcObj);
                        }
                    }
                }
                else
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                    newReplyMsg += GetToSMLItem(SecsFormat.U1, SanwaACK.ERRCODE_OBJECT_IDENTIFIER_IN_USE.ToString());
                    newReplyMsg += "<A[0]>\r\n";
                }
            }
            newReplyMsg += ">\r\n";

            e.ReplyAsync(newReplyMsg.ToSecsMessage());
        }
Exemple #10
0
        public bool ChangeLoadPortState(LoadPort lpObj, E87_LPTS newState)
        {
            bool Return = true;

            lpObj.InTransfer = true;

            if (lpObj.CurrentState != E87_LPTS.NO_STATE)
            {
                if (newState == lpObj.CurrentState)
                {
                    Return = false;
                }
            }

            switch (lpObj.CurrentState)
            {
            case E87_LPTS.NO_STATE:
                if (!(newState == E87_LPTS.IN_SERVICE ||
                      newState == E87_LPTS.OUT_OF_SERVICE ||
                      newState == E87_LPTS.TRANSFER_BLOCKED ||
                      newState == E87_LPTS.TRANSFER_READY))
                {
                    Return = false;
                }

                break;

            case E87_LPTS.OUT_OF_SERVICE:
                //任何狀態下都可以切換 OUT_OF_SERVICE

                break;

            case E87_LPTS.IN_SERVICE:
                if (!(newState == E87_LPTS.OUT_OF_SERVICE ||
                      newState == E87_LPTS.TRANSFER_BLOCKED ||
                      newState == E87_LPTS.TRANSFER_READY))
                {
                    Return = false;
                }

                break;

            case E87_LPTS.TRANSFER_BLOCKED:
                if (!(newState == E87_LPTS.TRANSFER_READY ||
                      newState == E87_LPTS.READY_TO_LOAD ||
                      newState == E87_LPTS.READY_TO_UNLOAD ||
                      newState == E87_LPTS.OUT_OF_SERVICE))
                {
                    Return = false;
                }

                break;

            case E87_LPTS.TRANSFER_READY:
                if (!(newState == E87_LPTS.READY_TO_LOAD ||
                      newState == E87_LPTS.READY_TO_UNLOAD ||
                      newState == E87_LPTS.OUT_OF_SERVICE))
                {
                    Return = false;
                }

                break;

            case E87_LPTS.READY_TO_LOAD:
                if (!(newState == E87_LPTS.TRANSFER_BLOCKED ||
                      newState == E87_LPTS.OUT_OF_SERVICE))
                {
                    Return = false;
                }
                break;

            case E87_LPTS.READY_TO_UNLOAD:
                if (!(newState == E87_LPTS.TRANSFER_BLOCKED ||
                      newState == E87_LPTS.OUT_OF_SERVICE))
                {
                    Return = false;
                }
                break;
            }

            if (Return)
            {
                lpObj.PreviousState = lpObj.CurrentState;
                lpObj.CurrentState  = newState;
            }

            lpObj.InTransfer = false;
            return(true);
        }
Exemple #11
0
        private void ReplyAccessMode(PrimaryMessageWrapper e, SecsMessage receiveMsg, SecsMessage replyMsg, bool GroupDefine)
        {
            Item PORTGRPNAMEItem = null;
            Item ACCESSMODEItem  = null;
            Item PTNList         = null;

            if (GroupDefine)
            {
                PORTGRPNAMEItem = e.Message.SecsItem.Items[0];
                ACCESSMODEItem  = e.Message.SecsItem.Items[1];
                PTNList         = e.Message.SecsItem.Items[2];
            }
            else
            {
                ACCESSMODEItem = e.Message.SecsItem.Items[0];
                PTNList        = e.Message.SecsItem.Items[1];
            }

            if (GroupDefine)
            {
                string LPGroupName = PORTGRPNAMEItem.GetString();
                _loadPortGroupList.TryGetValue(LPGroupName, out LoadPortGroup LPGObj);

                if (LPGObj != null)
                {
                    _loadPortGroupList.Remove(LPGroupName);
                }

                if (PTNList.Count > 0)
                {
                    LoadPortGroup lpgObj = new LoadPortGroup
                    {
                        Name = LPGroupName
                    };

                    for (int i = 0; i < PTNList.Count; i++)
                    {
                        Item     PTNItem = PTNList.Items[i];
                        byte     ptn     = PTNItem.GetValue <byte>();
                        LoadPort loadObj = _loadPortList.FirstOrDefault(x => x.Value.Number == ptn).Value;
                        if (loadObj != null)
                        {
                            lpgObj._loadPortList.Add(loadObj.Name, loadObj);
                        }
                    }

                    _loadPortGroupList.Add(LPGroupName, lpgObj);
                }
            }

            string newReplyMsg = GetMessageName(replyMsg.ToSml());

            newReplyMsg += "< L[2]\r\n";

            Dictionary <string, SanwaLoadPortACK> LPACKList = new Dictionary <string, SanwaLoadPortACK>();

            if (ACCESSMODEItem.Format != SecsFormat.U1 || PTNList.Format != SecsFormat.List)
            {
                newReplyMsg += "<U1[0] " + SanwaACK.CAACK_INVALID_DATA.ToString() + ">\r\n";
                newReplyMsg += "<L[0]\r\n>\r\n";
            }
            else
            {
                byte accessmode = ACCESSMODEItem.GetValue <byte>();

                bool allPTNSuccessful = true;

                if (PTNList.Count > 0)
                {
                    for (int i = 0; i < PTNList.Count; i++)
                    {
                        Item             PTNItem  = PTNList.Items[i];
                        SanwaLoadPortACK lpACKObj = new SanwaLoadPortACK();
                        byte             ptn      = PTNItem.GetValue <byte>();
                        LoadPort         loadObj  = _loadPortList.FirstOrDefault(x => x.Value.Number == ptn).Value;

                        if (loadObj == null)
                        {
                            allPTNSuccessful = false;

                            lpACKObj.PortNumber = ptn;
                            lpACKObj.ErrCode    = SanwaACK.ERRCODE_LOAD_PORT_DOES_NOT_EXIST;
                        }
                        else
                        {
                            CheckLoadPortACK(GroupDefine, accessmode, loadObj, ref lpACKObj, ref allPTNSuccessful);
                        }

                        LPACKList.Add(lpACKObj.PortNumber.ToString(), lpACKObj);
                    }
                }
                else
                {
                    foreach (var loadObj in _loadPortList.Values)
                    {
                        SanwaLoadPortACK lpACKObj = new SanwaLoadPortACK();

                        CheckLoadPortACK(GroupDefine, accessmode, loadObj, ref lpACKObj, ref allPTNSuccessful);

                        LPACKList.Add(lpACKObj.PortNumber.ToString(), lpACKObj);
                    }
                }

                if (allPTNSuccessful)
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_ACK.ToString() + ">\r\n";
                    newReplyMsg += "<L[0]\r\n>\r\n";
                }
                else
                {
                    newReplyMsg += "<U1[0] " + SanwaACK.CAACK_CMD_PERFOEM_WITH_ERR.ToString() + ">\r\n";
                    foreach (var lpACKObj in LPACKList.Values)
                    {
                        newReplyMsg += GetToSMLItem(SecsFormat.U1, lpACKObj.ErrCode.ToString());
                        newReplyMsg += GetToSMLItem(SecsFormat.ASCII, lpACKObj.ErrText);
                    }
                }

                newReplyMsg += ">\r\n";
                e.ReplyAsync(newReplyMsg.ToSecsMessage());
            }
        }
Exemple #12
0
        private void CheckLoadPortACK(bool GroupDefine, byte accessmode, LoadPort loadObj,
                                      ref SanwaLoadPortACK lpACKObj, ref bool allPTNSuccessful)
        {
            if (!CheckLoadPortACK(accessmode, loadObj, ref lpACKObj))
            {
                allPTNSuccessful = false;
            }
            else
            {
                if (!GroupDefine)
                {
                    if (accessmode == 0x01)
                    {
                        E87_HostCommand Obj = new E87_HostCommand
                        {
                            Name        = "AUTOMODE",
                            MessageName = "S3F27",
                            lpObj       = loadObj
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F27AutoModeEvent?.Invoke(this, Obj);
                        });
                    }
                    else
                    {
                        E87_HostCommand Obj = new E87_HostCommand
                        {
                            Name        = "MANUALMODE",
                            MessageName = "S3F27",
                            lpObj       = loadObj
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F27ManualModeEvent?.Invoke(this, Obj);
                        });
                    }
                }
                else
                {
                    if (accessmode == 0x01)
                    {
                        E87_HostCommand Obj = new E87_HostCommand
                        {
                            Name        = "AUTOMODE",
                            MessageName = "S3F21",
                            lpObj       = loadObj
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F21AutoModeEvent?.Invoke(this, Obj);
                        });
                    }
                    else
                    {
                        E87_HostCommand Obj = new E87_HostCommand
                        {
                            Name        = "MANUALMODE",
                            MessageName = "S3F21",
                            lpObj       = loadObj
                        };

                        ThreadPool.QueueUserWorkItem(callback =>
                        {
                            S3F21ManualModeEvent?.Invoke(this, Obj);
                        });
                    }
                }
            }
        }