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