/// <summary>
 /// 跨线程托管:刷新小车位置
 /// </summary>
 /// <param name="MachineNo"></param>
 /// <param name="pos"></param>
 private void ThreadUIRefreshMachineCoord(int MachineNo, TMCoord pos)
 {
     this.wareHouseControl1.RefreshMachineCoord(MachineNo, pos);
     if(MachineNo == 1)
     {
         StringBuilder str = new StringBuilder();
         str.AppendFormat("层:{0},巷道:1,列:{1}", pos.L, pos.C);
         this.labelMachinePos1.Text = str.ToString();
     }
     else if(MachineNo == 2)
     {
         StringBuilder str = new StringBuilder();
         str.AppendFormat("层:{0},巷道:2,列:{1}", pos.L, pos.C);
         this.labelMachinePos2.Text = str.ToString();
     }
 }
        /// <summary>
        /// 刷新小车坐标
        /// </summary>
        /// <param name="MachineNo"></param>
        /// <param name="pos"></param>
        public void RefreshMachineCoord(int MachineNo, TMCoord pos)
        {
            if (pos.L < 1)
                pos.L = 1;
            if (pos.L > _LayerCount)
                pos.L = _LayerCount;

            if (pos.Ch < 1)
                pos.Ch = 1;
            if (pos.Ch > _ChannelCount)
                pos.Ch = _ChannelCount;
            if (pos.C < 1)
                pos.C = 1;
            if (pos.C > _ColumnCount)
                pos.C = _ColumnCount;
            if (_MachineDic.Count > 0)
            {
                TRANSMachine m = _MachineDic[MachineNo];

                if (m != null && (pos != m.MachinePos))
                {
                    m.CellLayer = _LayersList.ElementAt(pos.L - 1);
                    m.MachinePos = pos;
                    this.panelWareCells.Refresh();
                }
            }
        }
 /// <summary>
 /// 刷新小车位置
 /// </summary>
 /// <param name="MachineNo"></param>
 /// <param name="pos"></param>
 public void RefreshMachineCoord(int MachineNo, TMCoord  pos)
 {
     if(this.wareHouseControl1.InvokeRequired)
     {
         this.Invoke(new delegateUIRefreshPos(ThreadUIRefreshMachineCoord), MachineNo, pos);
     }
     else
     {
         ThreadUIRefreshMachineCoord(MachineNo, pos);
     }
 }
        /// <summary>
        /// 接收数据线程函数
        /// </summary>
        private void recvPlcProc()
        {
            byte[] data = new byte[1024];
            while (_conPlc)
            {
                 int recv =0;
                 byte[] byteStream = null;
                try
                {

                  //  recv= _sockPlc.ReceiveFrom(data, ref _epPlc);
                    byteStream = _udpClient.Receive(ref  C_Point);
                    _heartCount = 0; //收到数据包,清零,标识连接建立
                    _bConnected = true;
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("plc comm:"+e.Message);
                    continue;
                }

                //事件参数

                udpPackage package = new udpPackage();

                for (int i = 0; i < recv; i++)
                {
                    byteStream[i] = data[i];
                }
                if (package.Pack(byteStream))
                {
                    if ((package.frameType == 0x02) && (package.addr == this.MachineNo))
                    {
                        //应答帧,地址正确
                        if (package.cmd == (byte)HouseCmdCode.CMD_QUERY)
                        {
                            MachineWorkStatus newS = (MachineWorkStatus)package.data[3];
                            TMCoord newPos = new TMCoord(package.data[0], this.MachineNo, (package.data[1] + (package.data[2] << 8)));

                            if (newS != MStatus)
                            {
                                if(MStatus == MachineWorkStatus.PRODUCT_INHOUSE_OK)
                                {
                                    string ss = "入库任务"+(_currentCmdIndex+1).ToString()+"完成";
                                    Console.WriteLine(ss);

                                }
                                MStatus = newS;
                            //    string strS = "小车"+MachineNo.ToString()+"状态:"+MStatus.ToString();
                           //     Console.WriteLine(strS);
                                msgTMEventArg e = new msgTMEventArg();
                                e.MachineNo = this.MachineNo;
                                e.ErrorHappened = false;
                                e.TMStatus = newS;
                                if (EventTMStatusUpdated != null)
                                {
                                    EventTMStatusUpdated(this, e);
                                }

                            }
                            if(newPos != this.currentCoord)
                            {
                                msgTMEventArg e = new msgTMEventArg();
                                e.MachineNo = this.MachineNo;
                                e.ErrorHappened = false;
                                e.TMPos = newPos;
                                if(EventTMPosUpdated != null)
                                {
                                    EventTMPosUpdated(this,e);
                                }
                            }
                        }
                        else if (package.cmd == (byte)HouseCmdCode.CMD_PRODUCT_INHOUSE)
                        {

                        }
                        else if (package.cmd == (byte)HouseCmdCode.CMD_PRODUCT_OUTHOUSE)
                        {

                        }
                    }
                }
            }
        }