예제 #1
0
        /// <summary>
        /// 设置本段机器的后段出料状态(等待出料  出料完成)
        /// </summary>
        /// <param name="sendor">本段机器名称</param>
        /// <param name="Other">前段机器名称</param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public MesCmdAnswer SetOutStateBackSeg(string sendor, MachineState machineState, int timeout, bool SkipCheckLoction = false)
        {
            if (m_TcpLink == null)
            {
                return(null);
            }
            if (autoResetEvent.WaitOne(timeout, true))
            {
                BagClear();
                SetOutStateBackSegCmd cmdobj = new SetOutStateBackSegCmd();
                cmdobj.sendor       = sendor;
                cmdobj.machineState = machineState;

                MesCmdAnswer answer = CheckCMD(cmdobj, machineState, SkipCheckLoction);
                if (answer != null)
                {
                    autoResetEvent.Set();
                    return(answer);
                }

                cmdobj.Send(m_TcpLink);
                MesCmdAnswer mesCmdAnswer = GetCmdAnswerFrowSever(timeout);
                if (mesCmdAnswer != null)
                {
                    WriteStateFlags.AddOrUpdate(cmdobj.GenCmdCode(), machineState, (key, value) => { return(value = machineState); });
                }
                autoResetEvent.Set();
                return(mesCmdAnswer);
            }
            return(null);
        }
예제 #2
0
        public MesCmdAnswer GetLineOutStateCmdExc(string machineName, String Other, int timeout)
        {
            if (m_TcpLink == null)
            {
                return(null);
            }
            if (autoResetEvent.WaitOne(timeout, true))
            {
                BagClear();
                GetLineOutStateCmd getLineStateCmd = new GetLineOutStateCmd();
                getLineStateCmd.sendor = machineName;
                getLineStateCmd.Other  = Other;

                //string strCmd = JsonConvert.SerializeObject(getLineStateCmd);
                //strCmd += MesCmd.LineEndChars;
                //byte[] bytes = Encoding.Default.GetBytes(strCmd);
                //m_TcpLink.WriteData(bytes, bytes.Length);

                getLineStateCmd.Send(m_TcpLink);
                MesCmdAnswer mesCmdAnswer = GetCmdAnswerFrowSever(timeout);
                autoResetEvent.Set();
                return(mesCmdAnswer);
            }
            return(null);
        }
예제 #3
0
        public MesCmdAnswer SetLineOutStateCmdExc(string machineName, MachineState machineState, int timeout, bool SkipCheckLoction = false)
        {
            if (m_TcpLink == null)
            {
                return(null);
            }
            if (autoResetEvent.WaitOne(timeout, true))
            {
                BagClear();
                SetLineOutStateCmd setLineStateCmd = new SetLineOutStateCmd();
                setLineStateCmd.sendor       = machineName;
                setLineStateCmd.machineState = machineState;
                //string strCmd = JsonConvert.SerializeObject(setLineStateCmd);
                //strCmd += MesCmd.LineEndChars;
                //byte[] bytes = Encoding.Default.GetBytes(strCmd);
                //m_TcpLink.WriteData(bytes, bytes.Length);
                MesCmdAnswer answer = CheckCMD(setLineStateCmd, machineState, SkipCheckLoction);
                if (answer != null)
                {
                    autoResetEvent.Set();
                    return(answer);
                }

                setLineStateCmd.Send(m_TcpLink);
                MesCmdAnswer mesCmdAnswer = GetCmdAnswerFrowSever(timeout);
                if (mesCmdAnswer != null)
                {
                    WriteStateFlags.AddOrUpdate(setLineStateCmd.GenCmdCode(), machineState, (key, value) => { return(value = machineState); });
                }
                autoResetEvent.Set();
                return(mesCmdAnswer);
            }
            return(null);
        }
예제 #4
0
        private MesCmdAnswer GetCmdAnswerFromMem(string strcmdcode)
        {
            MesCmdAnswer mesCmdAnswer = null;

            ReciveAllAnswer.TryGetValue(strcmdcode, out mesCmdAnswer);
            return(mesCmdAnswer == null ? null :mesCmdAnswer);
        }
