コード例 #1
0
ファイル: test_TasksCollection.cs プロジェクト: wwkkww1983/bt
        //public override void Execute(CommPortProxy commPortProxy)
        protected override void OnExecute(CommPortProxy commPortProxy, CommCmdBase cmd)
        {
            //base.OnExecute (commPortProxy, station, cmd, parameters);
            //}
            //
            //{

            byte[] bytescmd = CommCmd.MakeCommand( );
            int    late     = CommCmd.LatencyTime;

            if (!commPortProxy.IsOpen)
            {
                commPortProxy.Open();
            }

            commPortProxy.Send(bytescmd, late);
        }
コード例 #2
0
        protected override void WaiteForDeviceAck(int timeout)
        {
            byte b     = 0;
            int  num   = 0;
            long ticks = DateTime.Now.Ticks;

            while (true)
            {
                num = (int)((DateTime.Now.Ticks - ticks) / 10000);
                if (timeout <= num)
                {
                    if ((b = (byte)(b + 1)) > 1)
                    {
                        throw new Exception("Communication timeout.");
                    }
                    ticks = DateTime.Now.Ticks;
                    SendDataFrame();
                }
                bool flag = false;
                Thread.Sleep(0);
                if (commState == CommState.csErr)
                {
                    CommCmd curCmd = base.curCmd;
                    Thread.Sleep(1000);
                    if (!SearchIsdtDevice())
                    {
                        break;
                    }
                    WriteTxFrame(curCmd);
                    ticks = DateTime.Now.Ticks;
                }
                if (SmLnkPkgMsg)
                {
                    return;
                }
            }
            throw new Exception("Connect the device failed.");
        }
