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

📄 selectscreen.cs

📁 c8051f320单片机的usb 示例程序。用keil uVision 建立工程。已测试通过
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -