Ejemplo n.º 1
0
        USB_Command2(int delay, CyHidDevice whichDev)
        {
            int  i;
            byte sum = 0;

            if (whichDev != null)
            {
                whichDev.Features.DataBuf[0] = 0;

                for (i = 0; i < 7; ++i)
                {
                    sum += cmd[i];
                    whichDev.Features.DataBuf[i + 1] = cmd[i];
                }
                whichDev.Features.DataBuf[8] = (byte)(1 + ~sum);

                if (!whichDev.SetFeature(whichDev.Features.ID))
                {
                    debugMessage("failed:Command");
                    return(false);
                }
                debugMessage("passed:Command");

                // Now wait for the response to see if the command completed.

                if (delay == 0)
                {
                    return(true);
                }

                // Always delay before getting status

                Thread.Sleep(delay);

                // Try 3 times to get command status

                for (i = 3; i > 0; --i)
                {
                    GetFeatureReport2(status, whichDev);

                    if (status[0] != 0)
                    {
                        return(true);
                    }

                    Thread.Sleep(delay);
                }
                if (status[0] == 0)
                {
                    Output.Text += "!!! Command failed to complete\r\n";
                    scroll();
                }
            }
            else
            {
                message("No unit attached!");
            }

            return(false);
        }
Ejemplo n.º 2
0
        GetInputReport2(byte[] dout, int count, byte xor, CyHidDevice whichDev)
        {
            bool status;

            if (whichDev != null)
            {
                status = whichDev.GetInput(whichDev.Inputs.ID);
                debugStatus("GetInputReport:failed", status);

                for (int i = 0; i < 8 && i < count; ++i)
                {
                    dout[i] = (byte)(xor ^ whichDev.Inputs.DataBuf[i + 1]);
                }
                return(status);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void GetHidDevice()
        {
            CyHidDevice device = usbHIDDevices[VID, PID] as CyHidDevice;

            if (device != null)
            {
                channel = new HIDCommunicationsChannel(device);
                host    = new LokiBootloaderHost(channel);
                host.EnterBootloader();
                this.UseWaitCursor = true;
                readEEPROMWorker.RunWorkerAsync();
            }
            else
            {
                OnDetach();
            }
        }
Ejemplo n.º 4
0
        GetFeatureReport2(byte[] status, CyHidDevice whichDev)
        {
            bool s;

            if (whichDev != null)
            {
                s = whichDev.GetFeature(0);

                if (s)
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        status[i] = whichDev.Features.DataBuf[i + 1];
                    }
                }
            }
            else
            {
                Output.Text += "No USB device\r\n";
            }
        }
Ejemplo n.º 5
0
        SetOutputReport2(byte[] din, int count, CyHidDevice whichDev)
        {
            int tsize, j;

            if (whichDev == null)
            {
                message("No unit attached!");
                return;
            }

            j = 0;
            while (count > 0)
            {
                whichDev.Outputs.DataBuf[0] = 0;

                if (count > 8)
                {
                    tsize = 8;
                }
                else
                {
                    tsize = count;
                }

                for (byte i = 0; i < tsize; ++i)
                {
                    whichDev.Outputs.DataBuf[i + 1] = din[j++];
                }

                if (!whichDev.SetOutput(whichDev.Outputs.ID))
                {
                    debugMessage("failed:Output");
                    return;
                }
                count -= tsize;
            }
            debugMessage("passed:Output");
        }