예제 #5
0
        public bool Init(string MachineName, string ip, int port)
        {
            m_TcpLink?.Close();
            bool bRtn = true;

            m_TcpLink = new TcpLink(0, MachineName, ip, port, 10000, MesCmd.LineEndChars);
            if (!m_TcpLink.IsOpen())
            {
                bRtn &= m_TcpLink.Open();
            }
            if (!bRtn)
            {
                return(false);
            }

            m_TcpLink.RecvStringMessageEvent += (object sender, AsyTcpSocketEventArgs e) =>
            {
                try
                {
                    string       answer       = e.Message;
                    MesCmdAnswer mesCmdAnswer = JsonConvert.DeserializeObject <MesCmdAnswer>(answer);
                    if (mesCmdAnswer != null)
                    {
                        Type type = FindCmdType(mesCmdAnswer.CmdType);
                        if (type != null)
                        {
                            mesCmdAnswer = (MesCmdAnswer)JsonConvert.DeserializeObject(answer, type);
                            if (mesCmdAnswer == null)
                            {
                                string timestr = DateTime.Now.ToString("yyyy - MM - dd - hh - mm - ss");
                                string strMes  = $"[{ timestr}]" + $": 回应为空 ";
                                File.AppendAllLines("D:\\ErrSeverInfo.text", new string[] { strMes });
                            }
                            ts.Add(mesCmdAnswer);
                            //CmdAnswer cmdAnswer = new CmdAnswer()
                            //{
                            //    _bHaveSet = true,
                            //    _mesCmdAnswer = mesCmdAnswer,
                            //};

                            ReciveAllAnswer.AddOrUpdate(mesCmdAnswer.strCodeFromCmd, mesCmdAnswer, (key, value) => { return(value = mesCmdAnswer); });
                            return;
                        }
                    }
                }
                catch (Exception es)
                {
                    string timestr = DateTime.Now.ToString("yyyy - MM - dd - hh - mm - ss");
                    string strMes  = $"[{ timestr}]" + $": {es} ";
                    File.AppendAllLines("D:\\ErrSeverInfo.text", new string[] { strMes });
                    ts.Add(null);
                }
            };
            return(true);
        }
예제 #6
0
        public bool Init(TcpLink tcpLink, TcpLink tcpLinkHeart)
        {
            m_TcpLink = tcpLink;
            bool bRtn = true;

            if (tcpLink == null)
            {
                return(false);
            }
            tcpLink.RecvStringMessageEvent += (object sender, AsyTcpSocketEventArgs e) =>
            {
                string       answer       = e.Message;
                MesCmdAnswer mesCmdAnswer = JsonConvert.DeserializeObject <MesCmdAnswer>(answer);
                if (mesCmdAnswer != null)
                {
                    Type type = FindCmdType(mesCmdAnswer.CmdType);
                    if (type != null)
                    {
                        mesCmdAnswer = (MesCmdAnswer)JsonConvert.DeserializeObject(answer, type);
                        if (mesCmdAnswer == null)
                        {
                            string timestr = DateTime.Now.ToString("yyyy - MM - dd - hh - mm - ss");
                            string strMes  = $"[{ timestr}]" + $": 回应为空 ";
                            File.AppendAllLines("D:\\ErrSeverInfo.text", new string[] { strMes });
                        }
                        ts.Add(mesCmdAnswer);
                        //CmdAnswer cmdAnswer = new CmdAnswer() {
                        //    _bHaveSet = true,
                        //    _mesCmdAnswer = mesCmdAnswer,
                        //};
                        lock ( objLock)
                        {
                            ReciveAllAnswer.AddOrUpdate(mesCmdAnswer.strCodeFromCmd, mesCmdAnswer, (key, value) => { return(value = mesCmdAnswer); });
                        }

                        return;
                    }
                }
                ts.Add(null);
            };
            if (!tcpLink.IsOpen())
            {
                bRtn &= tcpLink.Open();
            }
            if (!bRtn)
            {
                return(false);
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// 查询机器后段的出料状态 (后机返回 等待出料 出料完成)
        /// </summary>
        /// <param name="sendor">本段机器名称</param>
        /// <param name="Other">后段机器名称</param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public MesCmdAnswer QueryBackSegOutState(string sendor, String Other, int timeout)
        {
            if (m_TcpLink == null)
            {
                return(null);
            }
            if (autoResetEvent.WaitOne(timeout, true))
            {
                BagClear();
                GetOutStateBackSegCmd cmdobj = new GetOutStateBackSegCmd();
                cmdobj.sendor = sendor;
                cmdobj.Other  = Other;


                cmdobj.Send(m_TcpLink);
                MesCmdAnswer mesCmdAnswer = GetCmdAnswerFrowSever(timeout);
                autoResetEvent.Set();
                return(mesCmdAnswer);
            }
            return(null);
        }
예제 #8
0
        private MesCmdAnswer GetCmdAnswerFrowSever(int nTimeout)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Restart();
            MesCmdAnswer mesCmdAnswer = ts.Take();

            while (mesCmdAnswer == null)
            {
                if (stopwatch.ElapsedMilliseconds > nTimeout)
                {
                    break;
                }
                mesCmdAnswer = ts.Take();
            }

            if (mesCmdAnswer == null)
            {
            }
            return(mesCmdAnswer);
        }