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