一、裝置驅動模組實現
service/device-driver/ezware/function-ws/crd-common-device.ts
import { EventFunctionType, EventResultType } from '@/types'
import { EZMessageType, EZWebSocket } from './ez-web-socket'
class CrdCommon {
client: EZWebSocket
ObjName: string = 'CardDispenser'
LogicalName: string = 'aCardDispenser'
Device: string = 'CrdCommon'
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', [])
}
GetCardUnit(): Promise<any> {
return this.invokeMethod('GetCardUnit', [])
}
SetCardUnit(info: string): Promise<any> {
return this.invokeMethod('SetCardUnit', [info])
}
Reset(action: string): Promise<any> {
return this.invokeMethod('Reset', [action])
}
ResetAsync(action: string): Promise<any> {
return this.invokeMethod('ResetAsync', [action])
}
Eject(): Promise<any> {
return this.invokeMethod('Eject', [])
}
EjectAsync(): Promise<any> {
return this.invokeMethod('EjectAsync', [])
}
Retain(num: number): Promise<any> {
return this.invokeMethod('Retain', [num])
}
RetainAsync(num: number): Promise<any> {
return this.invokeMethod('RetainAsync', [num])
}
Dispense(num: number, present: boolean): Promise<any> {
return this.invokeMethod('Dispense', [num, present])
}
DispenseAsync(num: number, present: boolean): Promise<any> {
return this.invokeMethod('DispenseAsync', [num, present])
}
MoveCard(pos: string): Promise<any> {
return this.invokeMethod('MoveCard', [pos])
}
MoveCardAsync(pos: string): Promise<any> {
return this.invokeMethod('MoveCardAsync', [pos])
}
GetLastXfsErr(): Promise<any> {
return this.invokeMethod('GetLastXfsErr', [])
}
// 事件
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)
}
CardInserted() {
this.EventFunction(this.ObjName + '_' + 'CardInserted', null)
}
CardTaken() {
this.EventFunction(this.ObjName + '_' + 'CardTaken', null)
}
ReadRawDataComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'ReadRawDataComplete', para)
}
ResetComplete(para: string) {
this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
}
}
export default CrdCommon
service/device-driver/ezware/function-ws/idc-crd-motor-device.ts
import { EventFunctionType, EventResultType } from '@/types'
import { EZMessageType, EZWebSocket } from './ez-web-socket'
class CrdMotorIdc {
client: EZWebSocket
ObjName: string = 'CardDispenserReader'
LogicalName: string = 'aCardDispenserReader'
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 CrdMotorIdc
二、呼叫示例
詳見前文
ssts-hospital-web-master專案實戰記錄三十一:專案遷移-核心模組實現(useDeviceDriver&DeviceDriver)
ssts-hospital-web-master專案實戰記錄三十一:專案遷移-核心模組實現(useDeviceDriver&DeviceDriver)
二、執行測試