Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice

Similar documents




2


!"# $! "##$! $ "%& % & #$# & ()% & "!! * "! * #! * * $! ((!"# "##$ + #++ * * * * * * * * * * + $," ("# +### "##$ $ + + & $ ### "%& % & #$# & ()% & " "






法 与 采 购 模 式, 不 仅 不 能 保 证 一 些 战 略 性 物 资 的 充 分 供 应, 很 容 易 造 成 供 应 风 险, 而 且 会 影 响 供 应 链 的 后 续 活 动 因 此, 必 须 对 当 前 的 物 资 分 类 加 以 改 革 2 集 中 采 购 供 应 商 准 入 门


Visual Basic AD/DA Visual Basic 2

Ⅰ Ⅱ Ⅲ Ⅳ

1.ai

untitled

14-1 西 亞 的 自 然 環 境 第 14 章 西 亞 重 要 特 徵 : 乾 燥 氣 候 高 原 地 形 一 以 高 原 為 主 體 的 地 形 地 形 分 區 地 形 主 體 地 形 特 徵 1 世 界 最 大 半 島 古 老 地 台 與 2 古 老 地 台 : 因 紅 海 陷

麻 煩 的, 中 國 歷 來 是 一 個 產 能 非 常 大 的 國 家, 中 國 的 建 築 工 人 就 有 八 千 萬, 所 以 一 旦 通 貨 緊 縮 以 後, 第 一, 整 個 產 業 波 動, 產 能 過 剩, 第 二, 失 業 率 大 幅 度 提 高, 國 家 就 會 變 得 動 蕩,

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING


i

untitled

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

Windows XP

TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc

untitled

Microsoft PowerPoint - OPVB1基本VB.ppt

2 WF 1 T I P WF WF WF WF WF WF WF WF 2.1 WF WF WF WF WF WF

Bus Hound 5

??? W?! W YAYA 2

2/80 2

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

untitled

透 過 選 擇 Google Street View 場 景 模 式 來 呈 現 實 際 道 路 上 的 狀 況 模 擬 並 且 經 由 預 先 紀 錄 好 的 各 國 都 市 座 標, 讓 使 用 者 可 以 選 擇 各 國 道 路 來 做 行 車 上 的 模 擬 使 本 系 統 不 僅 可 以

% %

目 录

untitled

untitled

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

untitled


Microsoft Word - 小心翼翼的二十一點N.doc

68369 (ppp quickstart guide)

目次 

RS-232C [11-13] 1 1 (PLC) (HMI) Visual Basic (PLC) 402

行业

投影片 1

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

C++ 程式設計

untitled

untitled

概述

VB控件教程大全

INTRODUCTION TO COM.DOC

USB解决方案.ppt

穨control.PDF

TC35短信发送程序设计

untitled

本 课 程 作 为 非 计 算 机 专 业 本 科 通 识 课 程, 是 一 门 理 论 和 实 践 紧 密 结 合 的 实 用 课 程, 内 容 包 括 计 算 机 基 础 部 分 和 程 序 设 计 部 分 计 算 机 基 础 部 分 涵 盖 计 算 机 软 硬 件 组 成 数 制 表 示 操

r_09hr_practical_guide_kor.pdf

Logitech Wireless Combo MK45 English

Contents

untitled


GoFlex Home UG Book.book

图 片 展 示 : 资 源 简 介 : FPGA Altera CycloneII EP2C5T144C8 (4608 个 LE) 2 路 有 源 晶 振 (50M,25M) AS & JTAG 标 准 接 口 VGA 接 口 UART 接 口 蜂 鸣 器 8bit 并 行 DAC 8 路 按 键

穨文件1

FILTRON 1. DC AC AC 220V 50HZ / / / / 4. 1) / DC AC FILTRON DC AC FILTRON DC 12V 12VDC D

untitled

Microsoft Word - 11.doc

行业

untitled

untitled

mvc

ICD ICD ICD ICD ICD

ebook39-6

錄...1 說...2 說 說...5 六 率 POST PAY PREPAY DEPOSIT 更

2/14 Buffer I12, /* x=2, buffer = I 1 2 */ Buffer I243, /* x=34, buffer = I 2 43 */ x=56, buffer = I243 Buffer I243I265 code_int(int x, char *buffer)

2 SGML, XML Document Traditional WYSIWYG Document Content Presentation Content Presentation Structure Structure? XML/SGML 3 2 SGML SGML Standard Gener

CANVIO_AEROCAST_CS_EN.indd


行业

51 C 51 isp 10 C PCB C C C C KEIL

VB程序设计教程

ebook140-9

行业

逢 甲 大 學

Measurement Studio Expands Your Test and Measurement Programming Power

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

CC213

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

CC213

IP505SM_manual_cn.doc

游戏厅捕鱼技巧_天天酷跑游戏技巧 2048游戏技巧,游戏厅打鱼技巧_


untitled

C35_RG_E.book

Transcription:

路 ESW 聯 USB Chapter 9 Applications For Windows

Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice

USB I/O

USB / USB 3 料 2 1 3 路

USB / 列 料 料 料 LED 料 料 ADC 類 / 數 料 DAC 數 / 類 USB-RS232 料

列 路

狀 數 TD_Init ( ) 狀 數 SETUP TD_Poll ( ) SETUP USB 流 1s 列 TD_Suspend 理 TD_Resume ( )

FIFO 0 1 FIFO 1

WDM -INF USB Plug and Play IDs Selecting Device Drivers to load http://www.microsoft.com/hwdev/busbios/usbpnp.htm

