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

📄 form.cs

📁 CSharp直接控制usb-232的范例
💻 CS
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************************************/
/* Copyright (c)      2003 KOPF GmbH, Germany (All rights reserved)                                 */
/*                                                                                                  */
/* module name:       USBTransfer/Form.cs                                                                       */
/*                                                                                                  */
/* version:           V1.00                                                                         */
/*                                                                                                  */
/* abstract:          Basic Communication via AID.DLL to a FTDI-USB-Chip                            */
/*                                                                                                  */
/****************************************************************************************************/

/****************************************************************************************************/
/* List Of Changes                                                                                  */
/****************************************************************************************************/
/*                                                                                                  */
/* classes of changes:                                                                              */
/*                                                                                                  */
/* N: new module                                            (V1.00)                                 */
/* F: functional development                                (V+.00)                                 */
/* E: error correction                                      (Vx.+0)                                 */
/* I: change because of changed interface to other modules  (Vx.+0)                                 */
/* O: optimization without functional change                (Vx.x+)                                 */
/*                                                                                                  */
/* list of changes (last change is above):                                                          */
/*                                                                                                  */
/* Class: N    V1.00   03.04.03 KOPF-M.S.                                                           */
/* descript.:  new created                                                                          */
/*                                                                                                  */
/****************************************************************************************************/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace USBTransfer
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form : System.Windows.Forms.Form
	{
		[DllImport("AID.dll")]
		static extern uint FT_ListDevices();
		[DllImport("AID.dll")]
		static extern uint FT_Open();
		[DllImport("AID.dll")]
		static extern uint FT_Close();
		[DllImport("AID.dll")]
		static extern uint FT_Write([MarshalAs(UnmanagedType.LPArray)] byte[] p_data,ulong size);
		[DllImport("AID.dll")]
		static extern uint FT_GetStatus(ref ulong rxsize, ref ulong txsize);
		[DllImport("AID.dll")]
		static extern uint FT_SetBitMode(byte mask, byte enable);
		[DllImport("AID.dll")]
		static extern uint FT_Read([MarshalAs(UnmanagedType.LPArray)] byte[] p_data,ulong size);
		[DllImport("AID.dll")]
		static extern uint FT_EE_Read(ref ushort vid,ref ushort pid, ref ushort power);
		[DllImport("AID.dll")]
		static extern uint FT_EE_Program(ushort power);
		[DllImport("AID.dll")]
		static extern uint FT_EE_ProgramToDefault();
		[DllImport("AID.dll")]
		static extern uint KCAN_Send(uint channel, uint id, uint dlc, [MarshalAs(UnmanagedType.LPArray)] byte[] p_data);
		[DllImport("AID.dll")]
		static extern uint KCAN_Receive(ref uint channel, ref uint id, ref uint dlc, [MarshalAs(UnmanagedType.LPArray)] byte[] p_data);
		[DllImport("AID.dll")]
		static extern uint KCAN_Init(uint baudraute);

		private System.Windows.Forms.Button btn_ListDevices;
		private System.Windows.Forms.TextBox tbx_No_Devices;
		private System.Windows.Forms.Button btn_Open;
		private System.Windows.Forms.Button btn_Close;
		private System.Windows.Forms.Button btn_Write;
		private System.Windows.Forms.Button btn_Read;
		private System.Windows.Forms.Button btn_CAN_Send;
		private System.Windows.Forms.Button btn_SetBitMode;
		private System.Windows.Forms.TextBox tbx_Write;
		private System.Windows.Forms.TextBox tbx_Read;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tbx_Status;
		private System.Windows.Forms.Button btn_GetStatus;
		private System.Windows.Forms.TextBox tbx_RXSize;
		private System.Windows.Forms.TextBox tbx_TXSize;
		private System.Windows.Forms.Button btn_ResetDevice;
		private System.Windows.Forms.Button btn_EERead;
		private System.Windows.Forms.TextBox tbx_VID;
		private System.Windows.Forms.TextBox tbx_PID;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btn_EEWrite;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox tbx_Power;
		private System.Windows.Forms.TextBox tbx_CAN_TX_ID;
		private System.Windows.Forms.TextBox tbx_CAN_TX_DLC;
		private System.Windows.Forms.TextBox tbx_CAN_TX_0;
		private System.Windows.Forms.TextBox tbx_CAN_TX_1;
		private System.Windows.Forms.TextBox tbx_CAN_TX_2;
		private System.Windows.Forms.TextBox tbx_CAN_TX_3;
		private System.Windows.Forms.TextBox tbx_CAN_TX_4;
		private System.Windows.Forms.TextBox tbx_CAN_TX_5;
		private System.Windows.Forms.TextBox tbx_CAN_TX_6;
		private System.Windows.Forms.TextBox tbx_CAN_TX_7;
		private System.Windows.Forms.TextBox tbx_CAN_RX_ID;
		private System.Windows.Forms.Button btn_CAN_Receive;
		private System.Windows.Forms.TextBox tbx_CAN_RX_7;
		private System.Windows.Forms.TextBox tbx_CAN_RX_6;
		private System.Windows.Forms.TextBox tbx_CAN_RX_5;
		private System.Windows.Forms.TextBox tbx_CAN_RX_4;
		private System.Windows.Forms.TextBox tbx_CAN_RX_3;
		private System.Windows.Forms.TextBox tbx_CAN_RX_2;
		private System.Windows.Forms.TextBox tbx_CAN_RX_1;
		private System.Windows.Forms.TextBox tbx_CAN_RX_0;
		private System.Windows.Forms.TextBox tbx_CAN_RX_DLC;
		private System.Windows.Forms.Button btn_CAN_Init;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button btn_EEWriteDef;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.LinkLabel linkLabel1;
		private System.Windows.Forms.Label label7;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btn_ListDevices = new System.Windows.Forms.Button();
			this.tbx_No_Devices = new System.Windows.Forms.TextBox();
			this.btn_Open = new System.Windows.Forms.Button();
			this.btn_Close = new System.Windows.Forms.Button();
			this.btn_Write = new System.Windows.Forms.Button();
			this.btn_Read = new System.Windows.Forms.Button();
			this.btn_CAN_Send = new System.Windows.Forms.Button();
			this.btn_SetBitMode = new System.Windows.Forms.Button();
			this.tbx_Write = new System.Windows.Forms.TextBox();
			this.tbx_Read = new System.Windows.Forms.TextBox();
			this.tbx_Status = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.btn_GetStatus = new System.Windows.Forms.Button();
			this.tbx_RXSize = new System.Windows.Forms.TextBox();
			this.tbx_TXSize = new System.Windows.Forms.TextBox();
			this.btn_ResetDevice = new System.Windows.Forms.Button();
			this.btn_EERead = new System.Windows.Forms.Button();
			this.tbx_VID = new System.Windows.Forms.TextBox();
			this.tbx_PID = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.btn_EEWrite = new System.Windows.Forms.Button();
			this.tbx_Power = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.btn_EEWriteDef = new System.Windows.Forms.Button();
			this.tbx_CAN_TX_ID = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_DLC = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_0 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_1 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_2 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_3 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_4 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_5 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_6 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_TX_7 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_7 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_6 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_5 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_4 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_3 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_2 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_1 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_0 = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_DLC = new System.Windows.Forms.TextBox();
			this.tbx_CAN_RX_ID = new System.Windows.Forms.TextBox();
			this.btn_CAN_Receive = new System.Windows.Forms.Button();
			this.btn_CAN_Init = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.linkLabel1 = new System.Windows.Forms.LinkLabel();
			this.label7 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// btn_ListDevices
			// 
			this.btn_ListDevices.Location = new System.Drawing.Point(8, 8);
			this.btn_ListDevices.Name = "btn_ListDevices";
			this.btn_ListDevices.Size = new System.Drawing.Size(75, 20);
			this.btn_ListDevices.TabIndex = 0;
			this.btn_ListDevices.Text = "ListDevices";
			this.btn_ListDevices.Click += new System.EventHandler(this.btn_ListDevices_Click);
			// 
			// tbx_No_Devices
			// 
			this.tbx_No_Devices.Location = new System.Drawing.Point(92, 8);
			this.tbx_No_Devices.Name = "tbx_No_Devices";
			this.tbx_No_Devices.Size = new System.Drawing.Size(24, 20);
			this.tbx_No_Devices.TabIndex = 1;
			this.tbx_No_Devices.Text = "";
			// 
			// btn_Open
			// 
			this.btn_Open.Location = new System.Drawing.Point(8, 36);
			this.btn_Open.Name = "btn_Open";
			this.btn_Open.Size = new System.Drawing.Size(75, 20);
			this.btn_Open.TabIndex = 2;
			this.btn_Open.Text = "Open";
			this.btn_Open.Click += new System.EventHandler(this.btn_Open_Click);
			// 
			// btn_Close
			// 
			this.btn_Close.Enabled = false;
			this.btn_Close.Location = new System.Drawing.Point(8, 64);
			this.btn_Close.Name = "btn_Close";
			this.btn_Close.Size = new System.Drawing.Size(75, 20);
			this.btn_Close.TabIndex = 3;
			this.btn_Close.Text = "Close";
			this.btn_Close.Click += new System.EventHandler(this.btn_Close_Click);
			// 
			// btn_Write
			// 
			this.btn_Write.Enabled = false;
			this.btn_Write.Location = new System.Drawing.Point(8, 92);
			this.btn_Write.Name = "btn_Write";
			this.btn_Write.Size = new System.Drawing.Size(75, 20);
			this.btn_Write.TabIndex = 4;
			this.btn_Write.Text = "Write";
			this.btn_Write.Click += new System.EventHandler(this.btn_Write_Click);
			// 
			// btn_Read
			// 
			this.btn_Read.Enabled = false;
			this.btn_Read.Location = new System.Drawing.Point(8, 120);
			this.btn_Read.Name = "btn_Read";
			this.btn_Read.Size = new System.Drawing.Size(75, 20);
			this.btn_Read.TabIndex = 5;
			this.btn_Read.Text = "Read";
			this.btn_Read.Click += new System.EventHandler(this.btn_Read_Click);
			// 
			// btn_CAN_Send
			// 
			this.btn_CAN_Send.Location = new System.Drawing.Point(8, 384);
			this.btn_CAN_Send.Name = "btn_CAN_Send";
			this.btn_CAN_Send.Size = new System.Drawing.Size(75, 20);
			this.btn_CAN_Send.TabIndex = 6;
			this.btn_CAN_Send.Text = "CAN Send";
			this.btn_CAN_Send.Click += new System.EventHandler(this.btn_CAN_Send_Click);
			// 
			// btn_SetBitMode
			// 
			this.btn_SetBitMode.Enabled = false;
			this.btn_SetBitMode.Location = new System.Drawing.Point(8, 148);
			this.btn_SetBitMode.Name = "btn_SetBitMode";
			this.btn_SetBitMode.Size = new System.Drawing.Size(75, 20);
			this.btn_SetBitMode.TabIndex = 7;
			this.btn_SetBitMode.Text = "SetBitMode";
			this.btn_SetBitMode.Click += new System.EventHandler(this.btn_SetBitMode_Click);
			// 
			// tbx_Write
			// 
			this.tbx_Write.Location = new System.Drawing.Point(92, 92);
			this.tbx_Write.Name = "tbx_Write";
			this.tbx_Write.Size = new System.Drawing.Size(172, 20);
			this.tbx_Write.TabIndex = 9;
			this.tbx_Write.Text = "";
			// 
			// tbx_Read
			// 

⌨️ 快捷键说明

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