public Result API_UpdataSendUpdateData( Updatedata r_strcData ) { #if _TRACE_OUT_PUT PrintMagToTxt("API_UpdataSendUpdateData"); #endif Result result = Result.OK; ENUM_CMD TxCmd = ENUM_CMD.NOTHING; byte[] buf = new byte[57]; Array.Clear(buf, 0, buf.Length); TxCmd = ENUM_CMD.UPDAUE_SEND_UPDATE_DATA; buf[0] = 0x0D; //Magic buf[1] = 0xF0; //Magic buf[2] = (byte)( (int)TxCmd & 0xF );//command; buf[3] = 0; //command buf[4] = (byte)( r_strcData.usSize & 0xFF); //Length buf[5] = (byte)( (r_strcData.usSize >> 8 ) & 0xFF); //Length buf[6] = 0; //Reserved buf[7] = 0; //Reserved //Data======== //Addr buf[8] = (byte)( r_strcData.uiOffset & 0xFF ); buf[9] = (byte)( (r_strcData.uiOffset >> 8) & 0xFF ); buf[10] = (byte)( (r_strcData.uiOffset >> 16) & 0xFF ); buf[11] = (byte)( (r_strcData.uiOffset >> 24) & 0xFF ); //Flag buf[16] = (byte)( r_strcData.bRealRunFlag == true ? 0 : 1 ); //Flag = 1 => Test mode //Data Array.Copy( r_strcData.btData, 0, buf, 20, r_strcData.btData.Length ); //CRC uint uiCrc = 0; uiCrc = API_OtherCrc32( API_OtherCrc32( uiCrc, buf, 0, 12 ), buf, 16, (uint)(r_strcData.usSize-2)*4 ); buf[12] = (byte)( uiCrc & 0xFF ); buf[13] = (byte)( (uiCrc >> 8) & 0xFF ); buf[14] = (byte)( (uiCrc >> 16) & 0xFF ); buf[15] = (byte)( (uiCrc >> 24) & 0xFF ); if ( false == this.SendData(buf) ) return Result.FAILURE; Array.Clear(buf, 0, buf.Length); //Check receive data if ( false == this.ReceiveData( TxCmd, ref buf ) ) return Result.FAILURE; //Check result result = ConvertResult(buf[4]); if (Result.OK != result) return result; return Result.OK; }
public Result API_UpdataSendUpdateData ( Updatedata r_strcData ) { #if _TRACE_OUT_PUT PrintMagToTxt("API_UpdataSendUpdateData"); #endif Result result = Result.OK; ENUM_CMD TxCmd = ENUM_CMD.NOTHING; byte[] buf = new byte[57]; Array.Clear(buf, 0, buf.Length); TxCmd = ENUM_CMD.UPDAUE_SEND_UPDATE_DATA; buf[0] = 0x0D; //Magic buf[1] = 0xF0; //Magic buf[2] = (byte)((int)TxCmd & 0xF); //command; buf[3] = 0; //command buf[4] = (byte)(r_strcData.usSize & 0xFF); //Length buf[5] = (byte)((r_strcData.usSize >> 8) & 0xFF); //Length buf[6] = 0; //Reserved buf[7] = 0; //Reserved //Data======== //Addr buf[8] = (byte)(r_strcData.uiOffset & 0xFF); buf[9] = (byte)((r_strcData.uiOffset >> 8) & 0xFF); buf[10] = (byte)((r_strcData.uiOffset >> 16) & 0xFF); buf[11] = (byte)((r_strcData.uiOffset >> 24) & 0xFF); //Flag buf[16] = (byte)(r_strcData.bRealRunFlag == true ? 0 : 1); //Flag = 1 => Test mode //Data Array.Copy(r_strcData.btData, 0, buf, 20, r_strcData.btData.Length); //CRC uint uiCrc = 0; uiCrc = API_OtherCrc32(API_OtherCrc32(uiCrc, buf, 0, 12), buf, 16, (uint)(r_strcData.usSize - 2) * 4); buf[12] = (byte)(uiCrc & 0xFF); buf[13] = (byte)((uiCrc >> 8) & 0xFF); buf[14] = (byte)((uiCrc >> 16) & 0xFF); buf[15] = (byte)((uiCrc >> 24) & 0xFF); if (false == this.SendData(buf)) { return(Result.FAILURE); } Array.Clear(buf, 0, buf.Length); //Check receive data if (false == this.ReceiveData(TxCmd, ref buf)) { return(Result.FAILURE); } //Check result result = ConvertResult(buf[4]); if (Result.OK != result) { return(result); } return(Result.OK); }