示例#1
0
        public static bool WriteTripGuardband(byte p_slave_addr, byte p_index, ushort p_trip, ushort p_guardband)
        {
            bool result = false;

            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = 14;
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = 8;
            array[6]  = p_slave_addr;
            array[7]  = 48;
            array[8]  = p_index;
            array[9]  = 1;
            array[10] = (byte)(p_trip >> 8);
            array[11] = (byte)p_trip;
            array[12] = (byte)(p_guardband >> 8);
            array[13] = (byte)p_guardband;
            array[14] = 130;
            array[15] = 31;
            array[16] = 119;
            array[17] = 0;
            USBRead.Clear_Data_Array(0u);
            USBRead.Clear_Raw_Data_Array();
            if (USBWrite.Send_Script_To_PICkitS(ref array))
            {
                result = true;
            }
            return(result);
        }
示例#2
0
        public static bool Write(byte p_slave_addr, uint p_mem_addr, byte p_num_bytes_to_write, ref byte[] p_data_array)
        {
            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = (byte)(12 + p_num_bytes_to_write);
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = (byte)(6 + p_num_bytes_to_write);
            array[6]  = p_slave_addr;
            array[7]  = 2;
            array[8]  = (byte)(p_mem_addr >> 16);
            array[9]  = (byte)(p_mem_addr >> 8);
            array[10] = (byte)p_mem_addr;
            array[11] = p_num_bytes_to_write;
            int i;

            for (i = 0; i < (int)p_num_bytes_to_write; i++)
            {
                array[i + 12] = p_data_array[i];
            }
            array[i + 12] = 130;
            array[i + 13] = 31;
            array[i + 14] = 119;
            array[i + 15] = 0;
            USBRead.Clear_Data_Array(0u);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#3
0
 internal static void reset_buffers()
 {
     USBRead.Clear_Data_Array(0u);
     USBRead.Clear_Raw_Data_Array();
     I2CS.m_last_slave_addr_received     = 512;
     I2CS.m_previous_slave_addr_received = 512;
 }
示例#4
0
        public static bool ReadBufferIsReady()
        {
            bool flag = false;

            byte[] array = new byte[300];
            byte   num   = 1;

            byte[] buffer2 = new byte[1];
            Array.Clear(array, 0, array.Length);
            array[0]    = 0;
            array[1]    = 3;
            array[2]    = 14;
            array[3]    = 0x81;
            array[4]    = 0x84;
            array[5]    = 2;
            array[6]    = 0x42;
            array[7]    = 0x88;
            array[8]    = 0x83;
            array[9]    = 0x84;
            array[10]   = 1;
            array[11]   = 0x43;
            array[12]   = 0x89;
            array[13]   = num;
            array[14]   = 130;
            array[15]   = 0x1f;
            array[0x10] = 0x77;
            array[0x11] = 0;
            USBRead.Clear_Data_Array(num);
            USBRead.Clear_Raw_Data_Array();
            if ((USBWrite.Send_Script_To_PICkitS(ref array) && Utilities.m_flags.g_data_arrived_event.WaitOne(50, false)) && (USBRead.Retrieve_Data(ref buffer2, num) && (buffer2[0] == 1)))
            {
                flag = true;
            }
            return(flag);
        }
示例#5
0
 internal static void reset_buffers()
 {
     USBRead.Clear_Data_Array(0);
     USBRead.Clear_Raw_Data_Array();
     m_last_slave_addr_received     = 0x200;
     m_previous_slave_addr_received = 0x200;
 }
示例#6
0
        public static bool Send_Bytes(byte p_num_bytes_to_write, ref byte[] p_data_array, ref string p_script_view)
        {
            if (p_num_bytes_to_write > 253)
            {
                return(false);
            }
            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(4 + p_num_bytes_to_write);
            array[3] = 193;
            array[4] = p_num_bytes_to_write;
            int i;

            for (i = 0; i < (int)p_num_bytes_to_write; i++)
            {
                array[i + 5] = p_data_array[i];
            }
            array[i + 5]  = 31;
            array[i + 6]  = 119;
            array[i + 7]  = 0;
            p_script_view = "[SB]";
            string text = string.Format("[{0:X2}]", array[4]);

            p_script_view += text;
            for (i = 0; i < (int)p_num_bytes_to_write; i++)
            {
                text           = string.Format("[{0:X2}]", array[i + 5]);
                p_script_view += text;
            }
            USBRead.Clear_Data_Array(0u);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#7
0
        public static bool Write(byte p_slave_addr, uint p_mem_addr, byte p_num_bytes_to_write, ref byte[] p_data_array)
        {
            int index = 0;

            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = (byte)(12 + p_num_bytes_to_write);
            array[3]  = 0x81;
            array[4]  = 0x84;
            array[5]  = (byte)(6 + p_num_bytes_to_write);
            array[6]  = p_slave_addr;
            array[7]  = 2;
            array[8]  = (byte)(p_mem_addr >> 0x10);
            array[9]  = (byte)(p_mem_addr >> 8);
            array[10] = (byte)p_mem_addr;
            array[11] = p_num_bytes_to_write;
            index     = 0;
            while (index < p_num_bytes_to_write)
            {
                array[index + 12] = p_data_array[index];
                index++;
            }
            array[index + 12] = 130;
            array[index + 13] = 0x1f;
            array[index + 14] = 0x77;
            array[index + 15] = 0;
            USBRead.Clear_Data_Array(0);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#8
0
 public static bool Read_Status(byte p_slave_addr, ref byte[] p_data_array)
 {
     byte[] array = new byte[300];
     Array.Clear(array, 0, array.Length);
     array[0]    = 0;
     array[1]    = 3;
     array[2]    = 14;
     array[3]    = 0x81;
     array[4]    = 0x84;
     array[5]    = 2;
     array[6]    = p_slave_addr;
     array[7]    = 5;
     array[8]    = 0x83;
     array[9]    = 0x84;
     array[10]   = 1;
     array[11]   = (byte)(p_slave_addr + 1);
     array[12]   = 0x89;
     array[13]   = 3;
     array[14]   = 130;
     array[15]   = 0x1f;
     array[0x10] = 0x77;
     array[0x11] = 0;
     USBRead.Clear_Data_Array(3);
     USBRead.Clear_Raw_Data_Array();
     return(USBWrite.Send_Script_To_PICkitS(ref array) && (Utilities.m_flags.g_data_arrived_event.WaitOne(Basic.m_i2cs_read_wait_time, false) && USBRead.Retrieve_Data(ref p_data_array, 3)));
 }
示例#9
0
        public static bool Send_I2CRead_Word_Cmd(byte p_slave_addr, byte p_command1, byte p_command2, byte p_num_bytes_to_read, ref byte[] p_data_array, ref string p_script_view)
        {
            if (p_num_bytes_to_read == 0)
            {
                return(false);
            }
            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0]      = 0;
            array[1]      = 3;
            array[2]      = 15;
            array[3]      = 129;
            array[4]      = 132;
            array[5]      = 3;
            array[6]      = p_slave_addr;
            array[7]      = p_command1;
            array[8]      = p_command2;
            array[9]      = 131;
            array[10]     = 132;
            array[11]     = 1;
            array[12]     = (byte)(p_slave_addr + 1);
            array[13]     = 137;
            array[14]     = p_num_bytes_to_read;
            array[15]     = 130;
            array[16]     = 31;
            array[17]     = 119;
            array[18]     = 0;
            p_script_view = "[S_][W_][03]";
            string text = string.Format("[{0:X2}]", array[6]);

            p_script_view += text;
            text           = string.Format("[{0:X2}]", array[7]);
            p_script_view += text;
            text           = string.Format("[{0:X2}]", array[8]);
            p_script_view += text;
            p_script_view += "[RS][W_][01]";
            text           = string.Format("[{0:X2}]", array[12]);
            p_script_view += text;
            p_script_view += "[RN]";
            text           = string.Format("[{0:X2}]", array[14]);
            p_script_view += text;
            p_script_view += "[P_]";
            USBRead.Clear_Data_Array((uint)p_num_bytes_to_read);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);
            bool result;

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(Basic.m_i2cs_read_wait_time, false);
                result = (flag2 && USBRead.Retrieve_Data(ref p_data_array, (uint)p_num_bytes_to_read));
            }
            else
            {
                result = false;
            }
            return(result);
        }
