原來都寫串口的,現在要我寫并行口還有USB口
我暈,看來這回死定了
我連并口用到哪些API函數都不知道
# |7 N) Z9 K9 W: _( t+ W老大救命哦
[em06]API之打印函数:
AbortDoc 取消一份文档的打印 AbortPrinter 删除与一台打印机关联在一起的缓冲文件 AddForm 为打印机的表单列表添加一个新表单 3 r5 P" H! T6 D5 i3 ? AddJob 用于获取一个有效的路径名,以便用它为作业创建一个后台打印文件。它也会为作业分配一个作业编号 AddMonitor 为系统添加一个打印机监视器 ) y% t- ?' m& B$ T- W AddPort 启动“添加端口”对话框,允许用户在系统可用端口列表中加入一个新端口 4 c& h, g9 {2 o; y e# t AddPrinter 在系统中添加一台新打印机 4 {. |! U t% [: ]' i AddPrinterConnection 连接指定的打印机 AddPrinterDriver 为指定的系统添加一个打印驱动程序 * W& D3 B2 f) o- q7 v9 J AddPrintProcessor 为指定的系统添加一个打印处理器 1 I* {' L) g) ~, n: R AddPrintProvidor 为系统添加一个打印供应商 ) X$ H& e" t3 m# D AdvancedDocumentProperties 启动打印机文档设置对话框 % }1 P% ~% E3 ] ClosePrinter 关闭一个打开的打印机对象 ConfigurePort 针对指定的端口,启动一个端口配置对话框 5 O4 d: E" B2 A; f' W ConnectToPrinterDlg 启动连接打印机对话框,用它同访问网络的打印机连接 / m' A4 g- v" a DeleteForm 从打印机可用表单列表中删除一个表单 DeleteMonitor 删除指定的打印监视器 9 C7 a/ S. }- f2 X* ~- p. i/ Z DeletePort 启动“删除端口”对话框,允许用户从当前系统删除一个端口 DeletePrinter 将指定的打印机标志为从系统中删除 DeletePrinterConnection 删除与指定打印机的连接 DeletePrinterDriver 从系统删除一个打印机驱动程序 DeletePrintProcessor 从指定系统删除一个打印处理器 DeletePrintProvidor 从系统中删除一个打印供应商 ! i% D3 w5 U; U Y DeviceCapabilities 利用这个函数可获得与一个设备的能力有关的信息 DocumentProperties 打印机配置控制函数 EndDocAPI 结束一个成功的打印作业 EndDocPrinter 在后台打印程序的级别指定一个文档的结束 EndPage 用这个函数完成一个页面的打印,并准备设备场景,以便打印下一个页 ! {8 ?* h6 {: Z) V' b0 o z EndPagePrinter 指定一个页在打印作业中的结尾 : Z( E. ]( B, o! s& `% Q. l% u5 H EnumForms 枚举一台打印机可用的表单 . ?( d1 G: |; x" x0 j$ p EnumJobs 枚举打印队列中的作业 : K; H4 w, l: }, H8 ]$ i9 | EnumMonitors 枚举可用的打印监视器 ' q/ a' j1 o+ S. i3 l# K6 F EnumPorts 枚举一个系统可用的端口 # s6 c& z4 ]9 b8 ]1 Q" n( k: c1 o+ T: s EnumPrinterDrivers 枚举指定系统中已安装的打印机驱动程序 EnumPrinters 枚举系统中安装的打印机 EnumPrintProcessorDatatypes 枚举由一个打印处理器支持的数据类型 9 R2 r! @9 ] v" n EnumPrintProcessors 枚举系统中可用的打印处理器 Escape 设备控制函数 ; [7 m6 E+ J- `5 n1 m- X FindClosePrinterChangeNotification 关闭用FindFirstPrinterChangeNotification函数获取的一个打印机通告对象 FindFirstPrinterChangeNotification 创建一个新的改变通告对象,以便我们注意打印机状态的各种变化 ( t( j6 Q+ |4 [9 x2 w9 y% V p0 [0 T FindNextPrinterChangeNotification 用这个函数判断触发一次打印机改变通告信号的原因 ; k0 g0 ~7 B- b. X; g9 x \5 C) z5 ~ FreePrinterNotifyInfo 释放由FindNextPrinterChangeNotification函数分配的一个缓冲区 7 S8 I, T$ X( D7 p) i: n GetForm 取得与指定表单有关的信息 6 B9 I1 n& q1 u7 K r GetJob 获取与指定作业有关的信息 : r4 B0 ?2 ~6 w GetPrinter 取得与指定打印机有关的信息 ! Z0 U* E& j2 o+ t- N& ~; a( W, e GetPrinterData 为打印机设置注册表配置信息 3 P6 {3 ~0 F( A3 p3 g& K GetPrinterDriver 针对指定的打印机,获取与打印机驱动程序有关的信息 - v- @0 N4 U/ ?( h' r$ }8 a4 | GetPrinterDriverDirectory 判断指定系统中包含了打印机驱动程序的目录是什么 GetPrintProcessorDirectory 判断指定系统中包含了打印机处理器驱动程序及文件的目录 % H7 O& B2 \. B; |5 L OpenPrinter 打开指定的打印机,并获取打印机的句柄 3 e* ], m6 O, ~: f( l% | PrinterMessageBox 在拥有指定打印作业的系统上显示一个打印机出错消息框 PrinterProperties 启动打印机属性对话框,以便对打印机进行配置 ReadPrinter 从打印机读入数据 8 V3 d0 z% [0 `& s) y& {$ E' R ResetDC 重设一个设备场景 # R, M9 w' I) }0 g: R: J9 w R ResetPrinter 改变指定打印机的默认数据类型及文档设置 ScheduleJob 提交一个要打印的作业 SetAbortProc 为Windows指定取消函数的地址 0 I6 h- `: w& I- H) Q% [$ P7 W SetForm 为指定的表单设置信息 [1 O. M) }3 ? SetJob 对一个打印作业的状态进行控制 SetPrinter 对一台打印机的状态进行控制 5 l& q4 Z2 |& `1 Y SetPrinterData 设置打印机的注册表配置信息 4 ?$ v' L$ e- n1 s StartDoc 开始一个打印作业 StartDocPrinter 在后台打印的级别启动一个新文档 StartPage 打印一个新页前要先调用这个函数 StartPagePrinter 在打印作业中指定一个新页的开始 WritePrinter 将发送目录中的数据写入打印机看到这样一个usb通讯的帖子,可能对你有用!
主 题: 关于usb通讯方面的问题。请AKing大哥及相关高手来看看,万分感激!!! ! o1 I! h" N6 D) z' S 作 者: aiyu33 ()
等 级: 信 誉 值: 100 所属论坛: C++ Builder Windows SDK/API 3 h& A( l4 T7 j, D# j2 `. ^ 问题点数: 100 1 i, T# K+ H# M5 m( ^ 回复次数: 12 5 a8 h. u' N2 R. T$ b- | 发表时间: 2003-12-16 20:43:13 . q& `9 D# x% ?1 l( ~5 W( U' w. A: S最今我接到了开发pc和pocket pc通过usb口通讯的任务。这两个星期我参考了很多方面的资料,特别是AKing大哥写的一些文章。但我始终没有打通这个关口,我贴出我的代码请AKing大哥看看,现在很急,多谢。1 i% O: S# k! {/ Z( ] pc的os是windows2000professional
pocket pc是hp ipaq 2210,os 是pocket pc2003。 {+ c, z2 N1 G/ z5 ^8 N 我装了activesync3.7。我查看过了,这个activesync目录下有pocket pc的驱动程序。pc也能识别。; c& H+ f$ r4 Z) @" {! v: d 下面是我在pc上调用usb的代码。 下面的代码我能打开hidn类型的usb,但是就是不能打开pocket pc的usb。 //classGuid = {25dbce51-6c8f-4a72-8a6d-b54c2b4fc835} DEFINE_GUID(GUID_CLASS_PALM, 1 H& s$ a7 @% Z6 v 0x25dbce51, 0x6c8f, 0x4a72, 0x8a, 0x6d, 0xb5, 0x4c, 0x2b, }' e3 M( V; z& ^ 0x4f, 0xc8, 0x35); GUID HidGuid = GUID_CLASS_PALM; HANDLE Get_DeviceHandle( GUID* pGuid) {( f+ M8 Q5 P+ n7 x5 l( ~* G 6 ]8 M6 M' a9 f, x. z& R' h6 m- `' ~ HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if(info==INVALID_HANDLE_VALUE)) H1 X" F8 H; w- I( n {! Y% i0 a' x$ b4 C printf("No HDEVINFO available for this GUID\n"); return NULL; }7 ?5 ^: K+ A* A: \ SP_INTERFACE_DEVICE_DATA ifdata; ifdata.cbSize = sizeof(ifdata);$ W5 z( E4 Z n Q1 f) R //0000是我在注册表中找到的序号 m* m6 r. Z" P2 g5 D if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, 0000, &ifdata))$ r! m) X/ L9 j$ Q% {( _; S { printf("No SP_INTERFACE_DEVICE_DATA available for this GUID instance %d \n", instance+1);! [0 y' l5 j; w SetupDiDestroyDeviceInfoList(info);8 s) ]" q4 Y3 B return NULL;& J9 S% e$ L/ v, H1 E }// Get size of symbolic link name
DWORD ReqLen; % k' }" o9 |* { |' ]- V7 M SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL); ; n- o# A- e% ?. y0 _$ G3 I0 @4 b PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]);6 |& q+ w; T1 \$ H3 k7 y / s) S3 v7 O& H; O if( ifDetail==NULL)9 V2 |7 ~2 ?# P { SetupDiDestroyDeviceInfoList(info);2 Y6 L& c4 I& s return NULL; }// Get symbolic link name2 i' {3 i+ ~1 u1 J( _5 Q& {: p, n- q ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);2 \3 f; n+ k4 J* x1 ~. Y
if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info);2 E8 ^ F2 W. x0 o delete ifDetail;2 r! c5 o8 x0 Y6 x: I( d W& c C0 P return NULL; 9 W! K% Y- L' h) a8 s# p }printf("Symbolic link is %s\n",ifDetail->DevicePath);# T+ o* U7 T/ [$ o# Q% c' @
/*\\?\\usb#vid_03f0&pid_1016#5&1bc41f6c&0&1#{25DBCE51-6C8F-4A72-8A6D-B54C2B4FC835}这是ifDetail->DevicePath的内容*/
// Open file, i' h% Q/ r, \- j8 o9 ^ //前面都很正常但就是下面始终得出一个无效的句柄,我也就无法开展下一步的工作. HANDLE pDevice = CreateFile(! ~: P5 z; J7 D% K! I3 {7 k ifDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,( R: g1 s$ ^) I* m* J NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 3 P0 R6 h8 V5 C4 R if( pDevice==INVALID_HANDLE_VALUE) pDevice = NULL;+ g( `9 b; \2 G1 L SetupDiDestroyDeviceInfoList(info);; D" C! `) ?" q. p9 V3 H1 }! L3 `) a return pDevice;. i! B5 A' m ^/ y }1 A( V! N3 c) |' z4 G$ c 再次感谢关注这个问题的人们。6 N2 f' B* e( | V' L 回复人: constantine(飘遥的安吉儿) ( ) 信誉:101 2003-12-16 21:23:57 得分:0 ; N4 A, x. M9 i. l/ I/ I study
1 a$ K" @6 y! ~2 X7 k- r! p& c- o Top 回复人: wenyongjie(一个想成为大鸟的小菜鸟) ( ) 信誉:95 2003-12-16 22:28:46 得分:0 - ?' k/ O( I% K0 K9 x , p9 @& [; _) [2 y3 X 只有学习的份
Top * `7 t4 r* A( ?! C2 E; k( a' b' F4 m% B 回复人: HUANG_JH(保卫钓鱼岛) ( ) 信誉:115 2003-12-17 9:50:41 得分:10 % J+ x5 G S- H% x. L 不知道有没有用!
///////////////////////////////////////////////////////////////$ w/ W3 g4 b# o1 q; |, l // HW9911 evaluation board software Rev. 1.0 hugehard@263.net // or contact HEAD Co. by Tel 86-10-87312497 // or by fax: 86-10-87312495 n# ~' i! }( |& [2 }; q) _ ///////////////////////////////////////////////////////////////
// program by Liu Ding, Bei Jing HEAD Elec. // this is the main program for the HW9911 USB device evaluation board# T# J; a! a9 r4 \2 Q: g- R& ~5 y$ a // it illustrate the basical read/write process of HW9911 // by three examples: // 1. write datas to ram on the evaluation board7 F" g4 x7 y" F% n( I7 V7 \" R // 2. read the datas from the ram on the board8 K+ N8 a% q0 P // 3. send datas through RS-232 serial prot on the board // // the whole project are build with MSVC 6.0 // and tested on windows 98 platform.- p8 O3 c% E0 V // // notes: you can use hyper terminal to reaceive datas form RS232 port //' } i% i- _5 I c2 P: ]# n. u# U // this software are designed by Liu Ding // if you meet any problems, pls contact by email: //#include "hwdll.h"; G: `% P* ] [( e) Y #include "stdafx.h"5 k9 x7 }+ M1 a& P4 w #include <stdio.h>* F/ _6 }( J6 ^# K6 e #include <windows.h>9 E; r$ `4 a7 {6 \! K( i- x #include <memory.h>
#include <DEVIOCTL.H>9 H3 c$ n d, J3 h0 T1 T7 N& ~ #include <stdlib.h> #include <conio.h> #include "hw9911.h"6 t2 p: o- N! ^ #include "test9911.h"int main(); m. J- L; n- v- q5 b. q {2 O& A* o N7 A# x# O: l% V5 Y int hOpen=FALSE; int hCommandLength=32; int hDataLength=64; int i,VertAddr=0,HorAddr=0; int addr,TotalLen; USC StAddrH=0,StAddrL=0; USC DataLenH,DataLenL; USC *hDataBuffer,*hCommandBuffer; USC ch1=0x61; HANDLE hDeviceHandle; printf("************************************************\n"); printf("*******HW9911 USB DEVELOPMENT BOARD*************\n"); printf("************************************************\n\n"); printf("now press any key to open board\n"); getch();
/********* call hDeviceOpen in hwdll.dll to open the board***/
//hOpenDevice 说明: // BOOL hOpenDevice(HANDLE *DeviceHandle)+ c% e2 }2 B& Y3 Y1 Z: y/ X0 D6 d5 O5 G // 作用:打开设备 // 参数说明: // DeviceHandle:设备句柄/ h Q% g( L& h( T: j // 返回值:. q* p* m( ?8 Q4 c* e // 设备打开成功返回 TRUE,失败则返回FALSE if( (hOpen = hOpenDevice( &hDeviceHandle ))==FALSE); ]6 r$ J( v9 r/ K/ ? { printf("can't open device\n");, F& f7 y' s& ^4 ^( Z T! F) Y printf("press any key to exit\n");3 N* w9 R/ S& F! ]/ d7 Z getch(); return 0;! |4 k! k1 s, R$ f5 z; \+ y }" u. [! J% \" ] {6 C else 0 o' A. ?: e K6 P" ` printf("\nCongratulations! device opened!\n\n");/****** build and send command **********/
printf("how many bytes do you want to access?");. ?1 Z8 t! o8 ~& d& q# v+ C scanf("%x",&TotalLen); while(TotalLen > 0x7fff) {* f# }+ R2 t/ s* @3 p J printf("pls input a hex data less than 08000\n");3 s+ t3 Q4 F. I, s+ M1 X: l scanf("%x",&TotalLen); } DataLenH=(USC)(TotalLen/0x100); //data length high bytes DataLenL=(USC)(TotalLen%0x100); //data length low bytesprintf("************************************************\n");+ x( b) d$ N" U" x8 C& D printf("now program will write datas to ram on board\n");4 h- d* x7 Q0 Q2 X Q8 w$ V printf("total bytes of datas is %x\n",TotalLen);1 |& ?) L7 ]4 U+ e) }) y7 r printf("press any key to continue\n\n");4 R5 V8 Z/ A& Z getch();5 y$ F# k. u3 u* q1 N8 ? /*****************************************************************- T$ |# E7 g2 g! K! |$ e now will build a write command packet
with the first byte is 'w'.% A* z- A# Z( I4 G; }0 ? F% A and the following bytes are: start ram address byte high, start ram address byte low, datalength byte high, data length byte low. this packet will send to device through WritePipe1,7 F+ A" @6 r, J5 s; j7 s1 { which is endpoint 2 of HW9911. when the device receive this command packet,4 S/ ?- y) v2 B3 G& {: x it will write TotalLen bytes data to Ram on the board) x0 @' i/ T, t3 S y ******************************************************************/hCommandBuffer=(USC *)malloc(hCommandLength);% Z/ T& B6 T4 O1 b2 Q! ~6 T hDataBuffer=(USC *)malloc(hDataLength); hCommandBuffer[0] = 'w'; //read command hCommandBuffer[1] = StAddrH; hCommandBuffer[2] = StAddrL; hCommandBuffer[3] = DataLenH; hCommandBuffer[4] = DataLenL;
/* call hUSBIO() in hwdll.dll to send command packet to device*/4 `% s: ]. Z8 b // hUSBIO 说明:$ \; v% T% { F // BOOL hOpenDevice(HANDLE *DeviceHandle,: x) V$ i. `4 p( \5 q) K8 Q# G! m; X // unsigned char *IOBuffer,
// int BufferLength, // int PipeNumber,4 U9 l% f- F7 c' G4 d4 M3 c // int Action) // 作用:设备读写 // 参数说明:3 x* a9 n5 y8 m. _8 {, m! i- X // DeviceHandle:设备句柄5 c' B: d% _1 \, U: w# ?( f% @ // IOBuffer: 指向要传送的数据指针 // BufferLength: 数据包长度! i2 g( y$ e: N: ~$ u // 对于发送缓存1、2和接收缓存1、2,BufferLength必须小于或等于325 w; S4 ]1 x1 j' I; |# d0 y" B // 对于发送缓存3和接收缓存3,BufferLength必须小于或等于64 // PipeNumber: 通道号 // 发送缓存1:PipeNumber=0; // 接收缓存1:PipeNumber=1;# x" Y6 H/ J3 r" l w9 C1 W7 U // 发送缓存3:PipeNumber=2; // 接收缓存3:PipeNumber=3; // Action: 读写标志。TRUE代表从设备读数据到主机1 ^9 {& Q9 j! z: @ // FALSE代表从主机发送数据到设备 % n0 o! C6 }0 H8 N1 B; M // 操作接收缓存,Action必须为FALSE6 K3 T& c) b; O: O3 a0 ? // 操作发送缓存,Action必须为TRUE9 R( r( X% u5 ~# G# Q/ o // 返回值: // 操作成功返回TRUE,失败返回FALSEif ( hUSBIO( &hDeviceHandle,: _% p4 w; p5 M! P hCommandBuffer,
hCommandLength, hWritePipe1,, m0 W6 g; b" z5 O8 v FALSE) == TRUE)- _/ o4 k5 H9 l; J$ P { printf("command 'w' writed to board\n"); ? H+ H9 ?# e3 V$ P; ?4 | printf("now press any key to write datas to ram\n");% r; b/ W8 R: N( ~- f! P getch();5 `$ }1 y+ p" T+ U: D- d: Y- r# D U } else printf("data can't write to device\n");/******** write ram data to board **********/
printf(" ");+ C" J5 _% U5 Q& E0 y" U/ Q( y( u for(VertAddr=0;VertAddr<=0xf;VertAddr++)
printf("%02x ",VertAddr);+ b9 _7 X2 k# s/ w printf("\n"); addr=0; while (addr<TotalLen); i. X1 q" y: O1 @ o# K/ B6 a. J { if (addr+hDataLength > TotalLen)1 D n1 x- J3 ] ~0 x hDataLength = TotalLen-addr;# L0 p# |% H, c* `, T for(i=0;i<hDataLength;i++)) p7 W/ y2 @0 T- A { P, l% {- B0 l hDataBuffer=ch1++;6 ^5 A" e: O8 u: J! t% B( ~9 }9 ~8 L if (ch1 > 0x80) 1 A9 P' r5 g# t! M3 j ]1 R ch1 = 0x61;" W* J9 t+ g, r5 P) Q5 Y" L2 ?1 Q' W6 K/ {$ U }8 |( U6 W! O# G; E) A3 Y9 D /* call hUSBIO to write datas to write pipe3, which is endoint 6 of HW9911*/if ( hUSBIO( &hDeviceHandle,
hDataBuffer, hDataLength, hWritePipe3, ( Y3 P! b( Y9 f& }' @ FALSE) == TRUE) //FALSE means Write operate" C1 y, t* N9 |4 c { for(i=0;i<hDataLength;i++) {0 Q( L. d; P5 A) P) E /* print format control */ if(i % 16 == 0) ' \. M% X' N4 N: o+ G) J& a {* Y8 \/ e, \$ T' H: x printf("\n%04x ",HorAddr);' O u5 `' d% h9 h HorAddr=HorAddr+16; } printf("%02x ",(USC)hDataBuffer);" X9 j! B+ b3 F }- Y1 v1 X' x0 L+ Y* T0 R addr=addr+hDataLength; } else { printf("can't write to board\n"); exit(0);, L/ b' R9 f/ a, w }5 ~) y* I: x7 j4 Q* K } printf("\n\nTotal%x bytes write to ram OK\n\n",TotalLen);7 N9 l: j9 v* b8 t" q ! R9 p3 i+ |6 i# D* l! {0 ~ Top
+ R7 W+ F: l) t. X8 B/ l( j6 y, c 回复人: HUANG_JH(保卫钓鱼岛) ( ) 信誉:115 2003-12-17 9:50:51 得分:0 : v0 P! @" n j. H& r * \, U3 x* }0 t' L7 a( o/*****************************************************************
now will build a read command packet 7 m* t; U% g2 \; B with the first byte is 'R'.! c* G$ K1 |" m6 V and the following bytes are:! D# P! u# t& W3 B3 t& u8 @ start ram address byte high, start ram address byte low,& ~4 j( |& N, P* w% j# {4 ? r5 o datalength byte high, data length byte low.+ ~; A+ m. J. w' _, w% D this packet will send to device through WritePipe1, which is endpoint 2 of HW9911.( d0 F4 ]; M$ M! G when the device receive this command packet,6 d5 U F' b/ _; f5 @) K9 g it will read TotalLen bytes data from Ram on the board ******************************************************************/printf("************************************************\n"); K' W7 o. k! [3 u% a. e: @! { v printf("now program will read datas from ram on board\n");" ]& @! X5 S# v printf("total bytes of datas is %x\n",TotalLen);% x0 Q" V' C+ r: f0 N" D printf("press any key to continue\n\n");: g. k' N/ ]- G1 y- {% h8 n M getch();
hDataLength=64; hCommandBuffer[0] = 'r'; //read command hCommandBuffer[1] = StAddrH; hCommandBuffer[2] = StAddrL; ! I) Y" k! k! a% y; ^5 O hCommandBuffer[3] = DataLenH;; D1 v3 U; f' S! n hCommandBuffer[4] = DataLenL; ) o/ e2 _5 R% H8 G2 b6 _" G! Z /* call hUSBIO to send packet */ if ( hUSBIO( &hDeviceHandle,' ~( V. p# a8 P( T' l4 j; _0 }$ o hCommandBuffer, hCommandLength, hWritePipe1,$ g o3 ]5 G. t" n1 G9 i. t FALSE) == TRUE)! Y) G( I' Z% l, a" o' ]4 K4 y j { printf("command 'r' writed to board\n"); printf("now press any key to read datas from ram\n\n");; p0 K% T5 x4 w0 s1 y getch();. Q9 Y( o" M" E3 r3 \. ] }7 T* l/ |" N& v6 V3 P else printf("data can't write to device\n");/******** read ram data form board **********/
printf(" ");+ H5 [5 h$ y! m for(VertAddr=0;VertAddr<=0xf;VertAddr++) printf("%02x ",VertAddr); printf("\n"); addr=0; HorAddr=0; while (addr<TotalLen) { if (addr+hDataLength > TotalLen); \) ~* \% L2 ? t* \4 c; t: v n hDataLength = TotalLen-addr;- \( U7 z& p/ u9 c: I /* call hUSBIO to read datas from board */ if ( hUSBIO( &hDeviceHandle,2 j5 s2 y8 B9 j' G- f# [! ?# h hDataBuffer, hDataLength, hReadPipe3, TRUE) == TRUE) //TRUE means Read Operate {# `( z3 H. v4 l" R; A6 y' H for(i=0;i<hDataLength;i++)- F: |, m: R$ z8 G q2 _: h$ G { /* print format control */2 }! V: V p5 n" m l% t1 G if(i % 16 == 0) { printf("\n%04x ",HorAddr); HorAddr=HorAddr+16; } printf("%02x ",(USC)hDataBuffer); } addr=addr+hDataLength; }' Q. i5 u( Z" ~& @/ p0 o else {8 U- V+ z% D+ Q printf("can't read from board\n");8 p; \( u4 @ S6 C" r1 X exit(0); }* F7 m Q4 E- [& l }7 D, l v2 M8 u printf("\n\n");! |; I. |; h ~! P2 { printf("%x bytes read from ram OK\n\n",TotalLen);/*****************************************************/
/* process rs232 test */$ c8 j& x5 b) `( q* E /* the first byte in this packet is command 's' */( j. E: b" s) @; v /* and the following 2 bytes are used to set */" I7 ?, _8 i. @+ G Q /* the baud rate of 8051 *// _+ \1 q# i5 a6 o2 @ /* they will be write to TH1 and TL1 respectively*/ /* the following bytes are datas will be */ /* send through RS232 serial poart */: P' m7 M$ l" \ /*****************************************************/3 p6 k6 s; R- X printf("\npress any key to process RS232 Test\n");( {; \; x; c, n9 o: y1 j getch(); . D+ V% M& ]" w& M9 P" i& D6 a USC TH1,TL1;" o5 y8 A4 F7 Q+ z# O char hStr[30]; TH1=(USC)(BD9600/0x100); TL1=(USC)(BD9600%0x100); hCommandBuffer[0] = 's'; //read command, A7 a' I4 k3 k. Z hCommandBuffer[1] = TH1; hCommandBuffer[2] = TL1; //start address is 0x0000strcpy(hStr, "Hi, dear HW9911 consumers! "); E# Q% i( X, ]; K3 ^; z) F printf("Hi, dear HW9911 consumers! ");
memcpy(&(hCommandBuffer[3]),hStr,27);if ( hUSBIO( &hDeviceHandle,
hCommandBuffer, 30, hWritePipe1,8 k2 {' l8 u6 p) m. a FALSE) == FALSE)! A0 x1 L: N- ~ { printf("can't write datas to RS232\n");3 h/ T0 y: A* I, w) m3 E exit(0); }strcpy(hStr, "I'm HW9911 Evaluation Board, ");
printf("I'm HW9911 Evaluation Board, "); memcpy(&(hCommandBuffer[3]),hStr,29); ' Y' K; c$ A+ j/ e if ( hUSBIO( &hDeviceHandle, hCommandBuffer, 32, hWritePipe1, FALSE) == FALSE) { printf("can't write datas to RS232\n");+ ] _6 ]9 Y$ d1 C5 @ exit(0); }strcpy(hStr, "thanks for purchasing me, ");
printf("thanks for purchasing me, "); memcpy(&(hCommandBuffer[3]),hStr,26);4 u0 D+ m) a5 U' k 0 X1 f, j8 A+ H if ( hUSBIO( &hDeviceHandle, hCommandBuffer,; p% x; ~3 }' t' @1 w9 r 29,8 }3 V2 l& S) ]/ A' u/ s( d# Y7 o hWritePipe1,% P! \( N/ |' H6 T FALSE) == FALSE) {, N( L X+ f7 c$ r2 y! M printf("can't write datas to RS232\n");4 J2 i# v8 ^$ j6 I0 @2 A exit(0); }$ v$ x1 `% i M% `) S strcpy(hStr, "If you meet some problems, ");, Z# Y+ _. U3 y; z( L( {9 S) Q printf(hStr, "If you meet some problems, "); memcpy(&(hCommandBuffer[3]),hStr,27);( V6 {3 [+ Y- m) c: B if ( hUSBIO( &hDeviceHandle,) k+ Q' _& t* n; ~. | hCommandBuffer,* L( T2 N l& q5 ?1 _6 Q D. s3 W 30, hWritePipe1,( F9 ?3 `* Z* R7 B( z FALSE) == FALSE)- M' ^% N0 C% R- V+ q6 G( I {% A4 k5 N: z' D' t printf("can't write datas to RS232\n"); exit(0); }strcpy(hStr, "pls contact my designer ");) u* D9 i7 G( F4 l C' l printf("pls contact my designer ");; k' z9 ^; h2 p0 T: }9 }8 U# a memcpy(&(hCommandBuffer[3]),hStr,24);9 X9 y D, t5 B0 O# r5 F
if ( hUSBIO( &hDeviceHandle,) b# }7 T' c+ S hCommandBuffer, 27, hWritePipe1, FALSE) == FALSE) d) r! k3 _5 T0 p4 b { printf("can't write datas to RS232\n");0 |) d# [+ V; Q' v' W4 b8 | exit(0); }strcpy(hStr, "by email: hugehard@263.net."); printf("by email: hugehard@263.net.\n"); memcpy(&(hCommandBuffer[3]),hStr,27); if ( hUSBIO( &hDeviceHandle,) x; I' n5 @- N( q5 \ hCommandBuffer, 30, hWritePipe1,6 V" s( l$ ^! M s! L5 S FALSE) == FALSE) { printf("can't write datas to RS232\n"); exit(0); }: y% P7 t7 n2 V, K/ X: m; c4 b- f /********* call hDeviceOpen in hwdll.dll to open the board***// o+ N" u4 F6 k- v // hCloseDevice 说明: // BOOL hCloseDevice(HANDLE *DeviceHandle) // 作用:关闭设备 // 参数说明:( Y4 p X- h; q7 | // DeviceHandle:设备句柄4 e' F: c7 `( w. e; w // 返回值: // 设备关闭成功返回 TRUE,失败则返回FALSE if( (hOpen = hCloseDevice( &hDeviceHandle ))==FALSE): s, ?5 i( L N {( G5 s. Y4 ?; j, |" K! w' r printf("can't open device\n"); printf("press any key to exit\n"); getch();; O! M$ [6 Q3 T; | return 0; } else 3 y( y# R5 z. R- Q3 V: Q printf("device closed\n");
printf("press any key to exit the program\n");
free(hDataBuffer);. _! u3 |" f( M' t4 l free(hCommandBuffer); getch();" V5 l2 h% V& K. `( s3 f return 0;$ J: W8 Q# [ W }- F: x' p1 c3 ? Top / ^7 _2 v+ ~+ l1 g$ g & N5 }! _) [0 G 回复人: aiyu33() ( ) 信誉:100 2003-12-17 11:41:24 得分:0 ! i0 a" j+ _( U+ Y, [ ! W7 E- E: ^. `, T( H upupupupupupup
Top 7 T( q! P# P: {$ F4 B2 C+ K2 ~2 L 回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 12:53:39 得分:0 . C1 B; u& L3 z M3 [ p! U0 t- Q/ D1 k1 e 9 X! D: ~) \' Q, z7 c( o4 s/ }/ Z I) s 你开发的这种软件类似于Palm Desktop Software,负责Pocket与PC之间通讯,我建议你最好先写一个驱动,将USB口虚拟成一个串口,然后直接对串口操作会很方便的。我现在做的程序可能和你相似是一个CDMA模块,通过USB口与PC机连接,然后由驱动程序将它虚拟成一个串口,我的工作就是和这个虚拟的串口通讯。
Top 5 p( ]% Y# S: X6 `3 a* A% P 回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 12:56:27 得分:0 - @8 h3 N0 r: ` Pocket与PC连接肯定有驱动的,如果驱动程序没有将Pocket虚拟成一个串口,你也可以直接通过设备GUID和设备序列号进行访问,详情你参见我专栏上的一篇文章。当然了,通过虚拟串口来访问设备肯定要方便,简单些。
4 [( u2 C/ c0 I " Q/ }, w2 a, \1 J) y0 h7 _4 l Top 0 Y( L5 I$ {/ \ ; l* E' W; U1 M6 @9 I* B" B2 k2 p. X 回复人: aiyu33() ( ) 信誉:100 2003-12-17 13:31:08 得分:0
7 S! y0 k& f+ f" ] a$ [$ O3 k) r % g/ a5 g' x* ?3 l8 q - |9 i5 W9 T; I5 V+ M 我得这款pocketpc默认只支持使用usb与pc相连的,而且activesync3.7就是使用usb传输数据的。如果我自己写驱动的话,不仅不熟悉而且很可能activesync3.7这个软件就使用不了。我只需要利用它的驱动。你的专栏上的那篇文章我也看了,我就是模仿你的写的代码,但就是到createfile这步就不行了,我的同事是用palm开发类似的程序,也是到这步就行不通了,是不是有其他的原因? 我还想问问如果驱动程序将pocket虚拟成串口,如何查看它的符号名呢?! ~& W, o5 o; e" Z; o8 h 0 O& k+ z9 z& R$ z" c9 z4 f/ H 4 i$ E5 f3 ]# |2 E9 m Top
回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 16:53:17 得分:0 假如将一个USB设备虚拟成串口的话,那么它的符号名可能是COM3,COM4,或COMn,这根据你当前PC机的配置而定 。它的符号名位于注册表中HKEY_LOCAL_MACHINE\CurrentControlSet中,你可以搜索注册表,另外在2000或以上的操作系统中,你可以到HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SerialComm中看到。Top " U1 a% u4 g/ n ? 回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 16:55:33 得分:0 7 }0 q# h& X0 A7 j0 z ! N) b" F) J. F( }7 B. H: X) S$ p! J + s0 J& s3 k5 p# F. s+ | 我以前在一张贴子中详细回答了如何利用设备序列号和设备GUID来访问该设备,你可以搜索一下CSDN。你所说的CreateFile不能打通设备,你要查一下,你的符号名是否正确,包括设备序列号和设备GUID是否正确,设备GUID你可以从驱动程序的安装向导文件.inf中找到,设备序列号则需要你到注册表中去找。
0 o+ l" s& Z9 y$ H& Q 4 `7 _. r5 {# Y( @ Top 0 v* \, `" k8 ?9 W: k% p1 R) p
回复人: gyj_china(透明) ( ) 信誉:98 2003-12-17 18:15:30 得分:90 , q) O$ A3 J1 U5 ^* U" a& C 没有星星不敢发言:(# M$ g9 J, a6 M, G5 F
Top % ^ H7 V( w | L8 C 回复人: aiyu33() ( ) 信誉:100 2003-12-19 18:27:28 得分:0 8 e% L; `9 \& E3 N7 u% K " z2 L! O! @% J : p! L3 \1 b, }* E% _ 不好意思,是因为ActiveSync3.7一直在系统服务程序中运行,占用了驱动程序,所以不能打开设备。我删除了ActiveSync3.7后就可以了。大哥太好了
; D5 {' X Y* w4 {5 c7 \' J正是我想要的
謝謝你
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |