'use strict'; const _ = require("lodash"); const Controller = require('egg').Controller; class MessageController extends Controller { //打开端口 async openCom() { let { ctx } = this; let params = ctx.request.body let SerialPortItem = _.find(ctx.app.comKey, { key: params.key }) let res = await ctx.service.message.openCom(SerialPortItem); ctx.body = res ctx.status = 200 } //关闭端口 async closeCom() { let { ctx } = this; let params = ctx.request.body let SerialPortItem = _.find(ctx.app.comKey, { key: params.key }) let res = await ctx.service.message.closeCom(SerialPortItem); ctx.body = res ctx.status = 200 } //发送指令 async index() { let { ctx } = this; let params = ctx.request.body let SerialPortItem = _.find(ctx.app.comKey, { ripCom: params.ripCom }) let res = await ctx.service.message.index({ ...SerialPortItem, ...params }); ctx.body = res ctx.status = 200 } } module.exports = MessageController;