示例#10
0
        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));
        }
示例#11
0
        public static bool Retrieve_Data(uint p_byte_count, ref byte[] p_data_array)
        {
            bool flag = false;

            if (USBRead.Retrieve_Data(ref p_data_array, p_byte_count))
            {
                flag = true;
            }
            return(flag);
        }
示例#12
0
        public static bool Retrieve_USART_Data(uint p_byte_count, ref byte[] p_data_array)
        {
            bool result = false;

            if (USBRead.Retrieve_Data(ref p_data_array, p_byte_count))
            {
                result = true;
            }
            return(result);
        }
示例#13
0
        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));
        }
示例#14
0
        public static bool Send_And_Receive_Data(byte p_byte_count, ref byte[] p_send_data_array, ref byte[] p_receive_data_array, bool p_assert_cs, bool p_de_assert_cs, ref string p_script_view)
        {
            bool result = false;

            byte[] array = new byte[255];
            int    num   = 3;

            p_script_view = "";
            if (p_byte_count > 245)
            {
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            if (p_assert_cs)
            {
                array[num++]  = 139;
                p_script_view = "[CSON]";
            }
            array[num++]   = 134;
            array[num++]   = p_byte_count;
            p_script_view += "[DIO]";
            string text = string.Format("[{0:X2}]", p_byte_count);

            p_script_view += text;
            for (int i = 0; i < (int)p_byte_count; i++)
            {
                array[num++]   = p_send_data_array[i];
                text           = string.Format("[{0:X2}]", p_send_data_array[i]);
                p_script_view += text;
            }
            if (p_de_assert_cs)
            {
                array[num++]   = 140;
                p_script_view += "[CSOF]";
            }
            array[2]     = (byte)(num - 1);
            array[num++] = 31;
            array[num++] = 119;
            array[num]   = 0;
            USBRead.Clear_Data_Array((uint)p_byte_count);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(Basic.m_spi_receive_wait_time, false);
                if (flag2 && USBRead.Retrieve_Data(ref p_receive_data_array, (uint)p_byte_count))
                {
                    result = true;
                }
            }
            return(result);
        }
