Esempio n. 1
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);
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
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);
                        });
                    }
                }
            }
        }