public static bool Write_Using_PEC(byte p_slave_addr, byte p_start_data_addr, byte p_num_bytes_to_write, ref byte[] p_data_array, ref byte p_PEC, ref string p_script_view) { if (p_num_bytes_to_write > 0xfd) { return(false); } int index = 0; byte[] array = new byte[300]; byte num2 = 0; num2 = Utilities.calculate_crc8(p_slave_addr, num2); num2 = Utilities.calculate_crc8(p_start_data_addr, num2); for (index = 0; index < p_num_bytes_to_write; index++) { num2 = Utilities.calculate_crc8(p_data_array[index], num2); } Array.Clear(array, 0, array.Length); array[0] = 0; array[1] = 3; array[2] = (byte)(9 + p_num_bytes_to_write); array[3] = 0x81; array[4] = 0x84; array[5] = (byte)(3 + p_num_bytes_to_write); array[6] = p_slave_addr; array[7] = p_start_data_addr; index = 0; while (index < p_num_bytes_to_write) { array[index + 8] = p_data_array[index]; index++; } array[index + 8] = num2; array[index + 9] = 130; array[index + 10] = 0x1f; array[index + 11] = 0x77; array[index + 12] = 0; p_script_view = "[S_][W_]"; string str = string.Format("[{0:X2}]", array[5]); p_script_view = p_script_view + str; str = string.Format("[{0:X2}]", array[6]); p_script_view = p_script_view + str; str = string.Format("[{0:X2}]", array[7]); p_script_view = p_script_view + str; for (index = 0; index < p_num_bytes_to_write; index++) { str = string.Format("[{0:X2}]", array[index + 8]); p_script_view = p_script_view + str; } str = string.Format("[{0:X2}]", num2); p_script_view = p_script_view + str; p_script_view = p_script_view + "[P_]"; USBRead.Clear_Data_Array(0); USBRead.Clear_Raw_Data_Array(); return(USBWrite.Send_Script_To_PICkitS(ref array)); }
public static bool Write_Using_PEC(byte p_slave_addr, byte p_start_data_addr, byte p_num_bytes_to_write, ref byte[] p_data_array, ref byte p_PEC, ref string p_script_view) { if (p_num_bytes_to_write > 253) { return(false); } byte[] array = new byte[300]; byte b = 0; b = Utilities.calculate_crc8(p_slave_addr, b); b = Utilities.calculate_crc8(p_start_data_addr, b); int i; for (i = 0; i < (int)p_num_bytes_to_write; i++) { b = Utilities.calculate_crc8(p_data_array[i], b); } Array.Clear(array, 0, array.Length); array[0] = 0; array[1] = 3; array[2] = (byte)(9 + p_num_bytes_to_write); array[3] = 129; array[4] = 132; array[5] = (byte)(3 + p_num_bytes_to_write); array[6] = p_slave_addr; array[7] = p_start_data_addr; for (i = 0; i < (int)p_num_bytes_to_write; i++) { array[i + 8] = p_data_array[i]; } array[i + 8] = b; array[i + 9] = 130; array[i + 10] = 31; array[i + 11] = 119; array[i + 12] = 0; p_script_view = "[S_][W_]"; string text = string.Format("[{0:X2}]", array[5]); p_script_view += text; text = string.Format("[{0:X2}]", array[6]); p_script_view += text; text = string.Format("[{0:X2}]", array[7]); p_script_view += text; for (i = 0; i < (int)p_num_bytes_to_write; i++) { text = string.Format("[{0:X2}]", array[i + 8]); p_script_view += text; } text = string.Format("[{0:X2}]", b); p_script_view += text; p_script_view += "[P_]"; USBRead.Clear_Data_Array(0u); USBRead.Clear_Raw_Data_Array(); return(USBWrite.Send_Script_To_PICkitS(ref array)); }