ssts-hospital-web-master项目实战记录三十七:项目迁移-核心模块实现(useDeviceDriver-凭条打印机&标签打印机)
记录时间:2024-03-16
一、设备驱动模块实现
service/device-driver/ezware/function-ws/ptr-receipt-device
import { EventFunctionType, EventResultType } from '@/types'
import { EZMessageType, EZWebSocket } from './ez-web-socket'
class PtrReceipt {
client: EZWebSocket
ObjName: string = 'ReceiptPrinter'
LogicalName: string = 'aReceipt'
Device: string = 'PtrReceipt'
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 PtrReceipt
service/device-driver/ezware/function-ws/ptr-label-device
import { EventFunctionType, EventResultType } from '@/types'
import { EZMessageType, EZWebSocket } from './ez-web-socket'
class PtrLabel {
client: EZWebSocket
ObjName: string = 'LabelPrinter'
LogicalName: string = 'aReceipt1' // 测试无效的逻辑服务名:aLabel
Device: string = 'PtrReceipt' // 需要使用中间件支持的组件名,不可随意修改
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 PtrLabel
二、调用示例
二、运行测试
凭条打印机
标签打印机