示例#1
0
        //接收串口数据
        public void ReceiveData()
        {
            byte[] response_data = RecvSeriData.ReceData(serialPort);

            if (response_data != null)
            {
                byte ID_Temp = response_data[3];
                Ship ship    = GlobalManager.Instance.GetShip(ID_Temp);

                ship.UpdataStatusData(response_data);
                if (GlobalManager.flag_ctrl)
                {
                    LocalDataModel.Instance.StoreShipData(ship);
                }

                Array.Clear(response_data, 0, response_data.Length);

                GlobalManager.Instance.Main_View.ShowShipParam(ship);//有数据更新时才更新显示,否则不更新(即不是每次接收到数据才更新,只有接收到正确的数据才更新)
            }
        }
示例#2
0
        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            byte[] response_data = RecvSeriData.ReceData(serialPort1);

            #region 接收到一组正确的数据,则进行处理和显示
            if (response_data != null)
            {
                byte ID_Temp = response_data[3];
                switch (ID_Temp)
                {
                case 0x01: boat1.UpdataStatusData(response_data); boat1.StoreShipData(name); break;

                case 0x02: boat2.UpdataStatusData(response_data); boat2.StoreShipData(name); break;

                case 0x03: boat3.UpdataStatusData(response_data); boat3.StoreShipData(name); break;

                default: break;
                }
                Array.Clear(response_data, 0, response_data.Length);
                Display();//有数据更新时才更新显示,否则不更新(即不是每次接收到数据才更新,只有接收到正确的数据才更新)
            }
            #endregion
        }