Ejemplo n.º 6
0
        public static void BlockingBLUSBManager(string fullPathCyacd, BackgroundWorker BLCommThread)
        {
            CyHidDevice   myHidDevice_BLMgr = null;                                  // Handle of USB device
            USBDeviceList usbDevices_BLMgr = new USBDeviceList(CyConst.DEVICES_HID); // Pointer to list of USB devices
            uint          JTAGIDMgr, JTAGIDfileMgr, BLVERMgr;
            byte          DEVREVMgr;

            string[] CYACDLinesMgr;
            BLCommThread.WorkerReportsProgress = true;

            myHidDevice_BLMgr = usbDevices_BLMgr[Vendor_ID, Product_ID_BL] as CyHidDevice;
            if (myHidDevice_BLMgr != null)
            {
                myHidDevice_BLMgr = usbDevices_BLMgr[Vendor_ID, Product_ID_BL] as CyHidDevice;
            }
            else
            {
                return;
            }

            ///////////////////////////////////////////////////////////////////////////
            // Prepare and Send
            #region // --Enter Bootloader Command
            List <byte> cmdBuffer = new List <byte>();
            List <byte> rspBuffer = new List <byte>();

            // Build Enter Bootloader Packet
            CreateEnterBootLoaderCmd(ref cmdBuffer);

            // ____----____----Send the packet
            //First Byte in buffer holds the Report ID
            myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

            //Load 64 bytes of data
            for (int i = 1; i <= cmdBuffer.Count; i++)
            {
                myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
            }

            // Write to HID output buffer
            myHidDevice_BLMgr.WriteOutput();

            // Read from HID input buffer
            myHidDevice_BLMgr.ReadInput();

            // Parse the response
            rspBuffer.Clear();
            foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
            {
                rspBuffer.Add(b);
            }

            if (rspBuffer.Count != 0 && rspBuffer[2] == 0x00)
            {
                BLCommThread.ReportProgress(0);

                JTAGIDMgr  = rspBuffer[5];
                JTAGIDMgr |= (uint)rspBuffer[6] << 8;
                JTAGIDMgr |= (uint)rspBuffer[7] << 16;
                JTAGIDMgr |= (uint)rspBuffer[8] << 24;
                DEVREVMgr  = rspBuffer[9];
                BLVERMgr   = rspBuffer[10];
                BLVERMgr  |= (uint)rspBuffer[11] << 8;
                BLVERMgr  |= (uint)rspBuffer[12] << 16;

                CYACDLinesMgr = File.ReadAllLines(fullPathCyacd);
                JTAGIDfileMgr = uint.Parse(CYACDLinesMgr[0].Substring(0, 8), System.Globalization.NumberStyles.HexNumber);

                ///////////////////////////////////////////////////////////////////////////
                // Prepare and Send
                // --Programming Actions
                if (JTAGIDMgr == JTAGIDfileMgr)
                {
                    byte   ArrayID         = 0;
                    ushort RowNum          = 0;
                    ushort DataLen         = 0;
                    byte   rowChkSum       = 0;
                    byte   rowChkSumVerify = 0;
                    int    rowCnt          = 0;

                    // Row Data - Data Length bytes - 2*datalength ascii chars
                    List <byte[]> RowDataBytes = new List <byte[]>();
                    List <string> CyacdLines   = CYACDLinesMgr.ToList();
                    CyacdLines.RemoveAt(0);

                    foreach (string line in CyacdLines)
                    {
                        #region // parse
                        // Array ID - 1 byte - 2 ascii chars
                        ArrayID = byte.Parse(line.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);

                        // Row Number - 2 bytes - 4 ascii chars
                        RowNum = ushort.Parse(line.Substring(3, 4), System.Globalization.NumberStyles.HexNumber);

                        // Data Length - 2 bytes- 4 ascii chars
                        DataLen = ushort.Parse(line.Substring(7, 4), System.Globalization.NumberStyles.HexNumber);

                        // Row Data - Data Length bytes - 2*datalength ascii chars
                        RowDataBytes.Clear();
                        RowDataBytes = ASCIIHexByteArray2Bytes(line.Substring(11, 2 * DataLen));

                        // Row Checksum
                        rowChkSum = byte.Parse(line.Substring(11 + 2 * DataLen, 2), System.Globalization.NumberStyles.HexNumber);

                        #endregion

                        #region  // erase
                        // Build Erase Row Packet
                        CreateEraseRowCmd(ref cmdBuffer, ArrayID, RowNum);

                        // ____----____----Send the packet
                        //First Byte in buffer holds the Report ID
                        myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                        //Load 64 bytes of data
                        for (int i = 1; i <= cmdBuffer.Count; i++)
                        {
                            myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                        }

                        // Write to HID output buffer
                        myHidDevice_BLMgr.WriteOutput();

                        // Read from HID input buffer
                        myHidDevice_BLMgr.ReadInput();

                        // Parse the response
                        rspBuffer.Clear();
                        foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
                        {
                            rspBuffer.Add(b);
                        }

                        if (rspBuffer.Count == 0)
                        {
                            MessageBox.Show("Failure of Erase Row Command - no response bytes"); break;
                        }
                        if (rspBuffer[2] != 0x00)
                        {
                            MessageBox.Show("Failure of Erase Row Command - " + rspBuffer[2].ToString("X2")); break;
                        }

                        #endregion

                        #region  // send data

                        // Buffer Row on Master PSoC
                        foreach (byte[] rowDat in RowDataBytes)
                        {
                            // Build Send Data Packet
                            CreateSendDataCmd(ref cmdBuffer, rowDat);

                            // ____----____----Send the packet
                            //First Byte in buffer holds the Report ID
                            myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                            //Load data
                            for (int i = 1; i <= cmdBuffer.Count; i++)
                            {
                                myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                            }

                            // Write to HID output buffer
                            myHidDevice_BLMgr.WriteOutput();

                            // Read from HID input buffer
                            myHidDevice_BLMgr.ReadInput();

                            // Parse the response
                            rspBuffer.Clear();
                            foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
                            {
                                rspBuffer.Add(b);
                            }

                            if (rspBuffer.Count == 0)
                            {
                                MessageBox.Show("Failure of Send Data Commands - no response bytes"); break;
                            }
                            if (rspBuffer[2] != 0x00)
                            {
                                MessageBox.Show("Failure of Send Data Commands - " + rspBuffer[2].ToString("X2")); break;
                            }
                        }
                        if (rspBuffer.Count == 0)
                        {
                            MessageBox.Show("Failure of Send Data Commands Detected - no response bytes"); break;
                        }
                        if (rspBuffer[2] != 0x00)
                        {
                            MessageBox.Show("Failure of Send Data Commands Detected- " + rspBuffer[2].ToString("X2")); break;
                        }

                        #endregion +		new System.Collections.Generic.Mscorlib_CollectionDebugView<byte[]>(RowDataBytes).Items[8]	{byte[0x00000020]}	byte[]

                        #region  // program
                        // Build Program Row Packet
                        CreateProgramRowCmd(ref cmdBuffer, ArrayID, RowNum);

                        // ____----____----Send the packet
                        //First Byte in buffer holds the Report ID
                        myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                        //Load 64 bytes of data
                        for (int i = 1; i <= cmdBuffer.Count; i++)
                        {
                            myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                        }

                        // Write to HID output buffer
                        myHidDevice_BLMgr.WriteOutput();

                        // Read from HID input buffer
                        myHidDevice_BLMgr.ReadInput();

                        // Parse the response
                        rspBuffer.Clear();
                        foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
                        {
                            rspBuffer.Add(b);
                        }

                        if (rspBuffer.Count == 0)
                        {
                            MessageBox.Show("Failure of Program Row Command - no response bytes"); break;
                        }
                        if (rspBuffer[2] != 0x00)
                        {
                            MessageBox.Show("Failure of Program Row Command - " + rspBuffer[2].ToString("X2")); break;
                        }

                        #endregion

                        #region  // verify
                        rowChkSumVerify = (byte)(rowChkSum + ArrayID + RowNum + (RowNum >> 8) + DataLen + (DataLen >> 8));

                        // Build Verify Row Packet
                        CreateVerifyRowCmd(ref cmdBuffer, ArrayID, RowNum, rowChkSumVerify);

                        // ____----____----Send the packet
                        //First Byte in buffer holds the Report ID
                        myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                        //Load 64 bytes of data
                        for (int i = 1; i <= cmdBuffer.Count; i++)
                        {
                            myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                        }

                        // Write to HID output buffer
                        myHidDevice_BLMgr.WriteOutput();

                        // Read from HID input buffer
                        myHidDevice_BLMgr.ReadInput();

                        // Parse the response
                        rspBuffer.Clear();
                        foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
                        {
                            rspBuffer.Add(b);
                        }

                        if (rspBuffer[2] != 0x00)
                        {
                            MessageBox.Show("Failure of Verify Row CheckSum Command - " + rspBuffer[2].ToString("X2")); break;
                        }
                        if (rspBuffer[5] != rowChkSumVerify)
                        {
                            MessageBox.Show("Failure of Verify Row CheckSum Command - Failed CheckSum\nExpecting " + rowChkSumVerify.ToString("X") + " Received " + rspBuffer[5].ToString("X") + "\nArrayID: " + ArrayID.ToString("X") + " RowNum: " + RowNum.ToString("X")); break;
                        }
                        //else
                        //{ MessageBox.Show("Verify Row CheckSum - Passed CheckSum\nExpecting " + rowChkSumVerify.ToString("X") + " Received " + rspBuffer[5].ToString("X") + "\nArrayID: " + ArrayID.ToString("X") + " RowNum: " + RowNum.ToString("X")); }
                        #endregion

                        BLCommThread.ReportProgress((int)(((rowCnt * 1.0f) / CyacdLines.Count) * 100));
                        rowCnt++;
                    }

                    ////////////////////////////////////////////////////////////////////////////
                    // Prepare and Send
                    #region  // -- Verify Application Checksum
                    // Build Verify Application Packet
                    CreateVerifyApplicationCmd(ref cmdBuffer);

                    // ____----____----Send the packet
                    //First Byte in buffer holds the Report ID
                    myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                    //Load 64 bytes of data
                    for (int i = 1; i <= cmdBuffer.Count; i++)
                    {
                        myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                    }

                    // Write to HID output buffer
                    myHidDevice_BLMgr.WriteOutput();

                    // Read from HID input buffer
                    myHidDevice_BLMgr.ReadInput();

                    // Parse the response
                    rspBuffer.Clear();
                    foreach (byte b in myHidDevice_BLMgr.Inputs.DataBuf)
                    {
                        rspBuffer.Add(b);
                    }

                    if (rspBuffer[2] != 0x00)
                    {
                        MessageBox.Show("Failure of Verify Application CheckSum Command - " + rspBuffer[2].ToString("X2"));
                    }
                    if (rspBuffer[5] == 0x00)
                    {
                        MessageBox.Show("Failure of Verify Application CheckSum Command - Failed CheckSum");
                    }

                    #endregion

                    ///////////////////////////////////////////////////////////////////////////
                    // Prepare and Send
                    #region  // --Exit the bootloader
                    // Build Exit Bootloader Packet
                    CreateExitBootLoaderCmd(ref cmdBuffer);

                    // ____----____----Send the packet
                    //First Byte in buffer holds the Report ID
                    myHidDevice_BLMgr.Outputs.DataBuf[0] = myHidDevice_BLMgr.Outputs.ID;

                    //Load 64 bytes of data
                    for (int i = 1; i <= cmdBuffer.Count; i++)
                    {
                        myHidDevice_BLMgr.Outputs.DataBuf[i] = cmdBuffer[i - 1];
                    }

                    // Write to HID output buffer
                    myHidDevice_BLMgr.WriteOutput();
                    MessageBox.Show("  - Remember to Disconnect the USB cable from the POC; then,\n\n  --  Please disconnect and reconnect power to the FS Comfort to complete the programming process.\n\n", "Boot Load Operation Exited!");
                    #endregion
                }
            }
            #endregion
        }
