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