diff --git a/controllers/modbus.controller.js b/controllers/modbus.controller.js index 8deb5c9..708ccde 100644 --- a/controllers/modbus.controller.js +++ b/controllers/modbus.controller.js @@ -208,6 +208,7 @@ export const modbusController = { if (!req.query.slave_id) return res.status(400).json({ error: { message: "'slave_id' parameter is required." } }); const device = await db.get(`SELECT * FROM "modbus_slaves" WHERE id = ?`, [req.query.slave_id]); + const displayValues = await db.all(`SELECT * FROM "display_values" WHERE slave_id = ?`, [req.query.slave_id]) if (!device) return res.status(404).json({ error: { message: "Device not found." } }); @@ -216,8 +217,12 @@ export const modbusController = { res.setHeader("Connection", "keep-alive"); let interval = setInterval(async () => { - let value = 0; - let len = 1; // 16 bits default + let graphValue = 0; + let len = 1; // 16 bits default + + for (const value of displayValues) { + value.data = Buffer.from((await modbusClient.readHoldingRegisters(value.reg_addr, 1)).buffer).readUInt16BE(); + } if (device.g_display_reg_format === 32) len = 2; // ...64, 128, 256... @@ -226,17 +231,20 @@ export const modbusController = { switch (device.g_display_reg_format) { case 32: - value = Buffer.from(result.buffer).readUInt32BE(); + graphValue = Buffer.from(result.buffer).readUInt32BE(); break; case 16: - value = Buffer.from(result.buffer).readUint16BE(); + graphValue = Buffer.from(result.buffer).readUint16BE(); break; default: break; } res.write("event: message\n"); - res.write(`data: ${JSON.stringify({ graph: { value, format: device.g_display_reg_format } })}\n\n`); + res.write(`data: ${JSON.stringify({ + graph: { value: graphValue, format: device.g_display_reg_format }, + displayValues + })}\n\n`); }, 1000); req.on("close", () => clearInterval(interval)); } catch (error) { diff --git a/data.db b/data.db index 84155ce..78ab51f 100644 Binary files a/data.db and b/data.db differ diff --git a/migrations/001-init.sql b/migrations/001-init.sql index d1df254..822f187 100644 --- a/migrations/001-init.sql +++ b/migrations/001-init.sql @@ -58,22 +58,22 @@ CREATE TABLE IF NOT EXISTS "display_values" ( INSERT INTO "modbus_slaves" ( "id", "name", "g_display_reg_addr", "g_display_reg_format", "g_y_label", "is_logging" ) VALUES - (1, "Device #1", 1, 16, "Label 1", 1), - (2, "Device #2", 2, 32, "Label 2", 1), - (3, "Device #3", 8, 16, "Label 3", 0), + (1, "Device #1", 0, 16, "Label 1", 1), + (2, "Device #2", 1, 32, "Label 2", 1), + (3, "Device #3", 3, 16, "Label 3", 0), (4, "Device #4", NULL, NULL, "Label 4", 0); INSERT INTO "display_values" ( "id", "name", "slave_id", "reg_addr", "reg_format" ) VALUES - (1, "CV1", 1, 0, 16), - (2, "CV2", 1, 1, 16), - (3, "SP", 1, 2, 16), - (4, "CV1", 2, 3, 16), - (5, "CV2", 2, 4, 16), - (6, "SP", 2, 5, 16), - (7, "CV1", 3, 6, 16), - (8, "SP", 3, 7, 16); + (1, "CV1", 1, 10, 16), + (2, "CV2", 1, 11, 16), + (3, "SP", 1, 12, 16), + (4, "CV1", 2, 13, 16), + (5, "CV2", 2, 14, 16), + (6, "SP", 2, 15, 16), + (7, "CV1", 3, 16, 16), + (8, "SP", 3, 17, 16); -------------------------------------------------------------------------------- -- Down -------------------------------------------------------------------------------- diff --git a/public/css/dist.css b/public/css/dist.css index c43c182..ac86915 100644 --- a/public/css/dist.css +++ b/public/css/dist.css @@ -698,6 +698,10 @@ video { margin-top: 1.5rem; } +.mt-auto { + margin-top: auto; +} + .block { display: block; } @@ -726,6 +730,10 @@ video { height: 5rem; } +.h-\[720px\] { + height: 720px; +} + .h-full { height: 100%; } @@ -734,6 +742,10 @@ video { height: 100vh; } +.h-\[300px\] { + height: 300px; +} + .max-h-\[400px\] { max-height: 400px; } diff --git a/public/index.html b/public/index.html index 20842c2..45531e9 100644 --- a/public/index.html +++ b/public/index.html @@ -135,7 +135,6 @@
Loading...
+