示例#15
0
        public static bool Send_And_Receive_Data(byte p_byte_count, ref byte[] p_send_data_array, ref byte[] p_receive_data_array, bool p_assert_cs, bool p_de_assert_cs, ref string p_script_view)
        {
            bool flag = false;

            byte[] array = new byte[0xff];
            int    index = 3;
            int    num2  = 0;

            p_script_view = "";
            string str = "";

            if (p_byte_count > 0xf5)
            {
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            if (p_assert_cs)
            {
                array[index++] = 0x8b;
                p_script_view  = "[CSON]";
            }
            array[index++] = 0x86;
            array[index++] = p_byte_count;
            p_script_view  = p_script_view + "[DIO]";
            str            = string.Format("[{0:X2}]", p_byte_count);
            p_script_view  = p_script_view + str;
            for (num2 = 0; num2 < p_byte_count; num2++)
            {
                array[index++] = p_send_data_array[num2];
                str            = string.Format("[{0:X2}]", p_send_data_array[num2]);
                p_script_view  = p_script_view + str;
            }
            if (p_de_assert_cs)
            {
                array[index++] = 140;
                p_script_view  = p_script_view + "[CSOF]";
            }
            array[2]       = (byte)(index - 1);
            array[index++] = 0x1f;
            array[index++] = 0x77;
            array[index]   = 0;
            USBRead.Clear_Data_Array(p_byte_count);
            USBRead.Clear_Raw_Data_Array();
            if ((USBWrite.Send_Script_To_PICkitS(ref array) && Utilities.m_flags.g_data_arrived_event.WaitOne(Basic.m_spi_receive_wait_time, false)) && USBRead.Retrieve_Data(ref p_receive_data_array, p_byte_count))
            {
                flag = true;
            }
            return(flag);
        }
示例#16
0
        public static bool Update_Status_Packet()
        {
            bool flag = false;

            if ((Utilities.m_flags.HID_read_handle != IntPtr.Zero) && USBRead.Read_Thread_Is_Active())
            {
                Utilities.m_flags.g_status_packet_data_update_event.Reset();
                if (Send_Status_Request() && Utilities.m_flags.g_status_packet_data_update_event.WaitOne(0x7d0, false))
                {
                    flag = true;
                }
            }
            return(flag);
        }
示例#17
0
        public static bool Send_I2CWrite_Word_Cmd(byte p_slave_addr, byte p_command1, byte p_command2, byte p_num_bytes_to_write, ref byte[] p_data_array, ref string p_script_view)
        {
            if (p_num_bytes_to_write > 0xfd)
            {
                return(false);
            }
            int index = 0;

            byte[] array = new byte[300];
            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_command1;
            array[8] = p_command2;
            index    = 0;
            while (index < p_num_bytes_to_write)
            {
                array[index + 9] = p_data_array[index];
                index++;
            }
            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;
            str           = string.Format("[{0:X2}]", array[8]);
            p_script_view = p_script_view + str;
            for (index = 0; index < p_num_bytes_to_write; index++)
            {
                str           = string.Format("[{0:X2}]", array[index + 9]);
                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));
        }
