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