Пример #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
        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));
        }
Пример #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
        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));
        }
Пример #6
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)));
 }
Пример #7
0
        public static bool Configure_PICkitSerial_For_I2CSlave_Auto_Mode(byte p_slave_addr, byte p_slave_mask, byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str)
        {
            byte[] array  = new byte[65];
            byte[] array2 = new byte[255];
            byte[] array3 = new byte[65];
            bool   result = false;
            string text   = "";

            Array.Clear(array, 0, array.Length);
            Array.Clear(array3, 0, array3.Length);
            Mode.update_status_packet_data(7, ref array3);
            array3[23] = 2;
            array3[29] = p_slave_addr;
            array3[30] = p_slave_mask;
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            USBWrite.Send_Cold_Reset_Cmd();
            bool flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);

            Array.Clear(array2, 0, array2.Length);
            array2[0] = 0;
            array2[1] = 5;
            array2[2] = p_array_byte_count;
            for (int i = 3; i < (int)(p_array_byte_count + 3); i++)
            {
                array2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref array2);
            USBWrite.Send_Warm_Reset_Cmd();
            if (flag)
            {
                if (USBWrite.Update_Status_Packet())
                {
                    Utilities.m_flags.g_status_packet_mutex.WaitOne();
                    int j;
                    for (j = 7; j < 31; j++)
                    {
                        if (Constants.STATUS_PACKET_DATA[j] != array[j - 5])
                        {
                            p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", j - 7, Constants.STATUS_PACKET_DATA[j], array[j - 5]);
                            break;
                        }
                    }
                    if (j == 31)
                    {
                        result       = true;
                        p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
                    }
                    Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
                }
                else
                {
                    p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                }
            }
            else
            {
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
            }
            return(result);
        }
