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