示例#18
0
 public static bool Send_I2CRead_Word_Cmd(byte p_slave_addr, byte p_command1, byte p_command2, byte p_num_bytes_to_read, ref byte[] p_data_array, ref string p_script_view)
 {
     if (p_num_bytes_to_read != 0)
     {
         byte[] array = new byte[300];
         Array.Clear(array, 0, array.Length);
         array[0]      = 0;
         array[1]      = 3;
         array[2]      = 15;
         array[3]      = 0x81;
         array[4]      = 0x84;
         array[5]      = 3;
         array[6]      = p_slave_addr;
         array[7]      = p_command1;
         array[8]      = p_command2;
         array[9]      = 0x83;
         array[10]     = 0x84;
         array[11]     = 1;
         array[12]     = (byte)(p_slave_addr + 1);
         array[13]     = 0x89;
         array[14]     = p_num_bytes_to_read;
         array[15]     = 130;
         array[0x10]   = 0x1f;
         array[0x11]   = 0x77;
         array[0x12]   = 0;
         p_script_view = "[S_][W_][03]";
         string 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;
         str           = string.Format("[{0:X2}]", array[8]);
         p_script_view = p_script_view + str;
         p_script_view = p_script_view + "[RS][W_][01]";
         str           = string.Format("[{0:X2}]", array[12]);
         p_script_view = p_script_view + str;
         p_script_view = p_script_view + "[RN]";
         str           = string.Format("[{0:X2}]", array[14]);
         p_script_view = p_script_view + str;
         p_script_view = p_script_view + "[P_]";
         USBRead.Clear_Data_Array(p_num_bytes_to_read);
         USBRead.Clear_Raw_Data_Array();
         if (USBWrite.Send_Script_To_PICkitS(ref array))
         {
             return(Utilities.m_flags.g_data_arrived_event.WaitOne(m_i2cs_read_wait_time, false) && USBRead.Retrieve_Data(ref p_data_array, p_num_bytes_to_read));
         }
     }
     return(false);
 }
示例#19
0
        public static bool Send_I2CWrite_Word_Cmd(byte p_slave_addr, byte p_command1, byte p_command2, byte p_num_bytes_to_write, ref byte[] p_data_array, ref string p_script_view)
        {
            if (p_num_bytes_to_write > 253)
            {
                return(false);
            }
            byte[] array = new byte[300];
            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_command1;
            array[8] = p_command2;
            int i;

            for (i = 0; i < (int)p_num_bytes_to_write; i++)
            {
                array[i + 9] = p_data_array[i];
            }
            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;
            text           = string.Format("[{0:X2}]", array[8]);
            p_script_view += text;
            for (i = 0; i < (int)p_num_bytes_to_write; i++)
            {
                text           = string.Format("[{0:X2}]", array[i + 9]);
                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));
        }