Пример #8
0
        public static bool Send_Data(byte p_byte_count, ref byte[] p_data_array, ref string p_script_view)
        {
            byte[] array = new byte[310];
            int    index = 5;
            int    num2  = 0;
            string str   = "";

            p_script_view = "";
            if (p_byte_count > 0xfb)
            {
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(p_byte_count + 4);
            array[3] = 130;
            array[4] = p_byte_count;
            str      = string.Format("[{0:X2}]", p_byte_count);
            for (num2 = 0; num2 < p_byte_count; num2++)
            {
                array[index++] = p_data_array[num2];
                str            = string.Format("[{0:X2}]", p_data_array[num2]);
                p_script_view  = p_script_view + str;
            }
            array[index++] = 0x1f;
            array[index++] = 0x77;
            array[index]   = 0;
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
Пример #9
0
        public static bool WriteDefaultSettings()
        {
            bool result = false;

            byte[] array = new byte[300];
            Array.Clear(array, 0, array.Length);
            array[0]  = 0;
            array[1]  = 3;
            array[2]  = 8;
            array[3]  = 129;
            array[4]  = 132;
            array[5]  = 2;
            array[6]  = 66;
            array[7]  = 146;
            array[8]  = 130;
            array[9]  = 31;
            array[10] = 119;
            array[11] = 0;
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                result = true;
            }
            return(result);
        }
Пример #10
0
        public static bool Send_USART_Cmd(byte p_byte_count, ref byte[] p_data, ref string p_script_view)
        {
            byte[] array = new byte[255];
            int    num   = 5;

            p_script_view = "";
            if (p_byte_count > 247)
            {
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(p_byte_count + 4);
            array[3] = 130;
            array[4] = p_byte_count;
            string text = string.Format("[{0:X2}]", p_byte_count);

            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;
            }
            array[num++] = 31;
            array[num++] = 119;
            array[num]   = 0;
            return(USBWrite.Send_Script_To_PICkitS(ref array));
        }
Пример #11
0
        public static bool Configure_PICkitSerial_For_I2CSlave_Auto_Mode(byte p_slave_addr, byte p_slave_mask, byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str)
        {
            bool flag = false;

            byte[] array   = new byte[0x41];
            byte[] buffer2 = new byte[0xff];
            byte[] buffer3 = new byte[0x41];
            bool   flag2   = false;
            string str     = "";
            int    index   = 0;

            Array.Clear(array, 0, array.Length);
            Array.Clear(buffer3, 0, buffer3.Length);
            Mode.update_status_packet_data(7, ref buffer3);
            buffer3[0x17] = 2;
            buffer3[0x1d] = p_slave_addr;
            buffer3[30]   = p_slave_mask;
            USBWrite.configure_outbound_control_block_packet(ref array, ref str, ref buffer3);
            USBWrite.Send_Cold_Reset_Cmd();
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            Array.Clear(buffer2, 0, buffer2.Length);
            buffer2[0] = 0;
            buffer2[1] = 5;
            buffer2[2] = p_array_byte_count;
            for (int i = 3; i < (p_array_byte_count + 3); i++)
            {
                buffer2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref buffer2);
            USBWrite.Send_Warm_Reset_Cmd();
            if (!flag)
            {
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            if (!USBWrite.Update_Status_Packet())
            {
                p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                return(flag2);
            }
            Utilities.m_flags.g_status_packet_mutex.WaitOne();
            index = 7;
            while (index < 0x1f)
            {
                if (Constants.STATUS_PACKET_DATA[index] != array[index - 5])
                {
                    p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", index - 7, Constants.STATUS_PACKET_DATA[index], array[index - 5]);
                    break;
                }
                index++;
            }
            if (index == 0x1f)
            {
                flag2        = true;
                p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
            }
            Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
            return(flag2);
        }
Пример #12
0
        public static bool Transmit(byte MasterID, byte[] Data, byte DataByteCount, ref string ErrorString)
        {
            bool flag = false;

            byte[] array = new byte[30];
            Array.Clear(array, 0, array.Length);
            if (DataByteCount > 9)
            {
                ErrorString = "DataByteCount cannot exceed 9.";
                return(flag);
            }
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(DataByteCount + 5);
            array[3] = 132;
            array[4] = (byte)(DataByteCount + 1);
            array[5] = MasterID;
            array[6] = 31;
            array[7] = 119;
            array[8] = 0;
            if (DataByteCount == 0)
            {
                LIN.m_working_frame.BuildState.transmit_data_byte_count_zero = true;
                LIN.m_working_frame.BuildState.we_have_transmitted           = true;
                LIN.m_working_frame_is_done.Reset();
                flag = USBWrite.Send_Script_To_PICkitS(ref array);
                if (!flag)
                {
                    ErrorString = "Error sending script.";
                    return(false);
                }
                if (!LIN.m_working_frame_is_done.WaitOne(6000, false))
                {
                    ErrorString = "No data returned";
                    return(false);
                }
            }
            else
            {
                int i;
                for (i = 0; i < (int)DataByteCount; i++)
                {
                    array[i + 6] = Data[i];
                }
                array[i + 6] = 31;
                array[i + 7] = 119;
                array[i + 8] = 0;
                LIN.m_working_frame.BuildState.transmit_data_byte_count_zero = false;
                LIN.m_working_frame.BuildState.we_have_transmitted           = true;
                LIN.m_working_frame_is_done.Reset();
                flag = USBWrite.Send_Script_To_PICkitS(ref array);
                if (!flag)
                {
                    ErrorString = "Error sending script.";
                    return(false);
                }
            }
            return(flag);
        }
Пример #13
0
        public static bool Transmit(byte MasterID, byte[] Data, byte DataByteCount, ref string ErrorString)
        {
            int  index = 0;
            bool flag  = false;

            byte[] array = new byte[30];
            Array.Clear(array, 0, array.Length);
            if (DataByteCount > 9)
            {
                ErrorString = "DataByteCount cannot exceed 9.";
                return(flag);
            }
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(DataByteCount + 5);
            array[3] = 0x84;
            array[4] = (byte)(DataByteCount + 1);
            array[5] = MasterID;
            array[6] = 0x1f;
            array[7] = 0x77;
            array[8] = 0;
            if (DataByteCount == 0)
            {
                m_working_frame.BuildState.transmit_data_byte_count_zero = true;
                m_working_frame.BuildState.we_have_transmitted           = true;
                m_working_frame_is_done.Reset();
                flag = USBWrite.Send_Script_To_PICkitS(ref array);
                if (!flag)
                {
                    ErrorString = "Error sending script.";
                    return(false);
                }
                if (m_working_frame_is_done.WaitOne(0x1770, false))
                {
                    return(flag);
                }
                ErrorString = "No data returned";
                return(false);
            }
            index = 0;
            while (index < DataByteCount)
            {
                array[index + 6] = Data[index];
                index++;
            }
            array[index + 6] = 0x1f;
            array[index + 7] = 0x77;
            array[index + 8] = 0;
            m_working_frame.BuildState.transmit_data_byte_count_zero = false;
            m_working_frame.BuildState.we_have_transmitted           = true;
            m_working_frame_is_done.Reset();
            flag = USBWrite.Send_Script_To_PICkitS(ref array);
            if (!flag)
            {
                ErrorString = "Error sending script.";
                return(false);
            }
            return(flag);
        }
Пример #14
0
        public static bool Write_Slave_Profile(byte p_masterid, ref byte[] p_data, byte p_byte_count, ref byte p_error_code)
        {
            bool result = false;

            p_error_code = 0;
            byte[] array  = new byte[255];
            byte[] array2 = new byte[255];
            byte   b      = 0;
            byte   b2     = 0;

            if (p_byte_count > 244)
            {
                p_error_code = 3;
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(p_byte_count + 5);
            array[3] = 134;
            array[4] = p_masterid;
            array[5] = p_byte_count;
            byte b3;

            for (b3 = 0; b3 < p_byte_count; b3 += 1)
            {
                array[(int)(6 + b3)] = p_data[(int)b3];
            }
            array[(int)(b3 + 6)] = 31;
            array[(int)(b3 + 7)] = 119;
            array[(int)(b3 + 8)] = 0;
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                if (!LIN.Read_Slave_Profile(p_masterid, ref array2, p_byte_count, ref b2, ref b))
                {
                    p_error_code = 1;
                }
                else
                {
                    for (b3 = 0; b3 < p_byte_count; b3 += 1)
                    {
                        if (array2[(int)b3] != p_data[(int)b3])
                        {
                            p_error_code = 1;
                            return(false);
                        }
                    }
                    result = true;
                }
            }
            else
            {
                p_error_code = 2;
            }
            return(result);
        }
Пример #15
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);
        }