WDM -INF [USBBook] ;Uses the USBBook Vendor ID (1234) ;Uses the Product ID 5678 %USB\VID_1234 1234&PID_5678 5678.DeviceDesc%=IOHID, USB\VID_1234 1234&PID_5678.. [IOHID.CopyList] hidusb.sys hidclass.sys hidparse.sys ;---------------------------------------------------------------; [Strings] Provider="USB Book" MfgName="USB Book" USB\VID_1234 1234&PID_5678 5678.DeviceDesc="USB / "

USB I/O Windows AP INF(Driver) Windows AP VID PID INF (Driver)

USB 列 Control Panel 0547 0080 Ezusbw2k INF VB AP 1234 5678 HIDDEV INF

WDM -INF

USB USBCHECK.exe

USB

數 流

VB DLL ( ) newdll ' api 'opendevice : HID 'Writedevice : 料 HID 'Readdevice : HID 料 'closedevice : HID Public hid As New newdll Const MyVendorID = &H1234 Const MyProductID = &H5678 hiddevice = hid.opendevice(myvendorid, MyProductID) ; Text1.Text = hiddevice If hiddevice = True Then send(0) = Val( &H + Text2.Text) hid.writedevice send() ; 料 recevice() = hid.readdevice ; 料 Text3.Text = recevice(0) End If hid.closedevice ; End Sub

VB DLL ( )

http://www.microsoft.com/hwdev/usb hwdev/usb/

Application Requirements

Variable Definition VB Dim Execution As Integer Dim Speed As Integer Keil C int execution = 0; int speed = 0;

Integration VB OutputReportData(0) = Execution OutputReportData(1) = Speed Call WriteReport Keil C void ISR_Ep2out(void) interrupt 0 { : execution = OUT2BUF[0]; speed = OUT2BUF[1]; : }

Turn On/Turn off (VB) Private Sub Command1_Click() Execution = 1 - Execution If MyDeviceDetected = False Then MyDeviceDetected = FindTheHid If MyDeviceDetected = True Then OutputReportData(0) = Execution OutputReportData(1) = Speed Call WriteReport End If If Execution = 0 Then Command1.Caption = "Turn Off" Command1.Picture = Turnoff.Picture Else Command1.Caption = "Turn On" Command1.Picture = Turnon.Picture End If End Sub

LED Control (Keil C) int cnt = 0; int led = 1; int execution = 0; int speed = 0; void TD_Poll(void) { if (!execution) return; cnt++; if (cnt == 10000+speed*100){ cnt=0; P0=led; led<<=1; if(led == 256) led = 1;} }

Practice To design direction control for LED

Speed Control (VB) Private Sub HScroll1_Change() Speed = HScroll1.Value If MyDeviceDetected = False Then MyDeviceDetected = FindTheHid If MyDeviceDetected = True Then OutputReportData(0) = Execution OutputReportData(1) = Speed Call WriteReport End If End Sub

Using HID with Visual BASIC

VB-HID Development Steps host side Read Axelson Chapter 16 Human Interface Devices: Host Application Example Shows code for both VB and VC++ First edition of the book had a CD, Second edition does not Go to lvr.com, download usbhidio Unpack it VisualBasic folder has VB Project (usbhidio.vbp) In project Modules folder: ApiDeclarations.bas Contains VB declarations to allow VB to make C-style API calls VB application code in frmmain.frm Change VID and PID values to 0547/7450: 'Set these to match the values in the device's firmware and INF file. Const MyVendorID = &H547 Const MyProductID = &H7450

VB-HID Development Steps device side Keil project: gphid.uv2 fw2hid.c (from last session) gphid_descriptors.a51 INT-IN and INT-OUT endpoints Report descriptor specifies 2-byte in and out reports Compile and load the code Start the debugger First time: you ll see the HID Device Found box Readout should start incrementing

VB-HID Development Steps both sides Run the VB code It should find the device Then Allows you to send two-byte out reports First byte is readout increment rate Second byte is decimal point Shows the results of two-byte input reports First byte is current digit Second byte is pushbutton states

My Customization based on Jan s code

A VB HID Test Control Panel Click

Sending an OUTPUT Report The PC Side SendBuffer(0) = 0 The first byte is the Report ID SendBuffer(1) = 31 - hsrate.value ' next 2 bytes are data--rate SendBuffer(2) = dp ' decimal point NumberOfBytesWritten = 0 Result = WriteFile _ (HidDevice, _ SendBuffer(0), _ CLng(Capabilities.OutputReportByteLength), _ NumberOfBytesWritten, _ 0)

Sending an OUTPUT Report The Peripheral Side if(!(out1cs & bmepbusy)) // Is there something available? { timeconst = OUT1BUF[0]*20; // Output Report Byte 0 is time // const (tenths of sec) dp = OUT1BUF[1]; // decimal point OUT1BC = 0; // Re-arm EP1-OUT IN1BUF[0] = count; IN1BUF[1] = buttons; IN1BC = 2; // arm the EP2-IN transfer }

Reading an INPUT Report The PC Side Result = ReadFile _ (HidDevice, _ ReadBuffer(0), _ CLng(Capabilities.InputReportByteLength), _ NumberOfBytesRead, _ 0) tb7seg = Hex$(ReadBuffer(1)) ' put first byte value into text box (7-seg value) readval = ReadBuffer(2) ' get button states

Reading an INPUT Report The Peripheral Side if(!(out1cs & bmepbusy)) // Is there something available? { timeconst = OUT1BUF[0]*20; // Output Report Byte 0 is time // const (tenths of sec) dp = OUT1BUF[1]; // decimal point OUT1BC = 0; // Re-arm EP1-OUT IN1BUF[0] = count; IN1BUF[1] = buttons; IN1BC = 2; // arm the EP2-IN transfer }

Click below to find more Mipaper at www.lcis.com.tw Mipaper at www.lcis.com.tw