PRAKTIČNI VODNIK · PRECIZ
Kako povezati tehtnico RAVAS 3200 s SAP prek Wi-Fi
CloudScaleLink Neutron pretvori RAVAS ASCII prek RS-232 v izbrane ukaze MT-SICS prek TCP/IP za povezavo obstoječe tehtnice s SAP.
1. Rešitev za IT in integratorje
V opisani namestitvi tehtnica na viličarju z indikatorjem RAVAS 3200 ostane v uporabi. JavaScript aplikacija v Neutron AppEngine prevede komunikacijo za vmesnik SAP, ki pričakuje MT-SICS prek TCP. Neutron se poveže v omrežje Wi-Fi z WPA3-Enterprise in deluje kot strežnik TCP.
Potrebujete indikator RAVAS 3200 z dvosmernim RS-232, CloudScaleLink Neutron z AppEngine API 1 in odjemalca TCP v ciljnem sistemu. Vodič je namenjen IT ekipam, razvijalcem ter integratorjem tehtalnih sistemov. Pripravil: PRECIZ.
Obstoječa tehtnica ostane nespremenjena. Neutron poskrbi za omrežno povezavo in pretvorbo protokola.
2. Povežite RS-232 in omrežje
- Na RAVAS 3200 izberite PC → bidir: 9600 baud, 8 podatkovnih bitov, brez paritete, 1 stop bit in brez strojnega nadzora pretoka. Sporočila RAVAS se zaključijo s CR.
- CloudScaleLink Neutron povežite v omrežje Wi-Fi z WPA3-Enterprise in nastavitvami avtentikacije, ki jih zagotovi IT. SAP mora doseči naslov IP naprave. Navodila Neutron.
- Nastavite Serial redirect → Disabled in vgrajeni TCP mode → Disabled; izključite tudi nasprotujoče si mostove TCP. V razdelku Scale pustite RS-232/UART in TCP neizbrana kot vgrajena tehtalna vmesnika. Vrata bo prevzel AppEngine.
Nastavitve RS-232: izključen Serial redirect; aplikacija sama nastavi 9600 8N1 in obravnava zaključek CR.
Vgrajeni način TCP je izključen. Aplikacija zažene svoj strežnik na vratih 5000.
RS-232/UART in TCP nista izbrana za vgrajeni tehtalni protokol.
3. Naložite in zaženite aplikacijo
Prenesite aplikacijo JavaScript (.js)
V konfiguraciji aplikacije vnesite serialNumber s tablice indikatorja, nastavite fiksno enoto unit in po potrebi spremenite tcpPort (privzeto 5000). Prazen serialNumber pomeni odgovor I4 I. Primer nastavitev:
tcpPort: 5000,
unit: "kg",
serialNumber: "1234"V zavihku AppEngine izberite Upload, naložite JS in izberite Run. Po uspešnem preizkusu lahko vključite Run automatically at device startup. Aplikacija teče na Neutronu, ne v brskalniku. Postopek namestitve AppEngine.
AppEngine: nalaganje, zagon in dnevnik prevzema RS-232 ter povezave odjemalca TCP.
4. Prvo branje iz SAP ali odjemalca TCP
Odjemalca TCP povežite na naslov IP Neutrona in vrata 5000 oziroma nastavljena vrata. Pošljite I4\r\n, nato SXI\r\n. Vsak ukaz zaključite s CRLF in počakajte na celoten odgovor. Pri I0 je zadnja vrstica tista, ki se začne z I0 A.
SX S G 12.5 kg N 10.0 kg T 2.5 kgSX S pomeni stabilno, SX D dinamično meritev. G je bruto, N neto in T tara. Bruto in neto izhajata iz istega okvira GW, tara je njuna razlika. Enota in decimalna mesta sledijo konfiguraciji indikatorja.
5. Ukazi in odgovori aplikacije
Ukaz | Funkcija | Primer odgovora |
|---|---|---|
I0 | Seznam podprtih ukazov in njihovih nivojev; I0 B pomeni vmesno vrstico, I0 A zadnjo. | I0 B …; I0 A 2 "SXI" |
I4 | Vrne serijsko številko, vpisano v konfiguracijo aplikacije. | I4 A "1234" |
S | Prebere stabilno neto maso; na stabilnost čaka do približno pet sekund, nato vrne S I. | S S 10.0 kg / S I |
SI | Prebere trenutno neto maso; S S je stabilno, S D dinamično. | S S 10.0 kg / S D 10.0 kg |
Z | Ničlira tehtnico in potrdi, da aktivna tara ni več vključena. | Z A |
T | Tarira trenutno obremenitev in prebere nastalo taro. | T S 2.5 kg |
TA | Prebere taro; TA 2.5 kg nastavi prednastavljeno taro v podprtem decimalnem formatu. | TA A 2.5 kg |
TAC | Izbriše aktivno taro; TAC I pomeni, da aplikacija izbrisa ni potrdila. | TAC A / TAC I |
SXI | Prebere bruto, neto in taro brez čakanja na stabilnost; SX S je stabilno, SX D dinamično. | SX S G 12.5 kg N 10.0 kg T 2.5 kg |
ES: neznan ukaz ali neustrezni argumenti. EL: presežena čakalna vrsta. TA L: nepodprta vrednost, natančnost ali enota tare. I v odgovoru pomeni, da zahteve ni bilo mogoče uspešno zaključiti; + in - označujeta preobremenitev oziroma neveljavno območje iz odčitka. Podprt je navedeni nabor ukazov te aplikacije.
6. Kako je aplikacija razdeljena
start()
Prevzame RS-232, nastavi 9600 8N1 in zažene izključni strežnik TCP.
exchange()
Pošlje ukaz RAVAS s CR, sestavi odgovor in ob časovni prekoračitvi zadrži nadaljnje zahteve, da pozni odgovori ne pripadajo napačnemu ukazu.
readWeight()
Za S in SI združi decimalna mesta iz GN s preverjenim statusom in vrednostmi GW.
readExtendedWeight()
Za SXI uporabi en okvir GW za bruto in neto, izračuna taro ter preveri decimalno natančnost pred in po odčitku.
clearTare() in presetTare()
Brisanje tare preveri s statusnim bitom GW; pri prednastavljeni tari preveri enoto in dovoljena decimalna mesta.
respond() in drainQueue()
Ukaze MT-SICS preslika v operacije RAVAS in jih izvaja zaporedno, da se serijske zahteve ne prekrivajo.
7. Celotna koda aplikacije in prenos JS
Prenesite celotno aplikacijo JavaScript (.js)
Spodaj je celotna priložena aplikacija. Prenos vsebuje isto kodo. Pred zagonom uredite konfiguracijo; pollMs: 100 je premor pri čakanju na stabilnost ali potrditev operacije, ne samodejni tok podatkov v SAP.
/*
* Neutron AppEngine API 1 | SAP (TCP client) <-> RAVAS 3200 (RS-232)
* RAVAS serial setup: PC -> bidir, 9600 8N1, no handshake, CR terminator.
* Neutron: disable the system RS-232 function, I_TCP weighing protocol and
* TCP bridges so AppEngine can claim both interfaces. Use an unused TCP port.
* Keep the RAVAS display unit fixed. Set unit and serialNumber below.
* SAP: send ASCII commands ending in CRLF and wait for the full reply.
*/
(function () {
"use strict";
const config = {
tcpPort: 5000,
unit: "kg",
serialNumber: "", // Enter the serial number from the indicator plate.
readTimeoutMs: 650,
operationTimeoutMs: 5500,
stableTimeoutMs: 5000,
pollMs: 100,
queueLimit: 16
};
const commands = ["I0", "I4", "S", "SI", "Z", "T", "TA", "TAC", "SXI"];
const serialPort = serial.rs232;
let pending = null;
let serialBlockedUntil = 0;
let serialLine = "";
let discardSerialLine = false;
let session = null;
let busy = false;
function receiveSerial(event) {
for (const byte of event.data) {
if (byte === 13) {
const line = serialLine.trim();
const request = pending;
if (!discardSerialLine && request &&
(request.accept(line) || /^(?:ERR|[NG]?=+|[NG]-[ -]+)$/.test(line))) {
pending = null;
request.resolve(line);
}
serialLine = "";
discardSerialLine = false;
} else if (byte !== 10 && !discardSerialLine) {
if (byte < 32 || byte > 126 || serialLine.length >= 64) {
discardSerialLine = true;
} else {
serialLine += String.fromCharCode(byte);
}
}
}
}
async function exchange(command, accept, timeoutMs = config.readTimeoutMs) {
if (Date.now() < serialBlockedUntil) {
throw new Error("RS-232 is waiting for late replies to clear");
}
serialLine = "";
discardSerialLine = false;
let timer;
const response = new Promise((resolve, reject) => {
pending = { accept, resolve };
timer = setTimeout(() => reject(new Error("No RAVAS reply to " + command)), timeoutMs);
});
try {
// Install the response handler first. The reply may arrive before write resolves.
const results = await Promise.all([
response,
serialPort.write(command + "\r", { timeoutMs: 500 })
]);
if (results[1] !== command.length + 1) throw new Error("Incomplete serial write");
return results[0];
} catch (error) {
serialBlockedUntil = Date.now() + config.operationTimeoutMs;
throw error;
} finally {
clearTimeout(timer);
pending = null;
}
}
function parseDecimal(line, prefix) {
const match = /^([NTP])([+-])(\d{1,5})(?:\.(\d{0,4}))?$/.exec(line);
if (!match || match[1] !== prefix) return null;
const integer = match[3].replace(/^0+(?=\d)/, "");
const fraction = match[4] || "";
const counts = Number(match[2] + match[3] + fraction);
return {
text: (counts < 0 ? "-" : "") + integer + (fraction ? "." + fraction : ""),
counts,
decimals: fraction.length
};
}
function parseStatus(line) {
const match = /^W([+-]\d{5})([+-]\d{5})([0-9A-F]{2})([0-9A-F]{2})$/i.exec(line);
if (!match) return null;
let sum = 0;
for (let i = 0; i < line.length - 2; i++) sum += line.charCodeAt(i);
if (((~sum) & 255) !== parseInt(match[4], 16)) return null;
return { net: Number(match[1]), gross: Number(match[2]), flags: parseInt(match[3], 16) };
}
function weightReply(id, status, value) {
return id + " " + status + " " + value.text.padStart(10, " ") + " " + config.unit;
}
async function status() {
const line = await exchange("GW", value => value.startsWith("W"));
const frame = parseStatus(line);
if (!frame) return { error: /^N?-[ -]+$/.test(line) ? "-" : "I" };
if (frame.flags & 0x04) return { error: "+" };
if (frame.flags & 0x80) return { error: "I" };
return frame;
}
async function decimal(command, prefix) {
return parseDecimal(await exchange(command, line => line.startsWith(prefix)), prefix);
}
async function readWeight(stableOnly, source) {
const deadline = Date.now() + config.stableTimeoutMs;
do {
if (session !== source) return "S I";
const before = await status();
if (before.error) return "S " + before.error;
if (!stableOnly || (before.flags & 0x10)) {
const net = await decimal("GN", "N");
if (!net) return "S I";
const after = await status();
if (after.error) return "S " + after.error;
// GN supplies the decimal point. GW supplies checked status and raw counts.
const stable = (before.flags & after.flags & 0x10) &&
before.net === net.counts && after.net === net.counts &&
before.gross === after.gross &&
((before.flags ^ after.flags) & 0x40) === 0;
if (stable) return weightReply("S", "S", net);
if (!stableOnly) return weightReply("S", "D", net);
}
const remaining = deadline - Date.now();
if (remaining <= 0) break;
await new Promise(resolve => setTimeout(resolve, Math.min(config.pollMs, remaining)));
} while (Date.now() < deadline);
return "S I";
}
async function readExtendedWeight() {
const before = await decimal("GN", "N");
const frame = await status();
if (frame.error) return "SXI " + frame.error;
const after = await decimal("GN", "N");
// GW carries gross and net in one frame. GN supplies the decimal position.
// Reject the snapshot if the displayed precision changed across the GW query.
if (!before || !after || before.decimals !== after.decimals) return "SXI I";
const stable = (frame.flags & 0x10) &&
before.counts === frame.net && after.counts === frame.net;
const scale = 10 ** after.decimals;
const fields = [["G", frame.gross], ["N", frame.net], ["T", frame.gross - frame.net]];
return "SX " + (stable ? "S" : "D") + " " + fields.map(([tag, counts]) =>
tag + " " + (counts / scale).toFixed(after.decimals).padStart(10, " ") +
" " + config.unit
).join(" ");
}
async function acknowledge(command) {
return await exchange(command, line => line === "OK", config.operationTimeoutMs) === "OK";
}
async function readTares() {
const regular = await decimal("GT", "T");
const preset = await decimal("GP", "P");
if (!regular || !preset) throw new Error("RAVAS tare is unavailable");
return { regular, preset };
}
async function currentTare() {
const { regular, preset } = await readTares();
if (regular.counts === 0) return preset;
if (preset.counts === 0 || regular.text === preset.text) return regular;
const frame = await status();
if (!frame.error) {
const active = frame.gross - frame.net;
const matchesRegular = regular.counts === active;
const matchesPreset = preset.counts === active;
if (matchesRegular !== matchesPreset) return matchesRegular ? regular : preset;
}
throw new Error("RAVAS reported two ambiguous tare values");
}
async function tareIsCleared(timeoutMs) {
const deadline = Date.now() + timeoutMs;
do {
const frame = await status();
if (!frame.error && !(frame.flags & 0x40)) return true;
const remaining = deadline - Date.now();
if (remaining <= 0) return false;
await new Promise(resolve => setTimeout(resolve, Math.min(config.pollMs, remaining)));
} while (true);
}
async function clearTare() {
if (await tareIsCleared(0)) return true;
const preset = await decimal("GP", "P");
if (preset && preset.counts !== 0) {
await acknowledge("RP");
if (await tareIsCleared(1000)) return true;
}
// A stored preset value can remain visible through GP even with no active tare.
// Use the GW tare-active bit to verify the result, allowing for the update delay.
await acknowledge("RT");
return await tareIsCleared(1000);
}
async function presetTare(argument) {
const match = /^\+?(\d{1,10})(?:\.(\d{1,8}))? +([A-Za-z]+)$/.exec(argument);
if (!match || match[3] !== config.unit) return "TA L";
const format = await decimal("GP", "P");
if (!format) return "TA I";
const integer = match[1].replace(/^0+(?=\d)/, "");
const fraction = (match[2] || "").replace(/0+$/, "");
// RAVAS requires a decimal point even when the display has no decimals.
const integerWidth = 5 - format.decimals;
if (integer.length > integerWidth || fraction.length > format.decimals) return "TA L";
const value = integer.padStart(integerWidth, "0") + "." +
fraction.padEnd(format.decimals, "0");
if (!await acknowledge("SP" + value)) return "TA I";
return weightReply("TA", "A", await currentTare());
}
async function respond(line, source) {
const match = /^([A-Z][A-Z0-9]*)(?: +(.+))?$/.exec(line.trim());
if (!match || !commands.includes(match[1])) return "ES";
const [, command, argument] = match;
if (argument && command !== "TA") return "ES";
try {
switch (command) {
case "I0":
return commands.map((name, index) =>
"I0 " + (index === commands.length - 1 ? "A" : "B") +
" " + (name === "SXI" ? "2" : index < 5 ? "0" : "1") +
' "' + name + '"').join("\r\n");
case "I4":
return config.serialNumber ? 'I4 A "' + config.serialNumber + '"' : "I4 I";
case "SI":
case "S":
return await readWeight(command === "S", source);
case "SXI":
return await readExtendedWeight();
case "Z":
if (!await acknowledge("SZ")) return "Z I";
return await clearTare() ? "Z A" : "Z I";
case "T":
if (!await acknowledge("SR")) return "T I";
return weightReply("T", "S", await currentTare());
case "TAC":
return await clearTare() ? "TAC A" : "TAC I";
case "TA":
return argument
? await presetTare(argument)
: weightReply("TA", "A", await currentTare());
}
} catch (error) {
console.warn(command + ": " + error.message);
return (command === "SI" ? "S" : command) + " I";
}
}
async function drainQueue() {
if (busy) return;
busy = true;
try {
while (session && (session.queue.length || session.rejected)) {
const source = session;
const line = source.queue.shift();
if (line === undefined) source.rejected--;
const reply = line === undefined ? "EL" : await respond(line, source);
if (source !== session) continue;
try {
await tcp.write(reply + "\r\n", { connectionId: source.id });
} catch (error) {
console.warn("TCP reply failed: " + error.message);
source.queue.length = 0;
source.rejected = 0;
}
}
} finally {
busy = false;
}
}
async function start() {
if (!/^[\x20-\x21\x23-\x7e]{0,40}$/.test(config.serialNumber) ||
!/^[A-Za-z]+$/.test(config.unit)) {
throw new Error("Check the configured MT-SICS serial number and weight unit");
}
serialPort.on("data", receiveSerial);
await serialPort.claim();
await serialPort.configure({ baudRate: 9600, dataBits: 8, stopBits: 1, parity: "none" });
tcp.on("connection", event => {
if (event.role !== "server") return;
if (event.connected) session = { id: event.connectionId, queue: [], rejected: 0 };
else if (session && session.id === event.connectionId) session = null;
});
tcp.on("line", event => {
if (!session || session.id !== event.connectionId || !event.line.trim()) return;
if (session.queue.length >= config.queueLimit || session.rejected) {
session.rejected = Math.min(session.rejected + 1, config.queueLimit);
} else {
session.queue.push(event.line);
}
drainQueue().catch(error => console.error(error.message));
});
await tcp.configure({
mode: "server",
server: { port: config.tcpPort, exclusive: true },
delimiter: "\r\n",
maxLineBytes: 128
});
await tcp.claim();
console.info("RAVAS MT-SICS bridge configured on TCP port " + config.tcpPort);
}
start().catch(error => {
console.error("RAVAS bridge startup failed: " + (error.code || "") + " " + error.message);
app.stop();
});
})();
8. Preizkusite povezavo
- Z I4 potrdite identiteto, nato s SXI primerjajte maso in decimalna mesta z indikatorjem.
- Izvedite T, preberite taro s TA in jo izbrišite s TAC.
- Po TAC A mora naslednji SXI prikazati ničelno taro ter enak bruto in neto.
- Preizkusite stabilno in premikajoče se breme ter ponovno povezavo odjemalca.
Posnetki prikazujejo testno okolje. Vidni identifikator naprave, SSID, serijska številka 1234 in zasebni naslov IP so primeri za prikaz postopka.
TCP odjemalec: odgovori I4, SXI, T, TA in TAC ter stabilno in dinamično stanje.
Potrebujete povezavo tehtnice z vašim IT sistemom?
Sporočite nam model tehtnice, obstoječi vmesnik in ciljni sistem. PRECIZ pripravlja povezovanje tehtnic in prilagoditve komunikacije za IT ekipe ter integratorje.
Pogosta vprašanja
Ali lahko tehtnico povežemo tudi prek WebSocketa?
Ali je mogoča povezava prek MQTT?
Ali rešitev deluje z vsakim sistemom SAP?
Vodič obravnava vmesnik SAP za tehtanje, ki deluje kot odjemalec TCP in pričakuje navedene ukaze MT-SICS. Ciljni vmesnik mora podpirati ta nabor ukazov, CRLF in dogovorjeni format odgovora. Drugačen vmesnik SAP zahteva ustrezno prilagoditev povezave.
Lahko povežemo tudi ERP, MES, WMS ali SCADA?
Sistem, ki zna uporabljati prikazani MT-SICS prek TCP, lahko nastopa kot odjemalec. Za drugačne formate ali protokole se aplikacija AppEngine prilagodi ciljnemu sistemu. PRECIZ lahko pri načrtovanju povezave izhaja iz modela tehtnice, obstoječega vmesnika in zahtev IT sistema.
Ali moramo zamenjati obstoječo tehtnico RAVAS?
Pri prikazani rešitvi obstoječa tehtnica in indikator RAVAS 3200 ostaneta v uporabi. CloudScaleLink Neutron doda omrežno povezavo in pretvorbo RAVAS ASCII iz dvosmernega RS-232 v navedene odgovore MT-SICS prek TCP.
Ali ponavljajoče branje sproži tiskanje ali seštevanje?
Branje mase v tej aplikaciji uporablja zahtevi GN in GW. Ti odčitki ne sprožijo tiskanja ali prištevanja v delni seštevek. Operacije ničliranja in tariranja se izvedejo samo ob ustreznem ukazu odjemalca.
Potrebujete pomoč?
Potrebujete pomoč pri programski opremi, povezovanju ali uporabi rešitve? Opišite težavo, da vam lahko pomagamo pri naslednjem koraku.