Пример #16
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));
        }
Пример #17
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));
        }
Пример #18
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);
        }
Пример #19
0
        public static bool Read_Slave_Profile(byte p_masterid, ref byte[] p_data, byte p_expected_byte_count, ref byte p_actual_byte_count, ref byte p_error_code)
        {
            bool result = false;

            p_error_code = 0;
            byte[] array = new byte[30];
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = 4;
            array[3] = 135;
            array[4] = p_masterid;
            array[5] = 31;
            array[6] = 119;
            array[7] = 0;
            Array.Clear(LIN.m_slave_profile_id.Data, 0, LIN.m_slave_profile_id.Data.Length);
            bool flag = USBWrite.Send_Script_To_PICkitS(ref array);

            if (flag)
            {
                bool flag2 = LIN.m_slave_profile_id_read.WaitOne(2000, false);
                if (flag2)
                {
                    if (p_masterid == LIN.m_slave_profile_id.FrameID)
                    {
                        p_actual_byte_count = LIN.m_slave_profile_id.ByteCount;
                        if (p_expected_byte_count >= LIN.m_slave_profile_id.ByteCount)
                        {
                            for (int i = 0; i < (int)LIN.m_slave_profile_id.ByteCount; i++)
                            {
                                p_data[i] = LIN.m_slave_profile_id.Data[i];
                            }
                            result = true;
                        }
                        else
                        {
                            p_error_code = 3;
                        }
                    }
                    else
                    {
                        p_error_code = 4;
                    }
                }
                else
                {
                    p_error_code = 1;
                }
            }
            else
            {
                p_error_code = 2;
            }
            return(result);
        }
Пример #20
0
        public static bool Write_Slave_Profile(byte p_masterid, ref byte[] p_data, byte p_byte_count, ref byte p_error_code)
        {
            bool flag = false;

            p_error_code = 0;
            byte[] array   = new byte[0xff];
            byte[] buffer2 = new byte[0xff];
            byte   num     = 0;
            byte   num2    = 0;
            byte   index   = 0;

            if (p_byte_count > 0xf4)
            {
                p_error_code = 3;
                return(false);
            }
            Array.Clear(array, 0, array.Length);
            array[0] = 0;
            array[1] = 3;
            array[2] = (byte)(p_byte_count + 5);
            array[3] = 0x86;
            array[4] = p_masterid;
            array[5] = p_byte_count;
            index    = 0;
            while (index < p_byte_count)
            {
                array[6 + index] = p_data[index];
                index            = (byte)(index + 1);
            }
            array[index + 6] = 0x1f;
            array[index + 7] = 0x77;
            array[index + 8] = 0;
            if (USBWrite.Send_Script_To_PICkitS(ref array))
            {
                if (!Read_Slave_Profile(p_masterid, ref buffer2, p_byte_count, ref num2, ref num))
                {
                    p_error_code = 1;
                    return(flag);
                }
                for (index = 0; index < p_byte_count; index = (byte)(index + 1))
                {
                    if (buffer2[index] != p_data[index])
                    {
                        p_error_code = 1;
                        return(false);
                    }
                }
                return(true);
            }
            p_error_code = 2;
            return(flag);
        }
Пример #21
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);
        }
Пример #22
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));
        }
Пример #23
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);
 }
Пример #24
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));
        }
Пример #25
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);
        }
Пример #26
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);
        }
Пример #27
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);
        }
Пример #28
0
 public static bool Program(byte p_slave_addr)
 {
     byte[] array = new byte[300];
     Array.Clear(array, 0, array.Length);
     array[0]  = 0;
     array[1]  = 3;
     array[2]  = 8;
     array[3]  = 0x81;
     array[4]  = 0x84;
     array[5]  = 2;
     array[6]  = p_slave_addr;
     array[7]  = 3;
     array[8]  = 130;
     array[9]  = 0x1f;
     array[10] = 0x77;
     array[11] = 0;
     return(USBWrite.Send_Script_To_PICkitS(ref array));
 }
Пример #29
0
 public static bool Row_Init(byte p_slave_addr)
 {
     byte[] array = new byte[300];
     Array.Clear(array, 0, array.Length);
     array[0]  = 0;
     array[1]  = 3;
     array[2]  = 8;
     array[3]  = 129;
     array[4]  = 132;
     array[5]  = 2;
     array[6]  = p_slave_addr;
     array[7]  = 4;
     array[8]  = 130;
     array[9]  = 31;
     array[10] = 119;
     array[11] = 0;
     return(USBWrite.Send_Script_To_PICkitS(ref array));
 }
Пример #30
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));
        }