BT San Technology

24 July 2026

Recipe Dosing and Weighing with a PLC and a Web App: Who Does What

26 min read · Automation

Illustration: three hoppers dosing into a mixing vessel on load cells, a tablet showing a three-item recipe being weighed
AI-generated illustration

A factory that weighs and doses raw materials by recipe usually faces two problems at once. The first is that recipes are scattered, and an old file gets opened and used at the wrong version. The second is that the doser periodically goes over or under target, because material still in the air when the valve closes gets added on top. The two problems are fixed in different places, but if the split of duties between the web app and the PLC is unclear, both become hard to fix.

This article draws that split clearly, using simulation code that actually runs (TypeScript on Node 24, nothing to install). The PLC side has a scan loop, coarse then fine feeding, cutting the valve before the target, waiting for the weight to settle, and alarms. The web side has approved recipes, orders and batch records. The two sides talk through messages that carry a sequence number. A manager can read the explanations and tables and get the picture, and an engineer can run the code and follow along.

The real problem: wrong recipe version, overdosing and double dosing

Consider three hypothetical situations, not any BT San customer's project.

  • Small animal feed mill: recipes sit in several versions of an Excel file. The night shift opens an old file and sets the wrong weights for a whole batch, and the material has to be thrown away.
  • Paint or chemical blending plant: powder is dosed into a weighing tank, and for the next two hours the weighed amount is consistently a few hundred grams over target, because the material still in transit between the feeder mouth and the tank is not compensated.
  • Dry goods packing line: the web app orders a dose, the factory's internal network hiccups and no reply comes back, so it resends the same command. The doser doses twice.

All three are answered by the same principle. What changes often and must be auditable later (recipes, versions, approvers, batch records) lives on the web app. What must respond in milliseconds and stay safe even if the web goes down (valves, weight, alarms) lives in the PLC. And the two sides talk with messages that can be resent without causing a repeated effect.

What the documents say, and what this example does not claim

TopicWhat the source saysEffect on the design
In-flight materialThe Guide to Dynamic Weighing for Industry (INSTMC/NPL) states that there is a delay between the moment the system sees the target reached and the moment feeding actually stops. This is called in-flight time, and it lets extra material in. Every batch weighing system tries to control this error.Needs a compensation value per raw material, and the valve is cut before the target
Multi-speed feedingThe same guide states that the error can be reduced by lowering the feed rate near the end, keeping a coarse feed stage so the cycle time stays short, and adding a low-rate fine feed stageA COARSE step followed by a FINE step
Learning the compensationThe same guide describes weigh fillers that find the compensation from the measured cut-off point of small weighing runs after the material has settledAdjust the in-flight value batch by batch from the actual weighed result
Legal-for-trade fillersOIML R 61 covers the requirements and tests for automatic gravimetric filling instruments (AGFI) that produce predetermined masses in discrete loadsIf the product must pass legal inspection, check this requirement. Our example does not claim to pass it.
Batch modelAccording to the ISA page, ISA-88 defines an approach to batch control systems, and its functional model names five types of control: recipe management, scheduling, sequential control, regulatory control and safety interlockKeep the recipe and the sequential control in separate layers, following this concept
PLC languagesIEC 61131-3 defines four programmable controller languages: IL, ST, LD and FBD (the IEC page states that the 2013 edition was withdrawn and replaced by the 2025 edition)The TypeScript code in the example is a PLC simulation. A real PLC would be written in ST or LD.
Summary of the document pages read on 2026-11-21. This example was not tested against real equipment or against the full standards.

Every number in the example (target 50 kg, tolerance 0.30 kg, flow rates 10 and 2 kg/second, fall time 0.3 seconds) is hypothetical, chosen to show the behavior. None of them is a value from any real machine.

Overview of the example

The code is in the folder examples/plc-dosing-weighing-system/. It uses only Node 24 built-ins and runs TypeScript directly with node file.ts (Node simply strips the types and does not type-check them, so it does not use enum, and the .ts extension must be written in imports). It also uses node:sqlite, which ships with Node, to store the web side's data. The Node docs say this module is still experimental, so --no-warnings is added when running.

