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