ssts-hospital-web-master项目实战记录三十八:项目迁移-核心模块实现(useDeviceDriver-文档打印机)

记录时间:2024-03-16

一、设备驱动模块实现

service/device-driver/ezware/function-ws/ptr-document-device.ts

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

class PtrDocument {
  client: EZWebSocket
  ObjName: string = 'DocumentPrinter'
  LogicalName: string = 'aDocument'
  Device: string = 'PtrDocument'
  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', [])
  }
  GetFormList() {
    return this.invokeMethod('GetFormList', [])
  }
  GetMediaList() {
    return this.invokeMethod('GetMediaList', [])
  }
  GetForm(formName: string) {
    return this.invokeMethod('GetForm', [formName])
  }
  GetMedia(mediaName: string) {
    return this.invokeMethod('GetMedia', [mediaName])
  }
  GetField(formName: string, fieldName: string) {
    return this.invokeMethod('GetField', [formName, fieldName])
  }
  Reset(resetParam: string) {
    return this.invokeMethod('Reset', [resetParam])
  }
  ResetAsync(resetParam: string) {
    return this.invokeMethod('ResetAsync', [resetParam])
  }
  Eject(cut: string) {
    return this.invokeMethod('Eject', [cut])
  }
  PrintForm(formInfo: string) {
    return this.invokeMethod('PrintForm', [formInfo])
  }
  PrintFormAsync(formInfo: string) {
    return this.invokeMethod('PrintFormAsync', [formInfo])
  }
  PrintRawData(rawData: string) {
    return this.invokeMethod('PrintRawData', [rawData])
  }
  PrintRawDataAsync(rawData: string) {
    return this.invokeMethod('PrintRawDataAsync', [rawData])
  }
  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)
  }
  MediaInserted() {
    this.EventFunction(this.ObjName + '_' + 'MediaInserted', null)
  }
  MediaTakend() {
    this.EventFunction(this.ObjName + '_' + 'MediaTakend', null)
  }
  MediaPresented(para: string) {
    this.EventFunction(this.ObjName + '_' + 'MediaPresented', para)
  }
  PrintFormComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'PrintFormComplete', para)
  }
  ResetComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
  }
  TimeOut() {
    this.EventFunction(this.ObjName + '_' + 'TimeOut', null)
  }
  PrintRawDataComplete(para: string) {
    this.EventFunction(this.ObjName + '_' + 'PrintRawDataComplete', para)
  }
}

export default PtrDocument
  

二、调用示例

 

二、运行测试

 

 

 

 

 

 

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