⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Cypress Suite USB 3.4.6
💻 CS
📖 第 1 页 / 共 5 页
字号:
            Handler to close application
        */
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        /* Summary
            Method to check whether Fx2 is selected or not
        */
        private CyFX2Device Fx2DeviceSelected()
        {
            TreeNode selNode = DeviceTreeView.SelectedNode;

            if (selNode == null)
            {
                MessageBox.Show("Select an FX2 device in the device tree.", "Non-FX2 device selected");
                return null;
            }

            // Climb to the top of the tree
            while (selNode.Parent != null)
                selNode = selNode.Parent;

            fx2 = selNode.Tag as CyFX2Device;

            if (fx2 == null)
                MessageBox.Show("Select an FX2 device in the device tree.", "Non-FX2 device selected");

            return fx2;
        }

        /* Summary
            Used for some specific purposes for not showing the MessageBox similar to Fx2DeviceSelected
        */
        private CyFX2Device Fx2DeviceSelected_forusage()
        {
            TreeNode selNode = DeviceTreeView.SelectedNode;

            while (selNode.Parent != null)
                selNode = selNode.Parent;

            fx2 = selNode.Tag as CyFX2Device;

            return fx2;
        }

        /* Summary
            This event handler handles 3 events: programming large EEprom, small EEprom and loading RAM
        */
        private void ProgE2Item_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();
            string tmpFilter = FOpenDialog.Filter;

            if ((sender == ProgE2Item) || (sender == ProgSE2Item))
                FOpenDialog.Filter = "Firmware Image files (*.iic) | *.iic";

            if ((fx2 != null) && (FOpenDialog.ShowDialog() == DialogResult.OK))
            {
                bool bResult = false;

                if (sender == ProgE2Item)
                {
                    StatLabel.Text = "Programming EEPROM of " + fx2.FriendlyName;
                    Refresh();
                    bResult = fx2.LoadEEPROM(FOpenDialog.FileName, true);
                }
                else if (sender == ProgSE2Item)
                {
                    StatLabel.Text = "Programming EEPROM of " + fx2.FriendlyName;
                    Refresh();
                    bResult = fx2.LoadEEPROM(FOpenDialog.FileName, false);
                }
                else
                {
                    StatLabel.Text = "Programming RAM of " + fx2.FriendlyName;
                    Refresh();
                    bResult = fx2.LoadExternalRam(FOpenDialog.FileName);
                }
                StatLabel.Text = "Programming " + (bResult ? "succeeded." : "failed.");
                Refresh();
            }

            FOpenDialog.FileName = "";
            FOpenDialog.Filter = tmpFilter;
        }

        /* Summary
            Event handler to reset or run Fx2's CPU
        */
        private void HaltItem_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 != null)
                if (sender == HaltItem)
                    fx2.Reset(1);
                else
                    fx2.Reset(0);

        }

        /* Summary
            Event handler to handle changes in Check box of Device Class Selection Tabpage and at Start
        */
        private void CyUSBDeviceBox_CheckedChanged(object sender, EventArgs e)
        {
            byte DeviceMask = 0;

            DeviceMask |= CyUSBDeviceBox.Checked ? CyConst.DEVICES_CYUSB : (byte)0;
            DeviceMask |= MSCDeviceBox.Checked ? CyConst.DEVICES_MSC : (byte)0;
            DeviceMask |= HIDDeviceBox.Checked ? CyConst.DEVICES_HID : (byte)0;

            if (usbDevices != null)
            {
                usbDevices.DeviceRemoved -= usbDevices_DeviceRemoved;
                usbDevices.DeviceAttached -= usbDevices_DeviceAttached;
                usbDevices.Dispose();
            }

            usbDevices = new USBDeviceList(DeviceMask);

            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);

            curEndpt = null;
            curCyUsbDev = null;
            curHidDev = null;
            curHidReport = null;
            RefreshDeviceTree();
        }

        /* Summary
            Event handler for new device attach
        */
        void usbDevices_DeviceAttached(object sender, EventArgs e)
        {
            USBEventArgs usbEvent = e as USBEventArgs;

            RefreshDeviceTree();
        }

        /* Summary
            Event handler for device removal
        */
        void usbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            USBEventArgs usbEvent = e as USBEventArgs;
            curEndpt = null; // reinitialize
            RefreshDeviceTree();
        }

        /* Summary
            Clears the outputbox and status bar
        */
        private void Clear_Click(object sender, EventArgs e)
        {
            OutputBox.Text = "";
            StatLabel.Text = "";
            StatusLabel.Text = "";
        }

        /* Summary
            Aborts the selected pipe
        */
        private void Abort_Pipe_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }

            if (curEndpt == null)
            {
                MessageBox.Show("Select an endpoint to Abort.", "No endpoint selected");
                return;
            }
            curEndpt.Abort();
            StatLabel.Text = "Abort Pipe Successfull";
        }

        /* Summary
            Resets the selected pipe
        */
        private void Reset_Pipe_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }

            if (curEndpt == null)
            {
                MessageBox.Show("Select an endpoint to reset.", "No endpoint selected");
                return;
            }
            curEndpt.Reset();
            StatLabel.Text = "Reset Pipe Successfull";
        }

        /* Summary
            Aborts the selected endpoint
        */
        private void Abort_endpoint_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }

            if (curEndpt == null)
            {
                MessageBox.Show("Select an endpoint to Abort.", "No endpoint selected");
                return;
            }
            curEndpt.Abort();
            StatLabel.Text = "Abort Successfull";
        }

        /* Summary
            Resets the selected endpoint
        */
        private void Reset_endpoint_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }

            if (curEndpt == null)
            {
                MessageBox.Show("Select an endpoint to reset.", "No endpoint selected");
                return;
            }
            curEndpt.Reset();
            StatLabel.Text = "Reset Successfull";
        }

        /* Summary
            Reconnects the selected Fx2 device
        */
        private void Reconnect_device_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }
            fx2.ReConnect();
            StatLabel.Text = "Device Reconnected";
        }

        /* Summary
            Resets the selected Fx2 device
        */
        private void Reset_device_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }
            fx2.Reset();
            RefreshDeviceTree();
            StatLabel.Text = "Device Reset Successfull";

        }

        /* Summary
            Shows the last state and status of endpoint
        */
        private void URB_Stat_Click(object sender, EventArgs e)
        {
            fx2 = Fx2DeviceSelected();

            if (fx2 == null)
            {
                return;
            }

            if (curEndpt == null)
            {
                MessageBox.Show("Select an endpoint to find the status.", "No endpoint selected");
                return;
            }

            uint status = curEndpt.UsbdStatus;

            string Hex = String.Format("{0:X}", status);

            StatLabel.Text = "Last URB Error = 0x" + Hex + " " + CyUSBDevice.UsbdStatusString(status);

        }

        /* Summary
            Generates a .spt file --> asks for source .hex
        */
        private void Create_script_Click(object sender, EventArgs e)
        {
            string tmpFilter = FOpenDialog.Filter;
            string tmpTitle = FOpenDialog.Title;

            FOpenDialog.Title = "Select a hex file: ";
            FOpenDialog.Filter = "Intel HEX files (*.hex) | *.hex";

            if (FOpenDialog.ShowDialog() == DialogResult.OK)
            {
                fname = FOpenDialog.FileName;
                Refresh();
            }
            else
            {
                FOpenDialog.Title = tmpTitle;
                FOpenDialog.Filter = tmpFilter;
                return;
            }

            FOpenDialog.FileName = "";
            FOpenDialog.Title = tmpTitle;
            FOpenDialog.Filter = tmpFilter;

            string tmpSFilter = FSave.Filter;
            string tmpSTitle = FSave.Title;

            FSave.Filter = "Save script file (*.spt) | *.spt";


            if (FSave.ShowDialog() == DialogResult.OK)
            {
                scriptfile = FSave.FileName;
                Refresh();
            }
            else
            {
                FSave.Filter = tmpSFilter;
                FSave.Title = tmpSTitle;
                return;
            }

            FSave.FileName = "";
            FSave.Filter = tmpSFilter;
            FSave.Title = tmpSTitle;

            try
            {
                stream = new FileStream(scriptfile, FileMode.Create);
                sw = new StreamWriter(stream);

                LoadHexScript("VendAX.hex", true);
                LoadHexScript(fname, false);
                LoadHexScript(fname, true);

                sw.Close();
                stream.Close();
                scriptfile = "";

                StatLabel.Text = "Script Created: " + FSave.FileName;
            }
            catch (Exception exc)
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -