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