public FormItem(DEVICETYPE type, String name, String mac)
 {
     InitializeComponent();
     this.type       = type;
     labelTitle.Text = name;
     labelMac.Text   = mac;
 }
Beispiel #2
0
        public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
        {
            bool flag = false;

            if (p_device_type == 2)
            {
                m_devicetype    = DEVICETYPE.LIN;
                m_upper_fw_addr = 0x4000;
            }
            else
            {
                m_devicetype    = DEVICETYPE.PKSA;
                m_upper_fw_addr = 0x8000;
            }
            m_array_size = m_upper_fw_addr - 0x2000;
            if (!parse_hex_file_put_in_array(p_file_name))
            {
                p_error_code = 1;
                p_error_str  = "Error - Could not read hex file - download aborted";
                return(flag);
            }
            if (!Force_PKS_Into_Prog_Mode_Cmd())
            {
                p_error_code = 2;
                p_error_str  = "Error - Could not enter programming mode prior to updating firmware - download aborted";
                return(flag);
            }
            bool flag2 = false;

            byte[] buffer = new byte[14];
            if (!Clear_BL_Flash())
            {
                flag2        = true;
                p_error_str  = "Error - clearing flash prior to writing firmware";
                p_error_code = 3;
            }
            else if (!Write_BL_Flash(ref m_flash_data_array))
            {
                p_error_str  = "Error - writing flash";
                flag2        = true;
                p_error_code = 4;
            }
            else if (!Bootloader.Write_BL_Config_Bytes(ref m_config_bytes_array, ref m_config_bool_array))
            {
                flag2        = true;
                p_error_str  = "Error - writing config bytes";
                p_error_code = 5;
            }
            else
            {
                copy_current_fw_array_into_prior_array();
                if (!Read_BL_Flash(0x2000, m_upper_fw_addr - 0x2000, ref m_flash_data_array))
                {
                    flag2        = true;
                    p_error_str  = "Error - reading flash.";
                    p_error_code = 6;
                }
                else
                {
                    for (int i = 0; i < m_array_size; i++)
                    {
                        if (m_flash_data_array[i] != m_prior_flash_data_array[i])
                        {
                            p_error_str  = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, m_flash_data_array[i], m_prior_flash_data_array[i]);
                            flag2        = true;
                            p_error_code = 8;
                            break;
                        }
                    }
                    if (Bootloader.Read_BL_Config_Data(ref buffer))
                    {
                        for (int j = 0; j < buffer.Length; j++)
                        {
                            if (m_config_bool_array[j] && (buffer[j] != m_config_bytes_array[j]))
                            {
                                p_error_str  = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, buffer[j], m_config_bytes_array[j]);
                                flag2        = true;
                                p_error_code = 9;
                                break;
                            }
                        }
                    }
                    else
                    {
                        flag2        = true;
                        p_error_str  = "Error - reading config bytes";
                        p_error_code = 7;
                    }
                }
            }
            if (!flag2)
            {
                if (m_devicetype == DEVICETYPE.LIN)
                {
                    p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
                }
                else
                {
                    p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
                }
                p_error_code = 0;
                flag         = true;
            }
            if (Bootloader.Issue_BL_Reset())
            {
                restart_the_device();
                return(flag);
            }
            p_error_code = 10;
            p_error_str  = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
            return(false);
        }
 public static extern bool freeDeviceList(DEVICETYPE type, IntPtr devList);
 public static extern IntPtr buildDeviceList(DEVICETYPE type);
 public static extern int buildDeviceNamesFind(DEVICETYPE type, [MarshalAs(UnmanagedType.LPStr)] string altName);
