ssts-hospital-web-master项目实战记录四十一:项目迁移-核心模块实现(useDeviceDriver-密码键盘)

记录时间:2024-03-16

一、设备驱动模块实现

service/device-driver/ezware/function-ws/pin-common-device.ts

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

class PinCommon {
  client: EZWebSocket
  ObjName: string = 'PinPad'
  LogicalName: string = 'aPinPad'
  Device: string = 'PinCommon'
  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[]) {
    return this.client.send({
      LogicalName: this.LogicalName,
      Device: this.Device,
      Method: method,
      type: EZMessageType.method,
      Params: paras
    })
  }

  // 方法
  OpenConnection() {
    return this.invokeMethod('OpenConnection', [])
  }
  CloseConnection() {
    return this.invokeMethod('CloseConnection', [])
  }
  SetAttribute(key: string, value: any) {
    this[key] = value
    if (key === 'LogicalName') {
      this.client.initPool[this.LogicalName] = this
    }
    return this.invokeMethod('SetAttribute', [key, value])
  }
  GetAttribute(key: string) {
    return this[key]
  }
  OpenConnectionAsync() {
    return this.invokeMethod('OpenConnectionAsync', [])
  }
  CloseConnectionAsync() {
    return this.invokeMethod('CloseConnectionAsync', [])
  }
  GetStatus() {
    return this.invokeMethod('GetStatus', [])
  }
  GetCapabilities() {
    return this.invokeMethod('GetCapabilities', [])
  }
  Reset() {
    return this.invokeMethod('Reset', [])
  }
  ResetAsync() {
    return this.invokeMethod('ResetAsync', [])
  }
  Initialize() {
    return this.invokeMethod('Initialize', [])
  }
  InitializeAsync() {
    return this.invokeMethod('InitializeAsync', [])
  }
  Encrypt(encrpt: string) {
    return this.invokeMethod('Encrypt', [encrpt])
  }
  Decrypt(encrpt: string) {
    return this.invokeMethod('Decrypt', [encrpt])
  }
  GenerateRandom() {
    return this.invokeMethod('GenerateRandom', [])
  }
  ImportKey(keyInfo: string) {
    return this.invokeMethod('ImportKey', [keyInfo])
  }
  ImportKeyAsync(keyInfo: string) {
    return this.invokeMethod('ImportKeyAsync', [keyInfo])
  }
  ImportKeyEx(keyInfo: string) {
    return this.invokeMethod('ImportKeyEx', [keyInfo])
  }
  ImportKeyExAsync(keyInfo: string) {
    return this.invokeMethod('ImportKeyExAsync', [keyInfo])
  }
  GetData(dataInfo: string) {
    return this.invokeMethod('GetData', [dataInfo])
  }
  GetDataAsync(dataInfo: string) {
    return this.invokeMethod('GetDataAsync', [dataInfo])
  }
  CancelGetData() {
    return this.invokeMethod('CancelGetData', [])
  }
  GetPin(dataInfo: string) {
    return this.invokeMethod('GetPin', [dataInfo])
  }
  GetPinAsync(dataInfo: string) {
    return this.invokeMethod('GetPinAsync', [dataInfo])
  }
  CancelGetPin() {
    return this.invokeMethod('CancelGetPin', [])
  }
  GetPinBlock(pinblockInfo: string) {
    return this.invokeMethod('GetPinBlock', [pinblockInfo])
  }
  GetPinBlockEx(pinblockInfo: string) {
    return this.invokeMethod('GetPinBlockEx', [pinblockInfo])
  }
  GenerateMac(macInfo: string) {
    return this.invokeMethod('GenerateMac', [macInfo])
  }
  GetKeyDetail() {
    return this.invokeMethod('GetKeyDetail', [])
  }
  GetFuncKey() {
    return this.invokeMethod('GetFuncKey', [])
  }
  GetLastXfsErr() {
    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)
  }
  TimeOut() {
    this.EventFunction(this.ObjName + '_' + 'TimeOut', null)
  }
  GetDataComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'GetDataComplete', para)
  }
  GetPinComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'GetPinComplete', para)
  }
  KeyPressed(para: string) {
    this.EventFunction(this.ObjName + '_' + 'KeyPressed', para)
  }
  InitializeComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'InitializeComplete', para)
  }
  ImportKeyComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ImportKeyComplete', para)
  }
  ImportKeyExComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ImportKeyExComplete', para)
  }
  ResetComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
  }
}

export default PinCommon
 

二、调用示例

 

二、运行测试

 

 

 

 

posted @ 2024-03-16 18:59  lizhigang  阅读(1)  评论(0编辑  收藏  举报