'use strict'; const Service = require('egg').Service; const _ = require("lodash"); class DualFlowMotorService extends Service { //初始化双流电机 async init(params) { let { ctx, app } = this; app.cantest1 = params.start return { hasError: false, msg: `${params.start ? '开启' : '关闭'}成功` } } //保存双流电机数据 async send(params) { let { ctx, app } = this; let returnData = { hasError: false, msg: "发送成功" } await app.udp.udp.send(params.key, 8096, "localhost", (err, bytes) => { if (err) { returnData.msg = err } else { returnData.msg = `已成功发送${bytes}字节` // app.udp.udp.close(); // app.udp.udp.on("close", () => { // console.log("close"); // }); } }); return returnData } //保存双流电机数据 async save(params) { let { ctx, app } = this; // let res = await ctx.model.DualFlowMotor.create(params) // console.log(66688, res, params) return { a444: 52 } } } module.exports = DualFlowMotorService;