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