selectscreen.cs

来自「c8051f320单片机的usb 示例程序。用keil uVision 建立工程」· CS 代码 · 共 73 行

CS
73
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace USBXpress_TestPanel
{
    public partial class SelectScreen : Form
    {
        public SelectScreen()
        {
            InitializeComponent();
        }

        private void button_Reject_Click(object sender, EventArgs e)
        {
            Application.Exit();    // Exit program
        }

        private void SelectScreen_Load(object sender, EventArgs e)
        {
            //Variables we will use when loading this form
            int DevNum = 0;
            StringBuilder DevStr = new StringBuilder(SLUSBXpressDLL.SI_MAX_DEVICE_STRLEN);
            int i, iMax;

            comboBox_Device.Items.Clear();
            SLUSBXpressDLL.Status = SLUSBXpressDLL.SI_GetNumDevices(ref DevNum);

            // if we find a device, obtain the name of each device
            // and add to the combo list, otherwise display the error
            // and close the application

            if (SLUSBXpressDLL.Status == SLUSBXpressDLL.SI_SUCCESS)
            {
                for (i = 0; i < DevNum; i++)
                {
                    SLUSBXpressDLL.Status = SLUSBXpressDLL.SI_GetProductString(i, DevStr, SLUSBXpressDLL.SI_RETURN_SERIAL_NUMBER);
                    comboBox_Device.Items.Insert(i, DevStr);
                }
                comboBox_Device.SelectedIndex = 0;  // then set combo list to first item
            }
            else
            {
                MessageBox.Show("Error finding USB device.  Aborting application.");
                Application.Exit();
            }
        }

        private void button_Accept_Click(object sender, EventArgs e)
        {

            // when ok is clicked, set the timeouts on the device
            // and open the device
            SLUSBXpressDLL.Status = SLUSBXpressDLL.SI_SetTimeouts(10000, 10000);
            SLUSBXpressDLL.Status = SLUSBXpressDLL.SI_Open(comboBox_Device.SelectedIndex, ref SLUSBXpressDLL.hUSBDevice);

            if (SLUSBXpressDLL.Status != SLUSBXpressDLL.SI_SUCCESS)
            {
                MessageBox.Show("Error opening device: " + comboBox_Device.Text + ". Application is aborting. Reset hardware and try again.");
                Application.Exit();
            }

            TestPanel TPForm = new TestPanel();
            Form.ActiveForm.Hide(); 
            TPForm.Show();
        }
    }
}

⌨️ 快捷键说明

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