diff --git a/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs b/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs index c8dae898..35f47e76 100644 --- a/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs +++ b/projects/IoTNode/DeviceServices/SerialPort/Controllers/SerialPortController.cs @@ -34,5 +34,19 @@ namespace IoTNode.Controllers this._deviceService.UpdateButtons(number, buttons); }); } + + public ApiResponse Test([SwaggerParameter("设备编号")]string number, + [SwaggerParameter("串口")]string port, + [SwaggerParameter("波特率")]int baud, + [SwaggerParameter("数据位")]int dataBits, + [SwaggerParameter("校验位")]int partity, + [SwaggerParameter("停止位")]int stopBits, + [SwaggerParameter("消息")]string message) + { + return this.AsyncAction(() => + { + this._deviceService.Test(port, baud, dataBits, partity, stopBits, message); + }); + } } } \ No newline at end of file diff --git a/projects/IoTNode/DeviceServices/SerialPort/SerialPortService.cs b/projects/IoTNode/DeviceServices/SerialPort/SerialPortService.cs index ba5de990..2baee82c 100644 --- a/projects/IoTNode/DeviceServices/SerialPort/SerialPortService.cs +++ b/projects/IoTNode/DeviceServices/SerialPort/SerialPortService.cs @@ -37,6 +37,10 @@ namespace IoTNode.DeviceServices.SerialPortManager ExecInternal(button.PortName, button.BaudRate, button.DataBits, button.Parity, button.StopBits, button.Message); } + public void Test(string port, int baud, int dataBits, int partity, int stopBits, string message) + { + ExecInternal(port, baud, dataBits, partity, stopBits, message); + } internal void UpdateButtons(string number, string buttons) { using (var scope = _applicationServices.CreateScope()) diff --git a/projects/WebApp/wwwroot/pages/iot/device/ir.html b/projects/WebApp/wwwroot/pages/iot/device/ir.html index be964e8e..38606b89 100644 --- a/projects/WebApp/wwwroot/pages/iot/device/ir.html +++ b/projects/WebApp/wwwroot/pages/iot/device/ir.html @@ -353,7 +353,7 @@
-
+
@@ -473,7 +473,7 @@ }, save: function (e) { var buttons = []; - $(e.target).parents('.card').find('.row').each(function () { + $(e.target).parents('.card').find('.item').each(function () { buttons.push({ name: $(this).find("input[name='name']").val(), value: $(this).find("input[name='value']").val(), diff --git a/projects/WebApp/wwwroot/pages/iot/device/serial-port.html b/projects/WebApp/wwwroot/pages/iot/device/serial-port.html index 2ae05a1a..b2d2bb17 100644 --- a/projects/WebApp/wwwroot/pages/iot/device/serial-port.html +++ b/projects/WebApp/wwwroot/pages/iot/device/serial-port.html @@ -8,7 +8,7 @@
- +
@@ -21,7 +21,7 @@
-
+
@@ -71,7 +71,7 @@
@@ -86,54 +86,8 @@ weui.tab('.weui-tab'); }, methods: { - changePattern: function (v) { - this.change(v, 0, 480, 120); - }, - changeDirection(v) { - this.change(v, 0, 60, 60); - }, - changeWind(v) { - this.change(v, 0, 45, 15); - }, - changePower: function (v) { - var oldValue = parseInt(v); - if (oldValue === 1) { - this.send(3, 1); - getData(this.device, '按键').value = 3; - } - else if (oldValue === 2) { - this.send(1, 1); - getData(this.device, '按键').value = 1; - } - }, - changeTemperature: function (v, step) { - var oldValue = parseInt(v); - var min = 1; - var max = 15; - var newValue = oldValue + step; - if (step > 0 && newValue > max) { - newValue = max; - } - else if (step < 0 && newValue < min) { - newValue = min; - } - var newCode = this.code - oldValue + newValue; - this.send(newCode, 1); - getData(this.device, '按键').value = newCode; - }, - change: function (v, min, max, step) { - alert(v); - var oldValue = parseInt(v); - var newValue = oldValue + step; - if (newValue > max) { - newValue = min; - } - var newCode = this.code - oldValue + newValue; - this.send(newCode, 1); - getData(this.device, '按键').value = newCode; - }, - send: function (value, type) { - execApi(this.device.number, '/Ir/Send', 'type=' + type + '&code=' + value); + send: function (name) { + execApi(this.device.number, '/SerialPort/Send', 'type=' + type + '&code=' + value); }, getCustomButtons: function () { return Enumerable.from(JSON.parse(getDeviceDataValue(this.device, "指令"))) @@ -145,7 +99,7 @@ .where(function (o) { return o.name === "指令"; }) .firstOrDefault(); var buttons = this.getCustomButtons(); - var newBtn = { name: "测试", value: "603", order: 100 }; + var newBtn = { "name": "测试", "portName": "/dev/ttyS0", "baudRate": 9600, "parity": 0, "dataBits": 8, "stopBits": 1, "message": "0123456789ABCDEF", "order": 100 }; buttons.push(newBtn); data.value = JSON.stringify(buttons); }, @@ -162,83 +116,32 @@ } data.value = JSON.stringify(buttons); }, - study: function (code) { - execApi(this.device.number, '/Ir/Study', 'type=' + 5 + '&code=' + code); - }, - test: function (code) { - execApi(this.device.number, '/Ir/Send', 'type=' + 5 + '&code=' + code); + test: function (name) { + var button = Enumerable.from(this.getCustomButtons()).where(function (o) { return o.name === name; }).firstOrDefault(); + var query = 'port=' + button.portName; + query += '&baud=' + button.baudRate; + query += '&parity=' + button.parity; + query += '&dataBits=' + button.dataBits; + query += '&stopBits=' + button.stopBits; + query += '&message=' + button.message; + execApi(this.device.number, '/SerialPort/Test',query); }, save: function (e) { var buttons = []; - $(e.target).parents('.card').find('.row').each(function () { + $(e.target).parents('.card').find('.item').each(function () { buttons.push({ name: $(this).find("input[name='name']").val(), - value: $(this).find("input[name='value']").val(), + portName: $(this).find("input[name='portName']").val(), + baudRate: $(this).find("input[name='baudRate']").val(), + parity: $(this).find("input[name='parity']").val(), + dataBits: $(this).find("input[name='dataBits']").val(), + stopBits: $(this).find("input[name='stopBits']").val(), + message: $(this).find("input[name='message']").val(), order: $(this).find("input[name='order']").val() }); }); var value = JSON.stringify(buttons); - execApi(this.device.number, '/Ir/Buttons', 'buttons=' + value); - } - }, - computed: { - code: function () { - return getDeviceDataValue(this.device, '按键'); - }, - pattern: function () { - var code = this.code; - var pattern = { name: '制冷', value: 0 }; - if (code > 480 + 2) { - pattern = { name: '通风', value: 480 }; - } - else if (code > 360 + 2) { - pattern = { name: '抽湿', value: 360 }; - } - else if (code > 240 + 2) { - pattern = { name: '制热', value: 240 }; - } - else if (code > 120 + 2) { - pattern = { name: '自动', value: 120 }; - } - return pattern; - }, - direction: function () { - var code = this.code - this.pattern.value; - var direction = { name: '自动', value: 0 };; - if (code > 60 + 2) { - direction = { name: '手动', value: 60 }; - } - return direction; - }, - wind: function () { - var code = this.code - this.pattern.value - this.direction.value; - var wind = { name: '自动', value: 0 }; - if (code > 45 + 2) { - wind = { name: '低', value: 45 }; - } - else if (code > 30 + 2) { - wind = { name: '中', value: 30 }; - } - else if (code > 15 + 2) { - wind = { name: '高', value: 15 }; - } - return wind; - }, - power: function () { - var code = this.code - this.pattern.value - this.direction.value - this.wind.value; - var power = { name: '关', value: 1 }; - if (code > 1) { - power = { name: '开', value: 2 }; - } - return power; - }, - temperature: function () { - var code = this.code - this.pattern.value - this.direction.value - this.wind.value - this.power.value; - var temperature = { name: '16℃', value: 1 }; - if (code > 1) { - temperature = { name: parseInt(code + 15) + '℃', value: code }; - } - return temperature; + execApi(this.device.number, '/SerialPort/Buttons', 'buttons=' + value); } } });