You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
8 months ago
|
'use strict';
|
||
|
const Service = require('egg').Service;
|
||
|
const _ = require("lodash");
|
||
|
class MessageService extends Service {
|
||
|
//打开端口
|
||
|
async openCom(params) {
|
||
|
let { ctx, app } = this;
|
||
|
let SerialPortItem = _.find(app.comKey, { key: params.key })
|
||
|
let res = await ctx.service.dealSerialport.openSerialport(SerialPortItem.ripComInstence, params.ripCom);
|
||
|
return res
|
||
|
}
|
||
|
//关闭端口
|
||
|
async closeCom(params) {
|
||
|
let { ctx, app } = this;
|
||
|
let SerialPortItem = _.find(app.comKey, { key: params.key })
|
||
|
let res = await ctx.service.dealSerialport.closeSerialport(SerialPortItem.ripComInstence, params.ripCom);
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
//发送指令
|
||
|
async send(SerialPortItem, params) {
|
||
|
let { ctx } = this;
|
||
|
let sendResult = await ctx.service.dealSerialport.writeSerialport(SerialPortItem, params);
|
||
|
if (sendResult) {
|
||
|
return sendResult
|
||
|
} else {
|
||
|
return "端口已被占用,请关闭已占用的端口后刷新页面。"
|
||
|
}
|
||
|
}
|
||
|
//发送指令
|
||
|
async index(params) {
|
||
|
let sendResult = await this.send(params.ripComInstence, params);
|
||
|
return sendResult
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = MessageService;
|