示例#20
0
        public static bool ReadRawAvg(byte p_slave_addr, byte p_index, byte p_num_sensors, ref byte[] p_data_array)
        {
            bool result = false;

            byte[] array = new byte[300];
            byte   b     = (byte)(p_num_sensors * 4);

            if (p_num_sensors * 4 > 255)
            {
                return(result);
            }
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = 16;
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = 4;
            array[6]  = p_slave_addr;
            array[7]  = 3;
            array[8]  = p_index;
            array[9]  = p_num_sensors;
            array[10] = 131;
            array[11] = 132;
            array[12] = 1;
            array[13] = (byte)(p_slave_addr + 1);
            array[14] = 137;
            array[15] = b;
            array[16] = 130;
            array[17] = 31;
            array[18] = 119;
            array[19] = 0;
            USBRead.Clear_Data_Array((uint)b);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(200, false);
                if (flag2 && USBRead.Retrieve_Data(ref p_data_array, (uint)b))
                {
                    result = true;
                }
            }
            return(result);
        }
示例#21
0
        public static bool SelectKeypad(byte p_selection)
        {
            bool result = false;

            byte[] array = new byte[300];
            byte   b     = 1;

            byte[] array2 = new byte[1];
            Array.Clear(array, 0, array.Length);
            if (p_selection > 1)
            {
                return(result);
            }
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = 15;
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = 3;
            array[6]  = 66;
            array[7]  = 130;
            array[8]  = p_selection;
            array[9]  = 131;
            array[10] = 132;
            array[11] = 1;
            array[12] = 67;
            array[13] = 137;
            array[14] = b;
            array[15] = 130;
            array[16] = 31;
            array[17] = 119;
            array[18] = 0;
            USBRead.Clear_Data_Array((uint)b);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(50, false);
                if (flag2 && USBRead.Retrieve_Data(ref array2, (uint)b) && array2[0] == p_selection)
                {
                    result = true;
                }
            }
            return(result);
        }
示例#22
0
        public static bool Send_SPI_Receive_Cmd(byte p_num_bytes_to_read, ref byte[] p_data_array, bool p_first_cmd, bool p_last_cmd, ref string p_script_view)
        {
            bool result = false;

            byte[] array = new byte[255];
            int    num   = 3;

            p_script_view = "";
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            if (p_first_cmd)
            {
                array[num++]  = 139;
                p_script_view = "[CSON]";
            }
            array[num++]   = 132;
            array[num++]   = p_num_bytes_to_read;
            p_script_view += "[DI]";
            string text = string.Format("[{0:X2}]", p_num_bytes_to_read);

            p_script_view += text;
            if (p_last_cmd)
            {
                array[num++]   = 140;
                p_script_view += "[CSOF]";
            }
            array[2]     = (byte)(num - 1);
            array[num++] = 31;
            array[num++] = 119;
            array[num]   = 0;
            USBRead.Clear_Data_Array((uint)p_num_bytes_to_read);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(Basic.m_spi_receive_wait_time, false);
                if (flag2 && USBRead.Retrieve_Data(ref p_data_array, (uint)p_num_bytes_to_read))
                {
                    result = true;
                }
            }
            return(result);
        }