コード例 #3
0
        protected void WriteTxFrame(CommCmd cmd)
        {
            byte[] array = new byte[512];
            curCmd = cmd;
            switch (cmd)
            {
            case CommCmd.TestLinker:
                array[0] = 0;
                TxLen    = ConstructTxDataFrame(array, 1);
                break;

            case CommCmd.QueryDevice:
                array[0] = 224;
                TxLen    = ConstructTxDataFrame(array, 1);
                break;

            case CommCmd.AppUpdate:
                array[0] = 240;
                array[1] = 172;
                TxLen    = ConstructTxDataFrame(array, 2);
                break;

            case CommCmd.EraseApp:
                array[0] = 242;
                array[1] = 0;
                array[2] = (byte)(AppInfoTable.AppStartAddress & 0xFF);
                array[3] = (byte)((AppInfoTable.AppStartAddress >> 8) & 0xFF);
                array[4] = (byte)((AppInfoTable.AppStartAddress >> 16) & 0xFF);
                array[5] = (byte)((AppInfoTable.AppStartAddress >> 24) & 0xFF);
                array[6] = (byte)(AppInfoTable.AppSize & 0xFF);
                array[7] = (byte)((AppInfoTable.AppSize >> 8) & 0xFF);
                array[8] = (byte)((AppInfoTable.AppSize >> 16) & 0xFF);
                array[9] = (byte)((AppInfoTable.AppSize >> 24) & 0xFF);
                TxLen    = ConstructTxDataFrame(array, 10);
                break;

            case CommCmd.WriteApp:
                array[0] = 244;
                array[1] = 0;
                array[2] = (byte)(AppUpdateWriteAddress & 0xFF);
                array[3] = (byte)((AppUpdateWriteAddress >> 8) & 0xFF);
                array[4] = (byte)((AppUpdateWriteAddress >> 16) & 0xFF);
                array[5] = (byte)((AppUpdateWriteAddress >> 24) & 0xFF);
                for (int n = 0; n < 128; n++)
                {
                    array[6 + n] = UpdateFileBuf[(uint)((int)(AppUpdateWriteAddress - FileHeadInfo.AppStorageOffset) + Marshal.SizeOf(typeof(TFileHeadInfo))) + n];
                }
                TxLen = ConstructTxDataFrame(array, 134);
                break;

            case CommCmd.WriteAppData:
                array[0]  = 32;
                array[1]  = 5;
                array[2]  = 0;
                array[3]  = 0;
                array[4]  = 0;
                array[5]  = (byte)(ExFlashUpdateWriteAddress & 0xFF);
                array[6]  = (byte)((ExFlashUpdateWriteAddress >> 8) & 0xFF);
                array[7]  = (byte)((ExFlashUpdateWriteAddress >> 16) & 0xFF);
                array[8]  = (byte)((ExFlashUpdateWriteAddress >> 24) & 0xFF);
                array[9]  = 128;
                array[10] = 0;
                array[11] = 0;
                array[12] = 0;
                for (int j = 0; j < 16; j++)
                {
                    array[13 + j] = 0;
                }
                for (int k = 0; k < 128; k++)
                {
                    array[29 + k] = UpdateFileBuf[ExFlashUpdateWriteAddress - FileHeadInfo.DataStorageOffset + k + FileHeadInfo.AppSize + (uint)Marshal.SizeOf(typeof(TFileHeadInfo))];
                }
                TxLen = ConstructTxDataFrame(array, 157);
                break;

            case CommCmd.AppDataCheckSum:
            {
                uint num2 = 0u;
                array[0]  = 32;
                array[1]  = 6;
                array[2]  = 0;
                array[3]  = 0;
                array[4]  = 0;
                array[5]  = (byte)(FileHeadInfo.DataStorageOffset & 0xFF);
                array[6]  = (byte)((FileHeadInfo.DataStorageOffset >> 8) & 0xFF);
                array[7]  = (byte)((FileHeadInfo.DataStorageOffset >> 16) & 0xFF);
                array[8]  = (byte)((FileHeadInfo.DataStorageOffset >> 24) & 0xFF);
                array[9]  = (byte)(FileHeadInfo.DataSize & 0xFF);
                array[10] = (byte)((FileHeadInfo.DataSize >> 8) & 0xFF);
                array[11] = (byte)((FileHeadInfo.DataSize >> 16) & 0xFF);
                array[12] = (byte)((FileHeadInfo.DataSize >> 24) & 0xFF);
                for (int m = (int)FileHeadInfo.AppSize + Marshal.SizeOf(typeof(TFileHeadInfo)); m < (int)FileHeadInfo.AppSize + Marshal.SizeOf(typeof(TFileHeadInfo)) + FileHeadInfo.DataSize; m++)
                {
                    num2 += UpdateFileBuf[m];
                }
                array[13] = (byte)(num2 & 0xFF);
                array[14] = (byte)((num2 >> 8) & 0xFF);
                array[15] = (byte)((num2 >> 16) & 0xFF);
                array[16] = (byte)((num2 >> 24) & 0xFF);
                TxLen     = ConstructTxDataFrame(array, 17);
                break;
            }

            case CommCmd.AppCheckSum:
            {
                uint num = 0u;
                array[0]  = 246;
                array[1]  = 53;
                array[2]  = 0;
                array[3]  = (byte)(FileHeadInfo.AppStorageOffset & 0xFF);
                array[4]  = (byte)((FileHeadInfo.AppStorageOffset >> 8) & 0xFF);
                array[5]  = (byte)((FileHeadInfo.AppStorageOffset >> 16) & 0xFF);
                array[6]  = (byte)((FileHeadInfo.AppStorageOffset >> 24) & 0xFF);
                array[7]  = (byte)(FileHeadInfo.AppSize & 0xFF);
                array[8]  = (byte)((FileHeadInfo.AppSize >> 8) & 0xFF);
                array[9]  = (byte)((FileHeadInfo.AppSize >> 16) & 0xFF);
                array[10] = (byte)((FileHeadInfo.AppSize >> 24) & 0xFF);
                for (int l = Marshal.SizeOf(typeof(TFileHeadInfo)); l < (int)FileHeadInfo.AppSize + Marshal.SizeOf(typeof(TFileHeadInfo)); l += 4)
                {
                    num += BitConverter.ToUInt32(UpdateFileBuf, l);
                }
                array[11] = (byte)(num & 0xFF);
                array[12] = (byte)((num >> 8) & 0xFF);
                array[13] = (byte)((num >> 16) & 0xFF);
                array[14] = (byte)((num >> 24) & 0xFF);
                TxLen     = ConstructTxDataFrame(array, 15);
                break;
            }

            case CommCmd.RebootToApp:
                array[0] = 252;
                array[1] = 202;
                TxLen    = ConstructTxDataFrame(array, 2);
                break;

            case CommCmd.DeviceRename:
                array[0] = 192;
                for (int i = 0; i < renameArray.Length; i++)
                {
                    array[i + 1] = renameArray[i];
                }
                TxLen = ConstructTxDataFrame(array, 9);
                break;

            default:
                TxLen = 0;
                break;
            }
            if (TxLen != 0)
            {
                SendDataFrame();
            }
        }