ssts-hospital-web-master项目实战记录三十九:项目迁移-核心模块实现(useDeviceDriver-扫码器)

记录时间:2024-03-16

一、设备驱动模块实现

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

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

class BcrCommon {
  client: EZWebSocket
  ObjName: string = 'Barcode'
  LogicalName: string = 'aBarcode'
  Device: string = 'BcrCommon'
  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): any {
    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', [])
  }
  ReadBarcode(type: string, timeout: number) {
    return this.invokeMethod('ReadBarcode', [type, timeout])
  }
  ReadBarcodeAsync(type: string, timeout: number) {
    return this.invokeMethod('ReadBarcodeAsync', [type, timeout])
  }
  CancelReadBarcode() {
    return this.invokeMethod('CancelReadBarcode', [])
  }
  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)
  }
  ReadBarcodeComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ReadBarcodeComplete', para)
  }
  ResetComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
  }
}

export default BcrCommon
 

二、调用示例

 

二、运行测试

 

 

 

 

 

 

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