欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
UKEY虚拟通道方式流程分析
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

 

UKEY虚拟通道方式流程分析

 

最后更新 05-08-19

 

一 UKEY-虚拟通道整体架构

 

二 TermRWVC 虚拟通道client

由TSSysInf的client端

(E:\Program Files\Microsoft SDK\samples\winbase\WtsApi\TSSysInf\Client\SysInf_C.c)程序改写。

1 服务器端程序TermRWVC运行在PC上,提供5个接口函数供UKEY厂商调用。

 

 

1). 打开设备

TERMRWVC_API HANDLE CreateFileCenterm(char          * lpFileName);

2). 关闭设备

TERMRWVC_API BOOL CloseHandleCenterm(HANDLE                   hFile);

3). 读取文件

TERMRWVC_API BOOL ReadFileCenterm(         HANDLE               hFile,

                                                                                      LPVOID                lpBuffer,

                                                                                      DWORD                nNumberOfBytesToRead,

                                                                                      LPDWORD                          lpNumberOfBytesRead,

                                                                                      LPOVERLAPPED                 lpOverlapped);

4). 写入文件

TERMRWVC_API BOOL WriteFileCenterm(        HANDLE               hFile,

                                                                                      LPCVOID                            lpBuffer,

                                                                                      DWORD                nNumberOfBytesToWrite,

                                                                                      LPDWORD                          lpNumberOfBytesWritten,

                                                                                      LPOVERLAPPED   lpOverlapped);

5) .设置波特率(与串口扩展兼容)

TERMRWVC_API BOOL ComSetCenterm(                        HANDLE               hFile,

                                                                                   unsigned long         ulBaudRate);

#define TAXUSBNAME                       TEXT("TAX1:")

//提供Usb接口,设备名为TAX1:

 

2  TermRWVC.cpp中主要完成以下操作:

1)  DllMain,DLL的入口

2)   打开虚拟通道操作OpenTaxVc,调用WTSVirtualChannelOpen函数打开虚拟通道,该函数在2003SDK的Wtsapi32.h中定义。

3)  关闭虚拟通道操作CloseTaxVc

4)  读写虚拟通道操作DoTaxVc

5)  实现打开设备CreateFileCenterm,以TSUSBHSOPEN状态为参数调用DoTaxVc函数。

6)  实现关闭设备CloseHandleCenterm,以TSUSBHSCLOSE状态为参数调用DoTaxVc函数。

7)  实现读取文件ReadFileCenterm,以TSUSBHSREAD状态为参数调用DoTaxVc函数。

8)  实现写入文件WriteFileCenterm,以TSUSBHSWRITE状态为参数调用DoTaxVc函数。

9)  设置波特率ComSetCenterm没有实现。

 

3  DoTaxVc函数分析

涉及到的类结构TS_USB_DATA *p_usbdata,在StdAfx.h (E:\project\UKEY\天安信源代码\TermRWVC050201\TermRWVC\StdAfx.h)中有定义。

根据dwOPtype的类型判断是以下哪种状态,执行相应的操作

1)TSUSBHSOPEN ,

2)TSUSBHSCLOSE           

3) TSUSBHSREAD            ,调用WTSVirtualChannelRead          

4) TSUSBHSWRITE            

5) TSUSBHSSMASK             0x0ce37    //SERVER data

6) TSUSBHSCMASK            0x0ce25    //CLIENT data

7) TSUSBHSTIMEOUT  40000;//INFINITE;

 

三  usbVTC 虚拟通道Server

由TSSysInf的server端

(E:\Program Files\Microsoft SDK\samples\winbase\WtsApi\TSSysInf\Server)程序改写。

1 SysInfo.h由E:\Program Files\Microsoft SDK\samples\winbase\WtsApi\TSSysInf\Inc\SysInfo.h针对USBKEY做了部分修改:

1)  增加了虚拟通道USB操作类型的声明

2)  增加了类结构TS_USB_DATA 的声明

3)  增加了BOOL ReadUsbData(void)函数声明

4)  增加了BOOL WriteUsbData(DWORD dwlen,char * pszdata) 函数声明

2

VirtualChannelInitEventProc函数(SysInf_C.cpp)

 

1)Event事件定义

Value

Meaning

CHANNEL_EVENT_CONNECTED

A connection has been established with a terminal server that supports virtual channels. The pData parameter is a pointer to a null-terminated string with the name of the server.

CHANNEL_EVENT_DISCONNECTED

The connection to the terminal server has been disconnected. The pData parameter is NULL.

CHANNEL_EVENT_INITIALIZED

The Terminal Services client initialization has been completed. The pData parameter is NULL.

CHANNEL_EVENT_TERMINATED

The client has been terminated. The pData parameter is NULL.

CHANNEL_EVENT_V1_CONNECTED

A connection has been established with a terminal server that does not support virtual channels. The pData parameter is NULL.

CHANNEL_EVENT_REMOTE_CONTROL_START

A remote control operation has been started. The pData parameter is NULL.

CHANNEL_EVENT_REMOTE_CONTROL_STOP

A remote control operation has been terminated. The pData parameter is a pointer to a null-terminated string containing the name of the server.

 

2) PCHANNEL_ENTRY_POINTS pEntryPoints类结构体定义

typedef struct tagCHANNEL_ENTRY_POINTS {
  DWORD cbSize;
  DWORD protocolVersion;
  PVIRTUALCHANNELINIT pVirtualChannelInit;
  PVIRTUALCHANNELOPEN pVirtualChannelOpen;
  PVIRTUALCHANNELCLOSE pVirtualChannelClose;
  PVIRTUALCHANNELWRITE pVirtualChannelWrite;

} CHANNEL_ENTRY_POINTS, *PCHANNEL_ENTRY_POINTS;

 

3)  CHANNEL_EVENT_CONNECTED事件处理流程:

 

 

3 VirtualChannelOpenEvent  函数

1)event 事件定义

[in] Indicates the event that caused the notification. This parameter can be one of the following values.

Value

Meaning

CHANNEL_EVENT_DATA_RECEIVED

The virtual channel received data from the server end. pData is a pointer to a chunk of the data. dataLength indicates the size of this chunk. totalLength indicates the total size of the data written by the server.

CHANNEL_EVENT_WRITE_CANCELLED

A write operation started by a VirtualChannelWrite call has been canceled. pData is the value specified in the pUserData parameter of VirtualChannelWrite.

A write operation is canceled when the client session is disconnected. This notification enables you to free any memory associated with the write operation.

CHANNEL_EVENT_WRITE_COMPLETE

A write operation started by a VirtualChannelWrite call has been completed. pData is the value specified in the pUserData parameter of VirtualChannelWrite.

 

 

4         WorkerThread线程函数

监听由客户端发来的指令

 

 


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步