老大,怎麼寫并行口呢?用到哪些API函數阿
<P>原來都寫串口的,現在要我寫并行口還有USB口</P><P>我暈,看來這回死定了</P>
<P>我連并口用到哪些API函數都不知道</P>
<P>老大救命哦</P> 而且書上都找不到哦 <P>API之打印函数:
AbortDoc 取消一份文档的打印
AbortPrinter 删除与一台打印机关联在一起的缓冲文件
AddForm 为打印机的表单列表添加一个新表单
AddJob 用于获取一个有效的路径名,以便用它为作业创建一个后台打印文件。它也会为作业分配一个作业编号
AddMonitor 为系统添加一个打印机监视器
AddPort 启动“添加端口”对话框,允许用户在系统可用端口列表中加入一个新端口
AddPrinter 在系统中添加一台新打印机
AddPrinterConnection 连接指定的打印机
AddPrinterDriver 为指定的系统添加一个打印驱动程序
AddPrintProcessor 为指定的系统添加一个打印处理器
AddPrintProvidor 为系统添加一个打印供应商
AdvancedDocumentProperties 启动打印机文档设置对话框
ClosePrinter 关闭一个打开的打印机对象
ConfigurePort 针对指定的端口,启动一个端口配置对话框
ConnectToPrinterDlg 启动连接打印机对话框,用它同访问网络的打印机连接
DeleteForm 从打印机可用表单列表中删除一个表单
DeleteMonitor 删除指定的打印监视器
DeletePort 启动“删除端口”对话框,允许用户从当前系统删除一个端口
DeletePrinter 将指定的打印机标志为从系统中删除
DeletePrinterConnection 删除与指定打印机的连接
DeletePrinterDriver 从系统删除一个打印机驱动程序
DeletePrintProcessor 从指定系统删除一个打印处理器
DeletePrintProvidor 从系统中删除一个打印供应商
DeviceCapabilities 利用这个函数可获得与一个设备的能力有关的信息
DocumentProperties 打印机配置控制函数
EndDocAPI 结束一个成功的打印作业
EndDocPrinter 在后台打印程序的级别指定一个文档的结束
EndPage 用这个函数完成一个页面的打印,并准备设备场景,以便打印下一个页
EndPagePrinter 指定一个页在打印作业中的结尾
EnumForms 枚举一台打印机可用的表单
EnumJobs 枚举打印队列中的作业
EnumMonitors 枚举可用的打印监视器
EnumPorts 枚举一个系统可用的端口
EnumPrinterDrivers 枚举指定系统中已安装的打印机驱动程序
EnumPrinters 枚举系统中安装的打印机
EnumPrintProcessorDatatypes 枚举由一个打印处理器支持的数据类型
EnumPrintProcessors 枚举系统中可用的打印处理器
Escape 设备控制函数
FindClosePrinterChangeNotification 关闭用FindFirstPrinterChangeNotification函数获取的一个打印机通告对象
FindFirstPrinterChangeNotification 创建一个新的改变通告对象,以便我们注意打印机状态的各种变化
FindNextPrinterChangeNotification 用这个函数判断触发一次打印机改变通告信号的原因
FreePrinterNotifyInfo 释放由FindNextPrinterChangeNotification函数分配的一个缓冲区
GetForm 取得与指定表单有关的信息
GetJob 获取与指定作业有关的信息
GetPrinter 取得与指定打印机有关的信息
GetPrinterData 为打印机设置注册表配置信息
GetPrinterDriver 针对指定的打印机,获取与打印机驱动程序有关的信息
GetPrinterDriverDirectory 判断指定系统中包含了打印机驱动程序的目录是什么
GetPrintProcessorDirectory 判断指定系统中包含了打印机处理器驱动程序及文件的目录
OpenPrinter 打开指定的打印机,并获取打印机的句柄
PrinterMessageBox 在拥有指定打印作业的系统上显示一个打印机出错消息框
PrinterProperties 启动打印机属性对话框,以便对打印机进行配置
ReadPrinter 从打印机读入数据
ResetDC 重设一个设备场景
ResetPrinter 改变指定打印机的默认数据类型及文档设置
ScheduleJob 提交一个要打印的作业
SetAbortProc 为Windows指定取消函数的地址
SetForm 为指定的表单设置信息
SetJob 对一个打印作业的状态进行控制
SetPrinter 对一台打印机的状态进行控制
SetPrinterData 设置打印机的注册表配置信息
StartDoc 开始一个打印作业
StartDocPrinter 在后台打印的级别启动一个新文档
StartPage 打印一个新页前要先调用这个函数
StartPagePrinter 在打印作业中指定一个新页的开始
WritePrinter 将发送目录中的数据写入打印机
</P> <P>看到这样一个usb通讯的帖子,可能对你有用!</P><P>主 题: 关于usb通讯方面的问题。请AKing大哥及相关高手来看看,万分感激!!!
作 者: aiyu33 ()
等 级:
信 誉 值: 100
所属论坛: C++ Builder Windows SDK/API
问题点数: 100
回复次数: 12
发表时间: 2003-12-16 20:43:13
</P><P>最今我接到了开发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的代码。
下面的代码我能打开hidn类型的usb,但是就是不能打开pocket pc的usb。
//classGuid = {25dbce51-6c8f-4a72-8a6d-b54c2b4fc835}
DEFINE_GUID(GUID_CLASS_PALM,
0x25dbce51, 0x6c8f, 0x4a72, 0x8a, 0x6d, 0xb5, 0x4c, 0x2b,
0x4f, 0xc8, 0x35);
GUID HidGuid = GUID_CLASS_PALM;
HANDLE Get_DeviceHandle( GUID* pGuid)
{
HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if(info==INVALID_HANDLE_VALUE)
{
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);
SetupDiDestroyDeviceInfoList(info);
return NULL;
}</P><P> // Get size of symbolic link name
DWORD ReqLen;
SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char);
if( ifDetail==NULL)
{
SetupDiDestroyDeviceInfoList(info);
return NULL;
}</P><P> // Get symbolic link name
ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL))
{
SetupDiDestroyDeviceInfoList(info);
delete ifDetail;
return NULL;
}</P><P> printf("Symbolic link is %s\n",ifDetail->DevicePath);
</P><P>/*\\?\\usb#vid_03f0&pid_1016#5&1bc41f6c&0&1#{25DBCE51-6C8F-4A72-8A6D-B54C2B4FC835}这是ifDetail->DevicePath的内容*/
// Open file
//前面都很正常但就是下面始终得出一个无效的句柄,我也就无法开展下一步的工作.
HANDLE pDevice = CreateFile(
ifDetail->DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if( pDevice==INVALID_HANDLE_VALUE) pDevice = NULL;
SetupDiDestroyDeviceInfoList(info);
return pDevice;
}
再次感谢关注这个问题的人们。</P><P>
回复人: constantine(飘遥的安吉儿) ( ) 信誉:101 2003-12-16 21:23:57 得分:0
study</P><P>
Top
回复人: wenyongjie(一个想成为大鸟的小菜鸟) ( ) 信誉:95 2003-12-16 22:28:46 得分:0
只有学习的份</P><P>
Top
回复人: HUANG_JH(保卫钓鱼岛) ( ) 信誉:115 2003-12-17 9:50:41 得分:10
不知道有没有用!</P><P>///////////////////////////////////////////////////////////////
// HW9911 evaluation board software Rev. 1.0
// 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 HW9911
// by three examples:
// 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
//
// this software are designed by Liu Ding
// if you meet any problems, pls contact by email:
// <a href="mailthugehard@263.net" target="_blank" >hugehard@263.net</A>
// or contact HEAD Co. by Tel 86-10-87312497
// or by fax: 86-10-87312495
///////////////////////////////////////////////////////////////</P><P>#include "hwdll.h"
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <memory.h>
#include <DEVIOCTL.H>
#include <stdlib.h>
#include <conio.h>
#include "hw9911.h"
#include "test9911.h"</P><P>
int main()
{
int hOpen=FALSE;
int hCommandLength=32;
int hDataLength=64;
int i,VertAddr=0,HorAddr=0;
int addr,TotalLen;
USC StAddrH=0,StAddrL=0;
USC DataLenH,DataLenL;
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");
getch();</P><P>/********* call hDeviceOpen in hwdll.dll to open the board***/
//hOpenDevice 说明:
// BOOL hOpenDevice(HANDLE *DeviceHandle)
// 作用:打开设备
// 参数说明:
// DeviceHandle:设备句柄
// 返回值:
// 设备打开成功返回 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");</P><P>/****** 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");
scanf("%x",&TotalLen);
}
DataLenH=(USC)(TotalLen/0x100); //data length high bytes
DataLenL=(USC)(TotalLen%0x100); //data length low bytes</P><P> printf("************************************************\n");
printf("now program will write datas to ram on board\n");
printf("total bytes of datas is %x\n",TotalLen);
printf("press any key to continue\n\n");
getch();
/*****************************************************************
now will build a write command packet
with the first byte is 'w'.
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,
which is endpoint 2 of HW9911.
when the device receive this command packet,
it will write TotalLen bytes data to Ram on the board
******************************************************************/</P><P>
hCommandBuffer=(USC *)malloc(hCommandLength);
hDataBuffer=(USC *)malloc(hDataLength);
hCommandBuffer = 'w'; //read command
hCommandBuffer = StAddrH;
hCommandBuffer = StAddrL;
hCommandBuffer = DataLenH;
hCommandBuffer = DataLenL; </P><P>/* call hUSBIO() in hwdll.dll to send command packet to device*/
// hUSBIO 说明:
// BOOL hOpenDevice(HANDLE *DeviceHandle,
// unsigned char *IOBuffer,
// int BufferLength,
// int PipeNumber,
// int Action)
// 作用:设备读写
// 参数说明:
// DeviceHandle:设备句柄
// IOBuffer: 指向要传送的数据指针
// BufferLength: 数据包长度
// 对于发送缓存1、2和接收缓存1、2,BufferLength必须小于或等于32
// 对于发送缓存3和接收缓存3,BufferLength必须小于或等于64
// PipeNumber: 通道号
// 发送缓存1:PipeNumber=0;
// 接收缓存1:PipeNumber=1;
// 发送缓存3:PipeNumber=2;
// 接收缓存3:PipeNumber=3;
// Action: 读写标志。TRUE代表从设备读数据到主机
// FALSE代表从主机发送数据到设备
// 操作接收缓存,Action必须为FALSE
// 操作发送缓存,Action必须为TRUE
// 返回值:
// 操作成功返回TRUE,失败返回FALSE</P><P> if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
hCommandLength,
hWritePipe1,
FALSE) == TRUE)
{
printf("command 'w' writed to board\n");
printf("now press any key to write datas to ram\n");
getch();
}
else
printf("data can't write to device\n");</P><P>/******** write ram data to board **********/</P><P> printf(" ");
for(VertAddr=0;VertAddr<=0xf;VertAddr++)
printf("%02x ",VertAddr);
printf("\n");
addr=0;
while (addr<TotalLen)
{
if (addr+hDataLength > TotalLen)
hDataLength = TotalLen-addr;
for(i=0;i<hDataLength;i++)
{
hDataBuffer=ch1++;
if (ch1 > 0x80)
ch1 = 0x61;
}
/* call hUSBIO to write datas to write pipe3, which
is endoint 6 of HW9911*/</P><P> if ( hUSBIO( &hDeviceHandle,
hDataBuffer,
hDataLength,
hWritePipe3,
FALSE) == TRUE) //FALSE means Write operate
{
for(i=0;i<hDataLength;i++)
{
/* print format control */
if(i % 16 == 0)
{
printf("\n%04x ",HorAddr);
HorAddr=HorAddr+16;
}
printf("%02x ",(USC)hDataBuffer);
}
addr=addr+hDataLength;
}
else
{
printf("can't write to board\n");
exit(0);
}
}
printf("\n\nTotal%x bytes write to ram OK\n\n",TotalLen);</P><P>
Top
回复人: HUANG_JH(保卫钓鱼岛) ( ) 信誉:115 2003-12-17 9:50:51 得分:0
</P><P>/*****************************************************************
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,
which is endpoint 2 of HW9911.
when the device receive this command packet,
it will read TotalLen bytes data from Ram on the board
******************************************************************/</P><P> printf("************************************************\n");
printf("now program will read datas from ram on board\n");
printf("total bytes of datas is %x\n",TotalLen);
printf("press any key to continue\n\n");
getch();
hDataLength=64;
hCommandBuffer = 'r'; //read command
hCommandBuffer = StAddrH;
hCommandBuffer = StAddrL;
hCommandBuffer = DataLenH;
hCommandBuffer = DataLenL;
/* call hUSBIO to send packet */
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
hCommandLength,
hWritePipe1,
FALSE) == TRUE)
{
printf("command 'r' writed to board\n");
printf("now press any key to read datas from ram\n\n");
getch();
}
else
printf("data can't write to device\n");</P><P>/******** read ram data form board **********/
printf(" ");
for(VertAddr=0;VertAddr<=0xf;VertAddr++)
printf("%02x ",VertAddr);
printf("\n");
addr=0;
HorAddr=0;
while (addr<TotalLen)
{
if (addr+hDataLength > TotalLen)
hDataLength = TotalLen-addr;
/* call hUSBIO to read datas from board */
if ( hUSBIO( &hDeviceHandle,
hDataBuffer,
hDataLength,
hReadPipe3,
TRUE) == TRUE) //TRUE means Read Operate
{
for(i=0;i<hDataLength;i++)
{
/* print format control */
if(i % 16 == 0)
{
printf("\n%04x ",HorAddr);
HorAddr=HorAddr+16;
}
printf("%02x ",(USC)hDataBuffer);
}
addr=addr+hDataLength;
}
else
{
printf("can't read from board\n");
exit(0);
}
}
printf("\n\n");
printf("%x bytes read from ram OK\n\n",TotalLen);</P><P>/*****************************************************/
/* 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 */
/* send through RS232 serial poart */
/*****************************************************/
printf("\npress any key to process RS232 Test\n");
getch();
USC TH1,TL1;
char hStr;
TH1=(USC)(BD9600/0x100);
TL1=(USC)(BD9600%0x100);
hCommandBuffer = 's'; //read command
hCommandBuffer = TH1;
hCommandBuffer = TL1; //start address is 0x0000</P><P> strcpy(hStr, "Hi, dear HW9911 consumers! ");
printf("Hi, dear HW9911 consumers! ");
memcpy(&(hCommandBuffer),hStr,27);</P><P> if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
30,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}</P><P> strcpy(hStr, "I'm HW9911 Evaluation Board, ");
printf("I'm HW9911 Evaluation Board, ");
memcpy(&(hCommandBuffer),hStr,29);
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
32,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}</P><P> strcpy(hStr, "thanks for purchasing me, ");
printf("thanks for purchasing me, ");
memcpy(&(hCommandBuffer),hStr,26);
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
29,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}
strcpy(hStr, "If you meet some problems, ");
printf(hStr, "If you meet some problems, ");
memcpy(&(hCommandBuffer),hStr,27);
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
30,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}</P><P> strcpy(hStr, "pls contact my designer ");
printf("pls contact my designer ");
memcpy(&(hCommandBuffer),hStr,24);
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
27,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}</P><P> strcpy(hStr, "by email: <a href="mailthugehard@263.net" target="_blank" >hugehard@263.net</A>.");
printf("by email: <a href="mailthugehard@263.net.\n" target="_blank" >hugehard@263.net.\n</A>");
memcpy(&(hCommandBuffer),hStr,27);
if ( hUSBIO( &hDeviceHandle,
hCommandBuffer,
30,
hWritePipe1,
FALSE) == FALSE)
{
printf("can't write datas to RS232\n");
exit(0);
}
/********* call hDeviceOpen in hwdll.dll to open the board***/
// hCloseDevice 说明:
// BOOL hCloseDevice(HANDLE *DeviceHandle)
// 作用:关闭设备
// 参数说明:
// DeviceHandle:设备句柄
// 返回值:
// 设备关闭成功返回 TRUE,失败则返回FALSE
if( (hOpen = hCloseDevice( &hDeviceHandle ))==FALSE)
{
printf("can't open device\n");
printf("press any key to exit\n");
getch();
return 0;
}
else
printf("device closed\n");</P><P> printf("press any key to exit the program\n");
free(hDataBuffer);
free(hCommandBuffer);
getch();
return 0;
}</P><P>
Top
回复人: aiyu33() ( ) 信誉:100 2003-12-17 11:41:24 得分:0
upupupupupupup</P><P>
Top
回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 12:53:39 得分:0
你开发的这种软件类似于Palm Desktop Software,负责Pocket与PC之间通讯,我建议你最好先写一个驱动,将USB口虚拟成一个串口,然后直接对串口操作会很方便的。我现在做的程序可能和你相似是一个CDMA模块,通过USB口与PC机连接,然后由驱动程序将它虚拟成一个串口,我的工作就是和这个虚拟的串口通讯。</P><P>
Top
回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 12:56:27 得分:0
Pocket与PC连接肯定有驱动的,如果驱动程序没有将Pocket虚拟成一个串口,你也可以直接通过设备GUID和设备序列号进行访问,详情你参见我专栏上的一篇文章。当然了,通过虚拟串口来访问设备肯定要方便,简单些。</P><P>
Top
回复人: aiyu33() ( ) 信誉:100 2003-12-17 13:31:08 得分:0
我得这款pocketpc默认只支持使用usb与pc相连的,而且activesync3.7就是使用usb传输数据的。如果我自己写驱动的话,不仅不熟悉而且很可能activesync3.7这个软件就使用不了。我只需要利用它的驱动。你的专栏上的那篇文章我也看了,我就是模仿你的写的代码,但就是到createfile这步就不行了,我的同事是用palm开发类似的程序,也是到这步就行不通了,是不是有其他的原因?
我还想问问如果驱动程序将pocket虚拟成串口,如何查看它的符号名呢?</P><P>
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中看到。</P><P>
Top
回复人: kingcaiyao(AKing) ( ) 信誉:110 2003-12-17 16:55:33 得分:0
我以前在一张贴子中详细回答了如何利用设备序列号和设备GUID来访问该设备,你可以搜索一下CSDN。你所说的CreateFile不能打通设备,你要查一下,你的符号名是否正确,包括设备序列号和设备GUID是否正确,设备GUID你可以从驱动程序的安装向导文件.inf中找到,设备序列号则需要你到注册表中去找。</P><P>
Top
回复人: gyj_china(透明) ( ) 信誉:98 2003-12-17 18:15:30 得分:90
没有星星不敢发言:(</P><P>
Top
回复人: aiyu33() ( ) 信誉:100 2003-12-19 18:27:28 得分:0
不好意思,是因为ActiveSync3.7一直在系统服务程序中运行,占用了驱动程序,所以不能打开设备。我删除了ActiveSync3.7后就可以了。</P> <P>大哥太好了</P>
<P>正是我想要的</P>
<P>謝謝你</P> 看不懂 啊 啊啊 看不懂啊 啊 啊啊 看不懂啊 啦啦啦 谢谢 我是刚注册的新手 请各位大哥多关照
页:
[1]
2