Beispiel #6
0
 public static bool Load_Firmware(string p_file_name, int p_device_type, ref string p_error_str, ref int p_error_code)
 {
     bool flag = false;
     if (p_device_type == 2)
     {
         m_devicetype = DEVICETYPE.LIN;
         m_upper_fw_addr = 0x4000;
     }
     else
     {
         m_devicetype = DEVICETYPE.PKSA;
         m_upper_fw_addr = 0x8000;
     }
     m_array_size = m_upper_fw_addr - 0x2000;
     if (!parse_hex_file_put_in_array(p_file_name))
     {
         p_error_code = 1;
         p_error_str = "Error - Could not read hex file - download aborted";
         return flag;
     }
     if (!Force_PKS_Into_Prog_Mode_Cmd())
     {
         p_error_code = 2;
         p_error_str = "Error - Could not enter programming mode prior to updating firmware - download aborted";
         return flag;
     }
     bool flag2 = false;
     byte[] buffer = new byte[14];
     if (!Clear_BL_Flash())
     {
         flag2 = true;
         p_error_str = "Error - clearing flash prior to writing firmware";
         p_error_code = 3;
     }
     else if (!Write_BL_Flash(ref m_flash_data_array))
     {
         p_error_str = "Error - writing flash";
         flag2 = true;
         p_error_code = 4;
     }
     else if (!Bootloader.Write_BL_Config_Bytes(ref m_config_bytes_array, ref m_config_bool_array))
     {
         flag2 = true;
         p_error_str = "Error - writing config bytes";
         p_error_code = 5;
     }
     else
     {
         copy_current_fw_array_into_prior_array();
         if (!Read_BL_Flash(0x2000, m_upper_fw_addr - 0x2000, ref m_flash_data_array))
         {
             flag2 = true;
             p_error_str = "Error - reading flash.";
             p_error_code = 6;
         }
         else
         {
             for (int i = 0; i < m_array_size; i++)
             {
                 if (m_flash_data_array[i] != m_prior_flash_data_array[i])
                 {
                     p_error_str = string.Format("Error - Verification error:  flash byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", i, m_flash_data_array[i], m_prior_flash_data_array[i]);
                     flag2 = true;
                     p_error_code = 8;
                     break;
                 }
             }
             if (Bootloader.Read_BL_Config_Data(ref buffer))
             {
                 for (int j = 0; j < buffer.Length; j++)
                 {
                     if (m_config_bool_array[j] && (buffer[j] != m_config_bytes_array[j]))
                     {
                         p_error_str = string.Format("Error - Verification error:  Config byte {0:X2} reads as {1:X2}\nbut should be {2:X2}\n", j, buffer[j], m_config_bytes_array[j]);
                         flag2 = true;
                         p_error_code = 9;
                         break;
                     }
                 }
             }
             else
             {
                 flag2 = true;
                 p_error_str = "Error - reading config bytes";
                 p_error_code = 7;
             }
         }
     }
     if (!flag2)
     {
         if (m_devicetype == DEVICETYPE.LIN)
         {
             p_error_str = string.Format("LIN firmware written and verified using hex file {0}.\n", p_file_name);
         }
         else
         {
             p_error_str = string.Format("PICkit Serial firmware written and verified using hex file {0}.\n", p_file_name);
         }
         p_error_code = 0;
         flag = true;
     }
     if (Bootloader.Issue_BL_Reset())
     {
         restart_the_device();
         return flag;
     }
     p_error_code = 10;
     p_error_str = "Error - sending BL Reset Command.  Firmware may not have been updated correctly.";
     return false;
 }
Beispiel #7
0
        //#region zBUTTONMATE属性


        //#endregion

        //#region zTC1属性
        //UInt32 zTC1power;   //功率
        //UInt32 zTC1total_time;  //运行时间
        //Boolean[] zTC1Switch = new Boolean[6] { false, false, false, false, false, false }; //开关状态
        //#endregion

        //#region zDC1属性
        //UInt32 zDC1total_time;  //运行时间
        //UInt16 zDC1power;   //功率
        //UInt16 zDC1voltage; //电压
        //UInt16 zDC1current; //电流
        //Boolean[] zDC1Switch = new Boolean[4] { false, false, false, false};//开关状态
        //#endregion

        //#region zA1属性

        //#endregion

        //#region zM1属性

        //#endregion



        public DeviceItem(DEVICETYPE type, String name, String mac)
        {
            this.name = name;
            this.type = type;
            this.mac  = mac;
        }