Ejemplo n.º 7
0
 public HIDCommunicationsChannel(CyHidDevice device)
 {
     this._device = device;
 }
Ejemplo n.º 8
0
        public Form1()
        {
            InitializeComponent();


            // Create a list of CYUSB devices
            oUSBDeviceList = new USBDeviceList(CyConst.DEVICES_HID);

            oCyHidDevice = null;
            this.Text    = "No device";

            foreach (CyHidDevice oCyHidDeviceTemp in oUSBDeviceList)
            {
                if ((oCyHidDeviceTemp.VendorID == 0x0483) && (oCyHidDeviceTemp.ProductID == 0x5750))
                {
                    oCyHidDevice = oCyHidDeviceTemp;

                    this.Text = oCyHidDevice.Product + " by " + oCyHidDevice.Manufacturer + " - Connected";
                    //     this.Text = "DFDFD";

                    break;
                }
            }

            oCyHidDevice.Outputs.DataBuf[1] = 0;
            oCyHidDevice.Outputs.DataBuf[2] = 0;
            oCyHidDevice.Outputs.DataBuf[3] = 0;
            //oCyHidDevice.Outputs.DataBuf[4] = 4;
            // oCyHidDevice.Outputs.DataBuf[5] = 5;
            // oCyHidDevice.Outputs.DataBuf[6] = 6;

            this.Show();


            bool bResult;

            Stopwatch time10kOperations = Stopwatch.StartNew();
            UInt16    iPort             = 0x2FF8;

            time10kOperations.Stop();
            Freq.Text = Stopwatch.Frequency.ToString() + " per second";
            while (true)
            {
                Application.DoEvents();


                if (!doit)
                {
                    continue;
                }

                ;


                bResult = oCyHidDevice.ReadInput();
                time10kOperations.Stop();



                t = oCyHidDevice.Inputs.DataBuf[7];
                t = (t << 8) + oCyHidDevice.Inputs.DataBuf[6];
                t = (t << 8) + oCyHidDevice.Inputs.DataBuf[5];
                t = (t << 8) + oCyHidDevice.Inputs.DataBuf[4];

                s = oCyHidDevice.Inputs.DataBuf[11];
                s = (s << 8) + oCyHidDevice.Inputs.DataBuf[10];
                s = (s << 8) + oCyHidDevice.Inputs.DataBuf[9];
                s = (s << 8) + oCyHidDevice.Inputs.DataBuf[8];


                array1[idx++] = s;

                if (idx == 4990)
                {
                    idx = 9;
                }

                // continue;

                int tt = (int)oCyHidDevice.Inputs.DataBuf[2] + (oCyHidDevice.Inputs.DataBuf[3] << 8);

                //DB.AppendText(oCyHidDevice.Inputs.DataBuf[2].ToString() + " - " + oCyHidDevice.Inputs.DataBuf[3].ToString() + " - " + (time10kOperations.ElapsedMilliseconds).ToString() + "\r\n");
                DB.AppendText(tt.ToString() + " - " + (time10kOperations.ElapsedTicks).ToString() + " " + (time10kOperations.ElapsedMilliseconds).ToString() + " - " + t + " - " + s.ToString() + "\r\n");

                if (0 != c)
                {
                    c--;
                }
                if (0 == c)
                {
                    if (time10kOperations.ElapsedMilliseconds > 0)
                    {
                        over++;
                        Over.Text = over.ToString();
                    }
                    if (time10kOperations.ElapsedMilliseconds > 1)
                    {
                        over2++;
                        Over2.Text = over2.ToString();
                    }
                    if (time10kOperations.ElapsedMilliseconds > 5)
                    {
                        over5++;
                        Over5.Text = over5.ToString();
                    }
                }

                time10kOperations.Reset();
                time10kOperations.Start();



                continue;

                oCyHidDevice.Outputs.DataBuf[1] = (byte)time10kOperations.ElapsedMilliseconds;

                if (oCyHidDevice.Outputs.DataBuf[1] > 3)
                {
                    oCyHidDevice.Outputs.DataBuf[2]++;
                }

                if (oCyHidDevice.Outputs.DataBuf[1] > 6)
                {
                    oCyHidDevice.Outputs.DataBuf[3]++;
                }


                oCyHidDevice.Outputs.DataBuf[1] = 0x73;
                try
                {
                    oCyHidDevice.Outputs.DataBuf[2] = Convert.ToByte(textBox1.Text);
                    oCyHidDevice.Outputs.DataBuf[3] = Convert.ToByte(textBox2.Text);
                }
                catch
                {
                    textBox1.Text = "255";
                    textBox2.Text = "255";
                    oCyHidDevice.Outputs.DataBuf[2] = Convert.ToByte(textBox1.Text);
                    oCyHidDevice.Outputs.DataBuf[3] = Convert.ToByte(textBox2.Text);
                }
                //oCyHidDevice.Outputs.DataBuf[4] = 0x0D;
                // oCyHidDevice.Outputs.DataBuf[5] = 0x0A;
                //oCyHidDevice.Outputs.DataBuf[6]++;



                time10kOperations.Reset();
                time10kOperations.Start();

                bResult = oCyHidDevice.WriteOutput();


                //Out32((short)iPort, (short)0xFF);

                time10kOperations.Stop();
                // DB.AppendText(time10kOperations.ElapsedMilliseconds.ToString() + "\r\n") ;
                DB.AppendText(time10kOperations.ElapsedMilliseconds.ToString());
            }
            //oCyHidDevice.Outputs.DataBuf[2] = (byte)(oCyHidDevice.Inputs.DataBuf[1] + 1);
            //oCyHidDevice.Outputs.DataBuf[3] = (byte)(oCyHidDevice.Inputs.DataBuf[1] + 2);


            // if (bResult)
            // {
            //     bResult = oCyHidDevice.ReadInput();
            //     DB.AppendText(oCyHidDevice.Inputs.DataBuf[1].ToString() + "\r\n");
            // }
        }