示例#23
0
        public static bool Update_Status_Packet()
        {
            bool result = false;

            if ((Utilities.m_flags.HID_DeviceReady != false) && USBRead.Read_Thread_Is_Active())
            {
                Utilities.m_flags.g_status_packet_data_update_event.Reset();
                if (USBWrite.Send_Status_Request())
                {
                    bool flag = Utilities.m_flags.g_status_packet_data_update_event.WaitOne(2000, false);
                    if (flag)
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
示例#24
0
        public static bool Send_SPI_Send_Cmd(byte p_byte_count, ref byte[] p_data, bool p_first_cmd, bool p_last_cmd, ref string p_script_view)
        {
            byte[] array = new byte[0xff];
            int    index = 3;
            int    num2  = 0;
            string str   = "";

            if (p_byte_count > 0xf6)
            {
                return(false);
            }
            p_script_view = "";
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            if (p_first_cmd)
            {
                array[index++] = 0x8b;
                p_script_view  = "[CSON]";
            }
            array[index++] = 0x85;
            array[index++] = p_byte_count;
            p_script_view  = p_script_view + "[DO]";
            str            = string.Format("[{0:X2}]", p_byte_count);
            p_script_view  = p_script_view + str;
            for (num2 = 0; num2 < p_byte_count; num2++)
            {
                array[index++] = p_data[num2];
                str            = string.Format("[{0:X2}]", p_data[num2]);
                p_script_view  = p_script_view + str;
            }
            if (p_last_cmd)
            {
                array[index++] = 140;
                p_script_view  = p_script_view + "[CSOF]";
            }
            array[2]       = (byte)(index - 1);
            array[index++] = 0x1f;
            array[index++] = 0x77;
            array[index]   = 0;
            USBRead.Clear_Data_Array(0);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#25
0
        public static bool Find_ThisDevice(ushort VendorID, ushort ProductID)
        {
            IntPtr zero  = IntPtr.Zero;
            IntPtr zero2 = IntPtr.Zero;
            Guid   empty = Guid.Empty;
            string text  = "";
            ushort num   = 0;
            bool   flag  = USB.Get_This_Device(VendorID, ProductID, 0, ref zero, ref zero2, ref text, false, ref empty, ref num);

            if (flag)
            {
                flag = USBRead.Kick_Off_Read_Thread();
                if (flag)
                {
                    flag = USBWrite.kick_off_write_thread();
                }
            }
            return(flag);
        }
示例#26
0
        public static bool Send_SPI_Send_Cmd(byte p_byte_count, ref byte[] p_data, bool p_first_cmd, bool p_last_cmd, ref string p_script_view)
        {
            byte[] array = new byte[255];
            int    num   = 3;

            if (p_byte_count > 246)
            {
                return(false);
            }
            p_script_view = "";
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            if (p_first_cmd)
            {
                array[num++]  = 139;
                p_script_view = "[CSON]";
            }
            array[num++]   = 133;
            array[num++]   = p_byte_count;
            p_script_view += "[DO]";
            string text = string.Format("[{0:X2}]", p_byte_count);

            p_script_view += text;
            for (int i = 0; i < (int)p_byte_count; i++)
            {
                array[num++]   = p_data[i];
                text           = string.Format("[{0:X2}]", p_data[i]);
                p_script_view += text;
            }
            if (p_last_cmd)
            {
                array[num++]   = 140;
                p_script_view += "[CSOF]";
            }
            array[2]     = (byte)(num - 1);
            array[num++] = 31;
            array[num++] = 119;
            array[num]   = 0;
            USBRead.Clear_Data_Array(0u);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#27
0
 internal static void issue_event()
 {
     if (Utilities.g_i2cs_mode == Utilities.I2CS_MODE.INTERACTIVE)
     {
         bool flag = false;
         if (((m_last_slave_addr_received == (m_previous_slave_addr_received + 1)) && m_master_is_waiting_for_data) && !m_stop_command_issued)
         {
             issue_read_command();
             flag = true;
         }
         else if (((m_previous_slave_addr_received == 0x200) && ((m_last_slave_addr_received % 2) != 0)) && (m_master_is_waiting_for_data && !m_stop_command_issued))
         {
             issue_receive_command();
             flag = true;
         }
         else if (((m_previous_slave_addr_received == 0x200) && ((m_last_slave_addr_received % 2) == 0)) && (!m_master_is_waiting_for_data && m_stop_command_issued))
         {
             issue_write_command();
             flag = true;
         }
         else if ((((m_last_slave_addr_received != (m_previous_slave_addr_received + 1)) && !m_master_is_waiting_for_data) && ((m_previous_slave_addr_received != 0x200) && m_slave_address_was_just_set)) && !m_stop_command_issued)
         {
             issue_write_command();
             USBRead.Clear_Data_Array(0);
             USBRead.Clear_Raw_Data_Array();
             flag = true;
         }
         else if ((((m_previous_slave_addr_received != 0x200) && (m_last_slave_addr_received != (m_previous_slave_addr_received + 1))) && (((m_last_slave_addr_received % 2) != 0) && m_slave_address_was_just_set)) && !m_stop_command_issued)
         {
             issue_read_command();
             USBRead.Clear_Data_Array(0);
             USBRead.Clear_Raw_Data_Array();
             flag = true;
         }
         else if (((m_previous_slave_addr_received != 0x200) && ((m_last_slave_addr_received % 2) == 0)) && (m_slave_address_was_just_set && !m_stop_command_issued))
         {
             issue_receive_command();
             USBRead.Clear_Data_Array(0);
             USBRead.Clear_Raw_Data_Array();
             flag = true;
         }
     }
 }
示例#28
0
 public static void Cleanup()
 {
     if (USBRead.Read_Thread_Is_Active())
     {
         USBRead.Kill_Read_Thread();
         Thread.Sleep(500);
     }
     USBWrite.Kill_Write_Thread();
     USBWrite.Dispose_Of_Write_Objects();
     Utilities.CloseHandle(Utilities.m_flags.HID_write_handle);
     Utilities.CloseHandle(Utilities.m_flags.HID_read_handle);
     Utilities.m_flags.g_status_packet_data_update_event.Close();
     Utilities.m_flags.g_data_arrived_event.Close();
     Utilities.m_flags.g_bl_data_arrived_event.Close();
     Utilities.m_flags.g_status_packet_mutex.Close();
     Utilities.m_flags.g_PKSA_has_completed_script.Close();
     USBRead.m_usb_packet_mutex.Close();
     USBRead.m_cbuf2_data_array_mutex.Close();
 }
示例#29
0
        public static bool LCD_Write(byte p_slave_addr, byte p_LCD, string p_text)
        {
            byte num;

            if (p_text.Length != 0x10)
            {
                return(false);
            }
            if (p_LCD == 1)
            {
                num = 0x10;
            }
            else
            {
                num = 0x11;
            }
            int num2 = 0;

            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = 0x18;
            array[3] = 0x81;
            array[4] = 0x84;
            array[5] = 0x12;
            array[6] = p_slave_addr;
            array[7] = num;
            num2     = 0;
            while (num2 < 0x10)
            {
                array[num2 + 8] = Convert.ToByte(p_text[num2]);
                num2++;
            }
            array[num2 + 8]  = 130;
            array[num2 + 9]  = 0x1f;
            array[num2 + 10] = 0x77;
            array[num2 + 11] = 0;
            USBRead.Clear_Data_Array(0);
            USBRead.Clear_Raw_Data_Array();
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
示例#30
0
        public static bool ReadFirmwareOptions(byte p_slave_addr, ref byte p_options)
        {
            bool result = false;

            byte[] array = new byte[300];
            byte   b     = 1;

            byte[] array2 = new byte[1];
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = 14;
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = 2;
            array[6]  = p_slave_addr;
            array[7]  = 148;
            array[8]  = 131;
            array[9]  = 132;
            array[10] = 1;
            array[11] = (byte)(p_slave_addr + 1);
            array[12] = 137;
            array[13] = b;
            array[14] = 130;
            array[15] = 31;
            array[16] = 119;
            array[17] = 0;
            USBRead.Clear_Data_Array((uint)b);
            USBRead.Clear_Raw_Data_Array();
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = Utilities.m_flags.g_data_arrived_event.WaitOne(50, false);
                if (flag2 && USBRead.Retrieve_Data(ref array2, (uint)b))
                {
                    result    = true;
                    p_options = array2[0];
                }
            }
            return(result);
        }