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

记录时间:2024-03-16

一、设备驱动模块实现

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

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

class SiuCommon {
  client: EZWebSocket
  ObjName: string = 'SIU'
  LogicalName: string = 'aSIU'
  Device: string = 'SiuCommon'
  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', [])
  }
  GetLastXfsErr() {
    return this.invokeMethod('GetLastXfsErr', [])
  }
  EnableEvent() {
    return this.invokeMethod('EnableEvent', [])
  }
  DisableEvent() {
    return this.invokeMethod('DisableEvent', [])
  }
  SetGuidLight(item: string, command: string) {
    return this.invokeMethod('SetGuidLight', [item, command])
  }
  SetAuxiliary(item: string, command: string) {
    return this.invokeMethod('SetAuxiliary', [item, command])
  }
  SetIndicator(item: string, command: string) {
    return this.invokeMethod('SetIndicator', [item, command])
  }
  SetDoor(item: string, command: string) {
    return this.invokeMethod('SetDoor', [item, command])
  }

  // 事件
  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)
  }
  PortStatusChanged(dev: string, state: string) {
    this.EventFunction(
      this.ObjName + '_' + 'OpenConnectionComplete',
      dev + ',' + state
    )
  }
  TimeOut() {
    this.EventFunction(this.ObjName + '_' + 'TimeOut', null)
  }
  ResetComplete(para: any) {
    this.EventFunction(this.ObjName + '_' + 'ResetComplete', para)
  }
}

export default SiuCommon
 

二、调用示例

 

二、运行测试

 

 

 

 

 

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