UNPKG

node-fxplc

Version:

Node.js library for low-level Mitsubishi FX (MELSEC) PLC framed protocol communication

14 lines (13 loc) 512 B
"use strict"; // protocol-utils.js // Funzioni di supporto protocollo (checksum) // protocol-utils.js // Protocol helper functions (checksum, etc.). Object.defineProperty(exports, "__esModule", { value: true }); exports.calcChecksum = calcChecksum; function calcChecksum(payload) { // payload: Buffer (payload + ETX in original Python logic) const sum = payload.reduce((a, b) => a + b, 0); const hex = (sum & 0xFF).toString(16).toUpperCase().padStart(2, '0'); return Buffer.from(hex, 'ascii'); }