FilePurpose
plant.tsSimulates the site: a load cell with noise, a valve, and material falling through the air
plc.tsThe PLC side: a scan loop, a state machine, cutting before the target, alarms, and a mailbox that receives commands
web.tsThe web side: versioned recipes, approval, orders, resending with the same seq, and batch records (SQLite)
demo.tsRuns six groups of events
plc.test.tsA node:test suite with 5 cases
README.md / output.txtHow to run it, and the output from a real run

The scope of each side can be summarized as follows. The web app says what to dose, how much, and under which order number. The PLC says how much was actually dosed, and its status. The web never opens or closes a valve itself.

Step 1: a simulated site with noise and material in transit

plant.ts builds what makes weigh-dosing hard. The readings have noise, the empty tank has an initial weight (it must be tared), and material leaving the feeder mouth takes time to fall into the tank. After the valve closes, material therefore keeps entering the tank for another six scans (0.3 seconds). The random generator uses a fixed seed, so a rerun gives the same result.

plant.ts · lines 27–46
export function createPlant(seed = 7, preload = 12.4): Plant {
  const rnd = mulberry32(seed);
  const air: number[] = new Array(FALL_STEPS).fill(0); // in-flight material, kg per step
  let mass = 0;
  const gauss = () => Math.sqrt(-2 * Math.log(1 - rnd())) * Math.cos(2 * Math.PI * rnd());
  const p: Plant = {
    valve: 0,
    stuck: false,
    noise: 0.05,
    read: () => preload + mass + p.noise * gauss(),
    step() {
      air.push(p.stuck ? 0 : FLOW[p.valve] * DT);
      mass += air.shift() as number; // what left the gate FALL_STEPS ago lands now
    },
    discharge() {
      mass = 0;
    },
    trueNet: () => mass,
  };
  return p;
plant.ts createPlant: material passes through a delay queue before reaching the weighing tank

Step 2: the scan loop: filtering, settling and no-flow

The PLC works in short cycles that repeat constantly. Each cycle it reads the raw weight, filters it with the average of the last four values, and decides from the filtered value. Two helper functions are used often: a check for "settled" (the high-low range of the last eight values is narrow enough) and a check for "no flow" (the valve has been open for three seconds and the weight has not risen by 0.3 kg).

plc.ts · lines 35–41
  function stable() {
    const w = fil.slice(-CFG.settleWindow);
    return w.length === CFG.settleWindow && Math.max(...w) - Math.min(...w) < CFG.settleBand;
  }
  function noFlow() { // no real rise within noFlowScans -> feeder bridged or gate not opening
    return scans >= CFG.noFlowScans && net() - riseFrom < CFG.minRise;
  }
plc.ts: the stable and noFlow conditions

The average makes the filtered value lag slightly behind the true value. This is not a problem, because the in-flight learning in Step 4 compares the filtered value at the cut-off point with the settled value at the end, so the filter's delay is folded into the compensation value itself. The thing to remember is that if you change the filter, you must let the system learn again.

Step 3: the state machine: tare, coarse feed, fine feed, wait to settle

The sequence has six states: IDLE, TARE, COARSE, FINE, SETTLE and ALARM (plus HELD for the case where the web connection is lost). Every state change happens in one place, the scan function. Reading it from top to bottom shows the whole order of work.

plc.ts · lines 43–66
  function scan() {
    raw.push(plant.read());
    fil.push(raw.slice(-CFG.avg).reduce((a, b) => a + b, 0) / Math.min(raw.length, CFG.avg));
    scans++;
    if (!link && (step === "COARSE" || step === "FINE") && onLinkLost === "hold") {
      plant.valve = 0; go("HELD"); // safe hold: valve shut, wait for operator
      last = { ...(last as Result), status: "ALARM", alarm: "LINK_HOLD" };
    }
    const o = order as Order;
    if (step === "TARE" && stable()) { tare = fil[fil.length - 1]; plant.valve = 1; go("COARSE"); }
    else if (step === "TARE" && scans > CFG.settleTimeout) fail("SCALE_UNSTABLE_TARE");
    else if (step === "COARSE") {
      if (noFlow()) fail("NO_FLOW");
      else if (net() >= o.target - CFG.fineBand) { plant.valve = 2; go("FINE"); }
    } else if (step === "FINE") {
      used = inflight[o.material] ?? 0;
      if (noFlow()) fail("NO_FLOW");
      else if (net() >= o.target - used) { plant.valve = 0; cutW = net(); go("SETTLE"); } // early cut
    } else if (step === "SETTLE") {
      if (stable()) finish();
      else if (scans > CFG.settleTimeout) fail("SCALE_UNSTABLE");
    }
    plant.step(); // simplified: the real plant moves by itself
  }
plc.ts scan: one scan cycle of the PLC
  • TARE: wait until the value settles, then record the empty tank weight. Clear the old values first every time, otherwise the tare would come from samples of the previous batch.
  • COARSE: open the large valve until the net weight reaches the target minus 5 kg, then switch to fine feeding (the 5 kg band must be larger than the material left over from coarse feeding, which is about 3 kg in the example).
  • FINE: open the small valve and cut it immediately when the net weight reaches the target minus the in-flight value of that raw material. This is a deliberate cut before the target.
  • SETTLE: close the valve and wait for the weight to settle. If it does not settle within six seconds, raise an alarm. Do not guess the value.
  • NO_FLOW and SCALE_UNSTABLE cut the valve and stay in ALARM until an operator presses reset.

Step 4: the in-flight value adjusts itself batch by batch

After waiting for the weight to settle, the PLC knows two values: the filtered weight at the cut-off point and the settled weight at the end. The difference is the material that fell after the cut, which is the real in-flight amount for this run. The new compensation moves the old value halfway toward the measured value (alpha 0.5), capped at 3 kg to guard against odd values from an abnormal weighing. The result is then compared with the tolerance.

plc.ts · lines 68–80
  function finish() {
    const o = order as Order;
    const actual = Math.round((fil.slice(-CFG.settleWindow).reduce((a, b) => a + b, 0) / CFG.settleWindow - tare) * 100) / 100;
    const seen = Math.min(CFG.maxInflight, Math.max(0, actual - cutW)); // what fell after the cut
    const next = used + CFG.alpha * (seen - used);
    inflight[o.material] = Math.round(next * 1000) / 1000;
    const bad = Math.abs(actual - o.target) > o.tol;
    last = { seq: o.seq, status: bad ? "ALARM" : "DONE", material: o.material, target: o.target, actual,
      cutWeight: Math.round(cutW * 100) / 100, inflightUsed: used, inflightNew: inflight[o.material],
      ...(bad ? { alarm: "OVER_TOLERANCE" } : {}) };
    plant.discharge();
    step = bad ? "ALARM" : "IDLE";
  }
plc.ts finish: calculates the actual value, learns the in-flight value and checks the tolerance

This idea matches what the INSTMC guide describes: the compensation can be found from the measured cut-off point of earlier weighing runs. But this example adjusts every batch with a simple weighted average. A real machine must define for itself whether to learn from every run or only from runs that pass a criterion, and not to learn when the material flows abnormally (a value learned from a run with a blocked pipe would distort the compensation in every following run).

Step 5: a handshake: a resent command does not dose twice

The web sends a command (seq number, batch, raw material, target, tolerance) into the PLC's mailbox. The PLC can answer ACK (received and working on it), BUSY, DONE with the result, ALARM, STALE (the seq is older than one already received) or REJECT (the command makes no sense, for example a negative target). The key rule is that the same seq is never executed again, whether it arrives twice in a row or after the run has finished. The PLC replies with the status or the result it remembers.

plc.ts · lines 82–94
  // The only door from the web side: a mailbox with a sequence number.
  function receive(o: Order): Result {
    if (!(o.target > 0 && o.target <= CFG.capacity && o.tol > 0 && o.tol < o.target)) return { seq: o.seq, status: "REJECT" };
    const prev = last?.seq ?? 0;
    if (o.seq < prev) return { seq: o.seq, status: "STALE" };
    if (o.seq === prev) return step === "IDLE" || step === "ALARM" || step === "HELD" ? (last as Result) : { seq: o.seq, status: "ACK" };
    if (step !== "IDLE") return { seq: o.seq, status: "BUSY" }; // running, or alarm not yet reset
    order = o; starts[o.seq] = (starts[o.seq] ?? 0) + 1;
    last = { seq: o.seq, status: "ACK" };
    raw.length = 0; fil.length = 0; // tare only from fresh samples
    plant.valve = 0; go("TARE");
    return last;
  }
plc.ts receive: a mailbox that prevents double dosing with seq

Double dosing can happen in two ways. In the first, the command is resent because the reply was lost. In the second, the web crashes and restarts. Both must use the same seq. The web side therefore creates the seq from the row id in the database and writes that row before the first send. After a restart it finds the rows that are still PENDING and sends the same seq.

web.ts · lines 50–69
// The seq is the row id, written BEFORE the first send. After a web restart the same
// PENDING row is sent again with the same seq, so the PLC can recognise it.
export function runBatch(db: DatabaseSync, batchId: string, link: Link, maxTries = 20): string {
  const rows = db.prepare("SELECT * FROM batch_lines WHERE batch_id=? AND status='PENDING' ORDER BY line_no").all(batchId) as Row[];
  for (const r of rows) {
    const order: Order = { seq: r.seq, batchId: r.batch_id, material: r.material, target: r.target, tol: r.tol };
    let res: Result | null = null;
    for (let i = 0; i < maxTries; i++) {
      res = link.send(order);
      if (res && (res.status === "DONE" || res.status === "ALARM" || res.status === "REJECT")) break;
      link.wait();
    }
    if (!res || !["DONE", "ALARM", "REJECT"].includes(res.status)) return "LINK_DOWN"; // row stays PENDING
    db.prepare("UPDATE batch_lines SET actual=?, status=?, inflight_used=?, alarm=? WHERE seq=?")
      .run(res.actual ?? null, res.status, res.inflightUsed ?? null, res.alarm ?? null, r.seq);
    if (res.status !== "DONE") { db.prepare("UPDATE batches SET status='STOPPED' WHERE batch_id=?").run(batchId); return "STOPPED"; }
  }
  db.prepare("UPDATE batches SET status='DONE' WHERE batch_id=?").run(batchId);
  return "DONE";
}
web.ts runBatch: resend with the same seq until DONE or ALARM

A real system must be designed so that the PLC keeps the latest result in memory that survives a power loss, and so that the web acknowledges the result (an ack of done) before the PLC deletes it. This example keeps only the latest single result and does not simulate a power loss.

Step 6: the web side: versioned recipes, approval and batch records

Editing a recipe always produces a new version in draft status. The existing one cannot be overwritten. A batch uses only the latest approved version, and the author cannot approve their own recipe (the two-person rule). A recipe with a tolerance above 5% or a negative weight is rejected at save time. The tolerance in kilograms is calculated when the batch is created and stored in the record, so you know which value was used at the time.

web.ts · lines 37–46
// A batch always uses the newest APPROVED version; drafts are invisible to the plant.
export function createBatch(db: DatabaseSync, batchId: string, recipeId: string, lot: string, operator: string): void {
  const r = db.prepare("SELECT version, lines FROM recipes WHERE id=? AND status='approved' ORDER BY version DESC LIMIT 1").get(recipeId) as { version: number; lines: string } | undefined;
  if (!r) throw new Error("no approved recipe");
  db.prepare("INSERT INTO batches VALUES (?,?,?,?,?,'OPEN')").run(batchId, recipeId, r.version, lot, operator);
  (JSON.parse(r.lines) as RecipeLine[]).forEach((l, i) => {
    const tol = Math.round(l.kg * l.tolPct) / 100; // kg
    db.prepare("INSERT INTO batch_lines (batch_id,line_no,material,target,tol,status) VALUES (?,?,?,?,?,'PENDING')").run(batchId, i + 1, l.material, l.kg, tol);
  });
}
web.ts createBatch: uses the latest approved version and calculates the tolerance in kilograms

The batch record stores the target, the actual weighed value, the tolerance, the operator, the raw material lot, the recipe version, the in-flight value used, and the alarms. This is what an auditor or the quality department will ask about afterward.

A real run: six groups of events

output.txt
== 1. recipe versions and approval ==
approve by author: author cannot approve own recipe
v1 approved, v2 still draft -> a batch uses v1
bad recipe: bad line: {"material":"corn","kg":-5,"tolPct":0.6}

== 2. in-flight value adapts from batch to batch (target 50 kg, tol 0.30 kg) ==
batch  seq  inflight_used  cut_kg  actual_kg  error_kg  status
B1     2    0              50.1    50.8       0.80      ALARM -> next 0.35
B2     3    0.35           49.67   50.45      0.45      ALARM -> next 0.567
B3     4    0.567          49.44   50.16      0.16      DONE -> next 0.644
B4     5    0.644          49.36   50.1       0.10      DONE -> next 0.69
B5     6    0.69           49.33   50.07      0.07      DONE -> next 0.714
B6     7    0.714          49.37   50.1       0.10      DONE -> next 0.72

== 3. lost reply + duplicated request: dosed once per seq ==
result DONE, seq 8 dosed 1 time(s), new orders on PLC: 1

== 4. web app restarts mid-batch, resends the same seq ==
first run: LINK_DOWN
after restart: DONE, seq 9 dosed 1 time(s)

== 5. alarms ==
feeder stuck : STOPPED "NO_FLOW"
noisy scale  : STOPPED "SCALE_UNSTABLE_TARE"
first batch with in-flight 0: STOPPED "OVER_TOLERANCE"

== 6. web link lost in the middle of a batch ==
finish: step=IDLE status=DONE alarm=- actual=50.11 valve=0
hold  : step=HELD status=ALARM alarm=LINK_HOLD actual=- valve=0
Output from a real run on 2026-11-21 with node --no-warnings demo.ts (Node 24.21)

Reading the results one by one

  1. Recipes: the author cannot approve their own recipe. Recipe version 2, still in draft, is not used, and the batch gets version 1. A recipe with a negative weight is rejected.
  2. In-flight: the first batch used a value of 0 and got 50.80 kg, which is 0.80 over, so it raised OVER_TOLERANCE and learned 0.35. The second batch was 0.45 over and still raised the alarm. The third batch was 0.16 over and passed. The value then converged to about 0.7 kg (the true fall is 0.6 kg plus the effect of the filter), and the error dropped to 0.07 to 0.10 kg with nobody adjusting by hand.
  3. Lost reply and duplicate command: the command was sent twice in a row, and the first two replies were lost. Seq 8 was dosed once, and there was one new command on the PLC.
  4. Web restart midway: the command reached the PLC but the reply did not come back. On the first attempt the web returned LINK_DOWN. Meanwhile the PLC dosed all the way to the end by itself. When the web came back and sent the same seq, it got the same result. It was dosed once.
  5. Alarms: material that does not flow gives NO_FLOW, an unstable reading gives SCALE_UNSTABLE_TARE, and a new batch whose in-flight value is still 0 gives OVER_TOLERANCE. The batch is stopped and waits for the operator.
  6. Web lost during feeding: the finish policy doses to the end by itself, gets 50.11 kg, and keeps the result until the web returns. The hold policy closes the valve immediately and stays in HELD with a LINK_HOLD signal, and does not continue dosing.

Item 6 is the reason for the rule that the PLC does not depend on the web for real-time control. All the commands needed to dose to completion are already in the PLC from the moment it receives the order. Whether to choose finish or hold depends on the raw material. If stopping midway would ruin or endanger the whole tank (for example a reactive substance), it may be necessary to dose to the end. If continuing to dose with nobody watching is riskier, use hold. This is a decision to make together with the machine users and the safety engineer, not a value the code author guesses.

demo.ts · lines 71–82
say("\n== 6. web link lost in the middle of a batch ==");
for (const policy of ["finish", "hold"] as const) {
  const p = createPlant(3), c = createPlc(p, policy);
  c.inflight.corn = 0.7; // value learned earlier
  createBatch(db, "L" + policy, "feed-A", "LOT", "op1");
  const row = batchRecord(db, "L" + policy).lines[0] as { seq: number };
  c.receive({ seq: row.seq, batchId: "L" + policy, material: "corn", target: 50, tol: 0.3 });
  for (let i = 0; i < 100; i++) c.scan(); // ~5 s: coarse feeding
  c.setLink(false); // web app / network gone
  for (let i = 0; i < 400; i++) c.scan();
  say(`${policy.padEnd(6)}: step=${c.state().step} status=${c.state().last?.status} alarm=${c.state().last?.alarm ?? "-"} actual=${c.state().last?.actual ?? "-"} valve=${p.valve}`);
}
demo.ts group 6: comparing the finish and hold policies

The test suite

plc.test.ts has 5 cases. Running node --no-warnings --test plc.test.ts gives 5 passes. The first case checks that the in-flight value converges: the first batch must fall outside the tolerance, the last three runs must pass, and the learned value must be close to the true value. The second case checks all three alarms and a command that makes no sense. The third case checks duplicate seq handling.

plc.test.ts · lines 12–22
test("in-flight value converges and the error falls inside tolerance", () => {
  const c = createPlc(createPlant(1));
  const errs: number[] = [];
  for (let s = 1; s <= 8; s++) {
    c.receive(ord(s)); run(c); c.reset();
    errs.push(Math.abs((c.state().last?.actual ?? 99) - 50));
  }
  assert.ok(errs[0] > 0.3, "first batch with in-flight 0 should be out of tolerance");
  assert.ok(errs.slice(-3).every((e) => e <= 0.3), "last three batches within tolerance: " + errs);
  assert.ok(Math.abs((c.inflight.corn as number) - 0.7) < 0.1, "learned value near the real 0.6-0.7 kg");
});
plc.test.ts: the case where the in-flight value converges
plc.test.ts · lines 37–48
test("a repeated or stale sequence number is never dosed twice", () => {
  const c = createPlc(createPlant(3));
  assert.equal(c.receive(ord(5)).status, "ACK");
  assert.equal(c.receive(ord(5)).status, "ACK", "duplicate while running");
  assert.equal(c.receive(ord(6)).status, "BUSY");
  run(c);
  const done = c.receive(ord(5));
  assert.ok(done.status === "DONE" || done.status === "ALARM");
  assert.equal(c.receive(ord(5)).actual, done.actual, "same stored result");
  assert.equal(c.receive(ord(4)).status, "STALE");
  assert.equal(c.starts[5], 1);
});
plc.test.ts: the case where a duplicate or old seq must not dose again

The remaining two cases check the policy when the web connection is lost, and the web-side rules (self-approval, an unapproved recipe, resending after a restart). If anyone edits the code so that any mechanism breaks, the test suite fails.

Where a real system differs from the example

  • Language and hardware: a real PLC is written per IEC 61131-3, for example ST or LD, and receives the load cell signal through a transmitter via an analog module or a digital bus. The scan cycle and the filter must be set to suit the devices (see the related article on choosing load cells and communication).
  • Safety: emergency stops and process-level interlocks (for example, never open the valve if the tank door is open) are not in the example at all. They must be designed according to the machine's risk assessment, not through the web software.
  • Calibration: the scale must be calibrated with standard weights after installation and at regular intervals. However good the learned in-flight value is, it cannot fix the error of an uncalibrated scale. Run many consecutive test cycles before handover.
  • Legally relevant weighing: if the dosed weight is used to bill customers, or the product is controlled by weights and measures law, check whether the machine and software fall under it and whether they must pass an inspection. OIML R 61 is an international recommendation for automatic gravimetric filling instruments. Thai law must be confirmed by a specialist.
  • Changing values: the in-flight value and the tolerance should have edit permissions and an edit log, on both the PLC side and the web side.
  • Database: node:sqlite in the example is in memory and experimental. A real system uses a database with backups and user permissions.

Connecting to PLCs of various brands with Modbus TCP, and separating recipes from step sequencing, are covered in articles that go into more detail. See the related articles at the bottom of the page.

Hypothetical examples: adapting it to three businesses

Small animal feed mill

A recipe with several items per batch fits the structure of web.ts directly (one recipe has several lines). What needs to be added is an in-flight value for each raw material (the example already stores it as a table keyed by raw material name), since ground corn and bran have very different flow rates, and a raw material lot record per line so problems can be traced back.

Paint or chemical blending plant

Liquids behave differently from powders in flight, and some raw materials must never be mixed before others. The sequence and the permissive conditions must be in the PLC (see the article on interlocks and sequencing). The web app only stores that the recipe has been approved.

Dry goods packing line

The cycle time is very short. Machines like this usually use a dedicated weighing controller that handles coarse and fine feeding and compensation itself. The web app's job is to send the recipe and keep the totals per shift, without touching the machine's cycle time. What this example helps with is designing the handshake so that it knows which lot has already been dosed.

Common mistakes, and a checklist

  • Letting the web app open and close valves, or waiting for a reply from the web at every step. When the network hiccups, the machine hangs or overdoses.
  • Resending a command without a sequence number, which causes double dosing.
  • Using a sequence number generated fresh on every send, instead of one that was saved before sending.
  • Not compensating for in-flight material, or compensating with a fixed value that does not adjust per raw material.
  • Learning the in-flight value from a run with a blocked pipe or an unsettled scale, which distorts the compensation.
  • Reading the weight right after closing the valve without waiting for it to settle.
  • Overwriting an existing recipe version, so old batch records can no longer be explained.
  • Letting the recipe author approve their own recipe.
  • Not recording the recipe version, lot and operator in the batch record.
  1. The scope is clear: the web stores recipes and records, and the PLC controls the machine.
  2. Commands have a seq that is saved before sending, and the PLC does not run the same seq twice.
  3. It is defined whether the PLC finishes or stops when the web is lost, and this has been agreed with the people concerned.
  4. There is tare, coarse feed, fine feed, wait to settle, and a tolerance check on every batch.
  5. There are alarms for no flow, unstable weight and out-of-tolerance, and a person must reset them.
  6. The in-flight value is kept per raw material, adjusts itself with a cap, and is tested with long runs.
  7. The scale is calibrated with standard weights and has a re-check cycle.
  8. Recipes are versioned and approved, and batch records keep the version, lot and operator.

Limits of the example: it uses hypothetical data and is not connected to a real PLC or load cell. There is no safety circuit, no power loss or retained memory, no update that sends the DONE result back to the PLC once the web has received it, and no user permissions. The filter and the learning algorithm are simple. Use it as a learning example, not as production-ready code, and it does not claim to comply with any standard.

References

  1. A Guide to Dynamic Weighing for Industry (INSTMC / NPL Weighing & Force Measurement Panel): in-flight, coarse/fine feed, compensation (accessed 2026-11-21)
  2. OIML R 61: Automatic gravimetric filling instruments (accessed 2026-11-21)
  3. IEC 61131-3: Programmable controllers, Part 3: Programming languages (หน้า IEC) (accessed 2026-11-21)
  4. ISA-88 Batch Control (หน้าคณะกรรมการ ISA) (accessed 2026-11-21)
  5. Node.js: Running TypeScript natively (type stripping) (accessed 2026-11-21)
  6. Node.js: node:sqlite (accessed 2026-11-21)

Add us on LINE

Scan with the LINE app on your phone

QR code to add LINE @Bankoos

LINE ID: @Bankoos

Open LINE on this computer