ssts-hospital-web-master專案實戰記錄三十三:專案遷移-核心模組實現(useDeviceDriver-銀行卡讀卡器)

lizhigang發表於2024-03-16

一、裝置驅動模組實現

service/device-driver/ezware/function-ws/idc-motor-device.ts

import { EventFunctionType, EventResultType } from '@/types'
import { EZMessageType, EZWebSocket } from './ez-web-socket'

class IdcMotor {
client: EZWebSocket
ObjName: string = 'CardReader'
LogicalName: string = 'aCardReader'
Device: string = 'IdcMotor'
EventFunction: EventFunctionType
EventResult: EventResultType

constructor(
ezWebSocket: EZWebSocket,
globalEventFunction: EventFunctionType,
globalEventResult: EventResultType
) {
this.client = ezWebSocket
this.EventFunction = globalEventFunction
this.EventResult = globalEventResult
}

async setParams(name?: string, logicalName?: string) {
if (name) {
this.ObjName = name
}
if (logicalName) {
this.LogicalName = logicalName
}
await this.SetAttribute('LogicalName', this.LogicalName)
}
invokeMethod(method: string, paras: any[]): Promise<any> {
return this.client.send({
LogicalName: this.LogicalName,
Device: this.Device,
Method: method,
type: EZMessageType.method,
Params: paras
})
}

// 方法
OpenConnection(): Promise<any> {
return this.invokeMethod('OpenConnection', [])
}
CloseConnection(): Promise<any> {
return this.invokeMethod('CloseConnection', [])
}
SetAttribute(key: string, value: any): Promise<any> {
this[key] = value
if (key === 'LogicalName') {
this.client.initPool[this.LogicalName] = this
}
return this.invokeMethod('SetAttribute', [key, value])
}
GetAttribute(key: string): any {
return this[key]
}
OpenConnectionAsync(): Promise<any> {
return this.invokeMethod('OpenConnectionAsync', [])
}
CloseConnectionAsync(): Promise<any> {
return this.invokeMethod('CloseConnectionAsync', [])
}
GetStatus(): Promise<any> {
return this.invokeMethod('GetStatus', [])
}
GetCapabilities(): Promise<any> {
return this.invokeMethod('GetCapabilities', [])
}
Reset(action: string): Promise<any> {
return this.invokeMethod('Reset', [action])
}
ResetAsync(action: string): Promise<any> {
return this.invokeMethod('ResetAsync', [action])
}
ReadRawData(track: string, timeout: number): Promise<any> {
return this.invokeMethod('ReadRawData', [track, timeout])
}
ReadRawDataAsync(track: string, timeout: number): Promise<any> {
return this.invokeMethod('ReadRawDataAsync', [track, timeout])
}
CancelReadRawData(): Promise<any> {
return this.invokeMethod('CancelReadRawData', [])
}
GetLastXfsErr(): Promise<any> {
return this.invokeMethod('GetLastXfsErr', [])
}
EjectCard(): Promise<any> {
return this.invokeMethod('EjectCard', [])
}
EjectCardAsync(): Promise<any> {
return this.invokeMethod('EjectCardAsync', [])
}
RetainCard(): Promise<any> {
return this.invokeMethod('RetainCard', [])
}
RetainCardAsync(): Promise<any> {
return this.invokeMethod('RetainCardAsync', [])
}
ResetCount(): Promise<any> {
return this.invokeMethod('ResetCount', [])
}
WriteRawData(trackinfo: string): Promise<any> {
return this.invokeMethod('WriteRawData', [trackinfo])
}
WriteRawDataAsync(trackinfo: string, timeout: null): Promise<any> {
return this.invokeMethod('WriteRawDataAsync', [trackinfo, timeout])
}
ChipIO(jsonChipIO: string): Promise<any> {
return this.invokeMethod('ChipIO', [jsonChipIO])
}
ChipIOAsync(jsonChipIO: string): Promise<any> {
return this.invokeMethod('ChipIOAsync', [jsonChipIO])
}
ChipPower(powerType: string): Promise<any> {
return this.invokeMethod('ChipPower', [powerType])
}
ChipPowerAsync(powerType: string): Promise<any> {
return this.invokeMethod('ChipPowerAsync', [powerType])
}

// 事件
OpenConnectionComplete() {
this.EventFunction(this.ObjName + '_' + 'OpenConnectionComplete', null)
}
CloseConnectionComplete() {
this.EventFunction(this.ObjName + '_' + 'CloseConnectionComplete', null)
}
HWError(para: string) {
this.EventFunction(this.ObjName + '_' + 'HWError', para)
}
FatalError() {
this.EventFunction(this.ObjName + '_' + 'FatalError', null)
}
ReadRawDataComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'ReadRawDataComplete', para)
}
WriteRawDataComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'WriteRawDataComplete', para)
}
RetainCardComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'RetainCardComplete', para)
}
EjectCardComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'EjectCardComplete', para)
}
ChipPowerComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'ChipPowerComplete', para)
}
CardInserted() {
this.EventFunction(this.ObjName + '_' + 'CardInserted', null)
}
CardTaken() {
this.EventFunction(this.ObjName + '_' + 'CardTaken', null)
}
ResetComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
}
}

export default IdcMotor

二、呼叫示例

詳見前文
ssts-hospital-web-master專案實戰記錄三十一:專案遷移-核心模組實現(useDeviceDriver&DeviceDriver)

二、執行測試

相關文章