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