# SLMP Node-RED API Reference This page is a user-facing index of the JavaScript SLMP client surface used by the Node-RED nodes. Use the usage guide for flow examples, and this page when you need to find the low-level operation name for a specific SLMP command family. The main low-level client type is `SlmpClient` from `lib/slmp/client.js`. Construction requires an IPv4 literal or hostname that resolves to IPv4 in `host`, plus `port`, `transport`, a concrete canonical `plcProfile`, and exactly one complete `target` or `defaultTarget`. Timeout is optional with a 3000 ms default. Monitoring timer is optional with a four-second default (`16` in 250 ms units), accepts exact integers in `0..65535`, and uses explicit `0` for PLC-side indefinite processing wait. It is independent from the local communication timeout. TCP enables keepalive after 30 seconds idle. IPv6 literals and hostnames without an IPv4 result are rejected; the client never selects or falls back to IPv6. Every runtime target field (`network`, `station`, `moduleIO`, and `multidrop`) must be a primitive finite safe integer Number within its field range. Decimal or hexadecimal strings, Booleans, boxed Numbers, and coercible objects are not runtime values. The Node-RED editor separately converts saved connection fields and literal Route JSON using the displayed field radix. `remotePassword` is optional. Omit it (or use explicit `undefined`) to disable managed authentication. When present it must be a printable ASCII string with the selected profile's exact length rule: 6–32 characters for iQ-R-family profiles, or exactly 4 for Q/L-family profiles. Null, empty, non-string, and invalid credentials fail during construction. The credential is private client state and is not returned by metadata or serialization. `connect()` accepts no options. If managed authentication is configured, every new transport generation is unlocked before its first user command. The removed authentication-bypass option is not part of the public surface; normal, raw, and password request paths cannot skip the lifecycle. Ordinary client operations are admitted in FIFO order and only one wire transaction is active at a time. `close()` invalidates the active queue generation, rejects active and queued work, and closes the exact transport generation. If the client is idle it first tries to lock an authenticated generation. If work is active or queued, local close takes priority and the PLC lock state must be treated as unknown. In that case `close()` reports `SLMP_OPERATION_OUTCOME_UNKNOWN` with reason `closed`; the local transport is still closed. Overlapping `close()` calls share one in-flight promise and therefore one generation retirement, at most one managed lock attempt, one transport close, and one success or failure result. Closing state remains active until that shared operation settles, so `connect()` and normal operations cannot enter between concurrent close callers. A later sequential close is idempotent. Each activated transaction has one monotonic absolute deadline covering lazy connect, managed unlock, send completion, response framing/correlation, and protocol response decode through the boundary immediately before command-specific result materialization. Partial frames, wrong serials, and foreign routes do not restart it. An explicit `connect()` has its own connection deadline. A timeout before that boundary retires the current transport generation; no timed-out operation is retried or resent automatically. Once the public Promise has settled with a successful value, write acknowledgement, or PLC end code, a later `close()` or deadline cannot replace that result. Before publication, an incomplete non-state-changing read is reported as `SlmpClosedError`. An incomplete state-changing request that may have been sent is instead reported as outcome unknown with reason `closed`. The FIFO response phase validates the complete transport identity and the command-specific body shape, including exact lengths, acknowledgement emptiness, bit nibbles, label boundaries, and self-test echo data. A malformed body retires that transport generation before another queued wire request can send; a possibly-sent state change remains outcome-unknown. After validation, pure array/object/string/Buffer construction may run outside the wire FIFO. Public Promises still settle in admission order, and `close()` is checked before materialization and again before publication. UDP completion additionally requires both a successful `socket.send()` callback and a matching complete response. Either may arrive first; a response that arrives first is provisional until send success. Send failure discards it, retires and closes the UDP socket generation, and preserves the normal read-only transport or state-changing outcome-unknown classification. Traffic counters are not updated for a provisional matching response. A socket error releases the detached socket and ignores all later callbacks and messages from that generation. Missing send completion or response expires at the one absolute transaction deadline. ## Direct And Random Device Operations | Operation | Public API | | --- | --- | | Direct device read/write | `readDevices`, `writeDevices` | | Single-request contiguous words | `readWordsSingleRequest`, `writeWordsSingleRequest` | | Single-request contiguous bits | `readBitsSingleRequest`, `writeBitsSingleRequest` | | Single-request DWords / float32 | `readDWordsSingleRequest`, `readFloat32s` | | Extended Direct words | `readWordsExtended`, `writeWordsExtended` | | Extended Direct bits | `readBitsExtended`, `writeBitsExtended` | | Random read | `readRandom` | | Extended random read | `readRandomExtended` | | Random word/dword write | `writeRandomWords` | | Extended random word/dword write | `writeRandomWordsExtended` | | Random bit write | `writeRandomBits` | | Extended random bit write | `writeRandomBitsExtended` | | Block read/write | `readBlock`, `writeBlock` | | Type name | `readTypeName` | Extended Direct and Extended random APIs use the 008x subcommands. Use qualified device notation such as `U1\G0`, `U3E0\HG0`, or `J2\SW10` where the route requires it. Raw extension fields are not public. When index or indirect modification is needed, wrap the address in `new SlmpExtendedDevice(address, modification)` with `SlmpIndexZ`, `SlmpIndexLz`, or `SlmpIndirect`. Extended write tuples are exact `[device, value]` pairs; the device may be a qualified string or the typed wrapper. The former `readRandomExt`, `writeRandomWordsExt`, `writeRandomBitsExt`, and `registerMonitorDevicesExt` names remain temporary direct delegates. New code uses the `...Extended` names. `readDevices` and `writeDevices` require a Boolean `bitUnit`. With `bitUnit: true`, the device must be a canonical bit device. Explicit `bitUnit: false` access may still read or write a packed 16-bit word through a bit-device family. Random bit entries and Block `bitBlocks` require bit devices; Block `wordBlocks` require word devices. Random and block writes reject duplicate or overlapping destinations. Every bit write value is a native JavaScript Boolean; numeric and string spellings such as `0`, `1`, `"ON"`, and `"OFF"` are rejected before transport. Every object-form DeviceRef used by direct, typed, random, block, or monitor helpers must carry the exact client `plcProfile`; a missing or different identity is rejected before serial allocation or transport. Structured device operations must also fit their complete consumed span in the selected wire device-number field. The exact protocol boundaries are 24 bits for Q/L and 32 bits for ordinary iQ-R entries. A link-direct `J`-qualified entry always uses the 24-bit Q/L device specification, including on an iQ-R client. A normal word or bit consumes one device number, an ordinary DWord or float consumes two word-device numbers, and a packed bit-device word or Block bit point consumes 16 bit-device numbers; a low-level packed bit-device DWord consumes 32. Native long devices keep their command-specific stride. Direct, Random, Monitor registration, Block, typed, and named helpers reject a crossing span before request framing, serial allocation, connection, or traffic accounting. This is a wire-format check only; profile-catalog practical device ranges are not used as pre-transport address guards. Random word/DWord write overlap checks use the same ordinary, packed-bit, and native long-device widths, so overlapping destinations are rejected without rejecting valid adjacent native DWords. `readNamed` emits exactly one Random Read request or rejects the complete plan before transport. Counted word values, strings, DWord arrays, and packable bit entries are expanded into Random Read entries and deduplicated within the selected profile's one-request limit. That expansion and each result index are compiled once into a private immutable plan reused by send and result mapping; the plan is not exposed for caller mutation. A long-timer route that requires Direct Read is never selected implicitly; use `readTyped` or an explicit long-timer helper. `writeNamed` also must fit exactly one request and rejects the complete update before I/O otherwise. For a fixed repeated read, call `prepareReadNamed(client, addresses, options)` once and retain the returned opaque plan. `await plan.execute({ signal })` reuses the owned request payload and result indexes while still assigning a new serial, entering the normal FIFO, enforcing a new absolute deadline, and checking the current client lifecycle on every execution. An aborted active execution retires its transport generation so a late response cannot satisfy a later request. Call `plan.dispose()` when the plan is no longer needed. Disposal rejects future executions and releases the retained client, payload, and decode plan references; an execution that was already admitted completes normally. The prepared plan is bound to the exact `SlmpClient` and its profile, frame, compatibility, and target signature. It may be reused after an explicit close/reopen of that same unchanged client, but not with another client or after a configuration-signature change. `compileReadPlan` remains the inspectable structural address-expansion API; it is not a send-ready client-bound plan. `readNamed` remains the one-shot convenience API and does not accept a prepared plan in place of addresses. The Node-RED read node applies the same API internally with a one-entry exact-match cache, including for dynamic addresses and targets. Numeric high-level writes for `U`, `S`, `D`, `L`, and `F` accept primitive JavaScript Numbers only. Numeric strings, boxed Numbers, `BigInt`, Booleans, null, arrays, and coercible objects fail before queue admission. Accepted integers must retain the existing exact wire range, and `F` must remain finite after Float32 conversion. Scalar and counted-array forms use the same policy; `STR` remains string-only and `BIT` remains Boolean-only. High-level helper options may supply request-scoped values such as `target`. The helper-generated device lists, value lists, block lists, point counts, and `bitUnit` route are authoritative and cannot be replaced through that options object. ## Specialized Operations | Operation | Public API | | --- | --- | | Monitor registration/cycle | `registerMonitorDevices`, `registerMonitorDevicesExtended`, `runMonitorCycle` | | Label array access | `readArrayLabels`, `writeArrayLabels` | | Label random access | `readRandomLabels`, `writeRandomLabels` | | Remote CPU control | `remoteRun`, `remoteStop`, `remotePause`, `remoteLatchClear`, `remoteReset` | | Remote password | `remotePasswordUnlock`, `remotePasswordLock` | | CPU operation state | `readCpuOperationState` | | Latest self-diagnosis error code | `readLatestSelfDiagnosisErrorCode` | | Self-test loopback | `selfTestLoopback` | | Clear PLC error | `clearError` | Array label `unitSpecification` is `0` for a logical bit count and `1` for a logical byte count. Both forms occupy whole two-byte wire units: bit counts use `ceil(arrayDataLength / 16) * 2` bytes and byte counts use `ceil(arrayDataLength / 2) * 2` bytes. The logical length must be positive, and `writeArrayLabels` requires the exact padded buffer length. Random label read and write data lengths must also be positive and even. Read responses must match the requested count and, for array labels, each requested unit and logical length; malformed or trailing data raises `SlmpError`. Remote RUN is `remoteRun({ force, clearMode })`, where `force` is Boolean and `clearMode` is one of `RemoteClearMode.NO_CLEAR`, `RemoteClearMode.CLEAR_EXCEPT_LATCH`, or `RemoteClearMode.CLEAR_ALL`. Remote PAUSE is `remotePause({ force })`. Both fields are required. Remote RESET accepts no subcommand or response-wait override. `remotePasswordUnlock` and `remotePasswordLock` are explicit low-level commands for a client constructed without managed `remotePassword`. They are rejected on a managed client so a manual lock cannot make its connection-generation state incorrect. Managed clients use only automatic connect/close authentication. Monitor registration and each `runMonitorCycle` call are separate one-request operations. The cycle requires explicit registered Word and DWord counts. It does not auto-register, retry, or infer them; the PLC defines the error when a cycle is requested before registration. `selfTestLoopback` accepts a 1–960 byte Buffer containing only ASCII `0-9/A-F` and verifies declared length, actual length, and exact echo. `clearError` always uses the fixed empty payload. ## High-Level Helpers | Operation | Public API | | --- | --- | | Address parsing and formatting | `parseDevice`, `deviceToString`, `normalizeAddress`, `parseAddress`, `formatParsedAddress` | | Extended-device model | `SlmpExtendedDevice`, `SlmpIndexZ`, `SlmpIndexLz`, `SlmpIndirect` | | Typed values | `readTyped`, `writeTyped` | | Named one-request reads and writes | `compileReadPlan`, `prepareReadNamed`, `readNamed`, `writeNamed` | | Structured long-timer reads | `readLongTimer`, `readLongRetentiveTimer` | | Bit-in-word write | `writeBitInWord` (direct or qualified U/J Extended Device route) | `writeBitInWord` validates and snapshots the complete operation before it enters the client queue, including both request routes and capacity. It then holds one ordinary-client FIFO turn and one absolute procedure deadline while it sends one word read followed by one word write. The write is still sent when the requested bit already has the desired value. This prevents another operation on the same client from interleaving between those requests, but it is not an atomic PLC operation: another connection or PLC program logic can change the word in the race window, and the read and write can occur in different PLC scans. A failure after the write may have been sent is outcome-unknown. The helper never retries automatically; verify PLC state before deciding whether to issue a new operation. Direct words use Direct Read/Write. Qualified U module-buffer and J link-direct words use Extended Random Read/Write, with the exact same qualified route in both requests. Unsupported profile/route combinations fail before the read. All public address-to-number and number-to-address helpers require the canonical `plcProfile`. `parseDevice` returns an immutable semantic object that contains that profile. Passing the object to a client configured for another profile is rejected before serial allocation, counters, or transport. This exact match also applies inside direct, random, block, monitor-registration, and unit-specific word/bit collections. The supported dtype vocabulary is `BIT`, `U`, `S`, `D`, `L`, `F`, and `STR`. Compatibility spellings `:I`, `:STRING`, and `DSTR...` are not accepted. `:BIT` is valid only for canonical bit devices. Numeric and string dtypes are valid only for canonical word devices; use the `.0` through `.F` selector for a semantic bit inside a word device. This semantic rule is separate from explicit low-level packed word-unit access to a bit-device family. `parseAddress()`, `formatParsedAddress()`, and `normalizeAddress()` accept count-free AddressSpec values only. The `,count` grammar remains part of `readNamed` / `writeNamed` request entries, where it accepts complete ASCII decimal text from `1` through `Number.MAX_SAFE_INTEGER`. Signs, whitespace, fractions, exponents, non-ASCII digits, trailing text, and zero are rejected before the command/profile point limit is applied. `parseDevice()` and `deviceToString()` are the existing DeviceAddress surface for direct devices such as `D100` and `X10`. The count-free `parseAddress()`, `formatParsedAddress()`, and `normalizeAddress()` family is the existing AddressSpec surface for dtype/bit-selected expressions such as `D100:U` and `D50.A`. DeviceAddress parsing rejects typed expressions and qualified routes; AddressSpec parsing rejects plain devices and qualified `U...\\...` / `J...\\...` routes. Qualified routes remain the separate `SlmpExtendedDevice` contract. No synonymous `parseDeviceAddress` or `parseAddressSpec` API is exported. Numeric fields in runtime extension objects also require primitive finite safe integer Numbers. An explicitly present `null` is invalid; only an omitted optional field selects its documented default. String qualification in `Jn\...` and `Un\...` device syntax is unchanged; it is parsed as address syntax rather than runtime numeric coercion. The raw request API requires command, subcommand, and an explicit byte payload. Known commands have a fixed read-only/state-changing classification. Unknown vendor commands are conservatively state-changing unless the caller supplies the Boolean `stateChanging: false` assertion. Request `series` and 4E `serial` are not public options; both are derived or assigned by the client. PLC errors expose the numeric end code, stable `slmp_end_code_xxxx` key, and structured error information, not localized manual-derived messages. When a non-zero response contains structured error information, its network, station, module I/O, multidrop, command, and subcommand must match the active wire request. A mismatch raises a malformed `SlmpError`, closes the supplying transport generation, and is not a definitive PLC error. A possibly sent state-changing operation is instead `SlmpOperationOutcomeUnknownError` with reason `malformed-response`. Bytes after a matching nine-byte prefix remain available as additional PLC error data. Standard acknowledgement-only APIs also require an empty data body after end code zero; unexpected data is the same malformed/outcome-unknown failure. `rawCommand()` is excluded and continues to return arbitrary successful response data. Timeout and lifecycle errors are machine-readable: `SlmpTimeoutError` (`SLMP_TIMEOUT`), `SlmpClosedError` (`SLMP_CLOSED`), and `SlmpNotConnectedError` (`SLMP_NOT_CONNECTED`). If a state-changing request may have been sent before timeout, close, or transport failure, the result is `SlmpOperationOutcomeUnknownError` (`SLMP_OPERATION_OUTCOME_UNKNOWN`). Its `reason` is `timeout`, `closed`, `transport`, or `malformed-response`, and `cause` retains the original error. Do not automatically retry outcome-unknown operations; first verify PLC state. TCP command payloads are limited to 65,529 bytes. UDP command payloads are limited to 65,492 bytes for 3E and 65,488 bytes for 4E so the complete frame fits one datagram. Single-request command builders reject oversized inputs before transport or serial allocation and never truncate or split them. Label builders additionally enforce their aggregate payload size; their largest protocol-representable even payload is 65,528 bytes. `readNamed` never splits a plan: its expanded Random Read entry count must fit the selected profile limit. ## Profile Selection `availablePlcProfiles()` returns a new array of canonical, connection-selectable profile IDs. It excludes `Unspecified` and the base-only `melsec:qcpu` profile; modifying the returned array does not change the library's profile registry. `profileDescriptors()` returns canonical name, display name, connection availability, and base-profile metadata for every profile. The base-only `melsec:qcpu` entry is included with `connectable: false`; the editor filters that entry from connection selections. `plcProfileDisplayName(profile)` returns one display label for a canonical profile. The former `displayName(profile)` name remains a temporary direct delegate; profile descriptor `displayName` fields are unchanged. `getProfileLimit(profile, key)` accepts a canonical value from `SlmpProfileLimitKey` and returns a frozen `{ maxPoints, weightedMaxPoints }` object from the same capability table used by request validation. The weighted value is `null` when that command has no second weighted limit. An unknown profile/key pair returns `null`; the lookup performs no PLC communication and does not expose capability evidence fields. ## Target Module I/O Constants `ModuleIONo` provides named request-header module I/O numbers for multi-CPU and routed CPU targets. Use these values in the route object's `moduleIO` field; omitted route targets still use the own-station route `0x03FF`. | Constant | Value | | --- | --- | | `ModuleIONo.CONTROL_SYSTEM_CPU` | `0x03D0` | | `ModuleIONo.STANDBY_SYSTEM_CPU` | `0x03D1` | | `ModuleIONo.SYSTEM_A_CPU` | `0x03D2` | | `ModuleIONo.SYSTEM_B_CPU` | `0x03D3` | | `ModuleIONo.MULTIPLE_CPU_1` .. `ModuleIONo.MULTIPLE_CPU_4` | `0x03E0` .. `0x03E3` | | `ModuleIONo.REMOTE_HEAD_1` / `ModuleIONo.REMOTE_HEAD_2` | `0x03E0` / `0x03E1` | | `ModuleIONo.CONTROL_SYSTEM_REMOTE_HEAD` / `ModuleIONo.STANDBY_SYSTEM_REMOTE_HEAD` | `0x03D0` / `0x03D1` | | `ModuleIONo.OWN_STATION` | `0x03FF` | ## Traffic Statistics `SlmpClient.trafficStats()` returns a frozen `{ requestCount, txBytes, rxBytes }` snapshot. Counters are cumulative for the client lifetime and are not reset by close or reconnect. ## PLC clock setting For Node-RED input examples and the readback flow, see the [slmp-set-time node usage](USAGE_GUIDE.md#slmp-set-time-node). `SlmpClient.setTime(value, options = {})` writes SM210 OFF, SD210 clock words, then SM210 ON under one client operation lock. Q/QnU/QnUDV/L use four packed BCD words; iQ-R/iQ-F/iQ-L/MX-F/MX-R use seven BIN words. Ethernet module profiles use the CPU's clock layout. Unknown layouts reject before sending. `Date` uses host local fields (1980..2079). Seven-integer arrays use `[YY, month, day, hour, minute, second, weekday]`, YY 0..79, Sunday 0. Target options are forwarded to every write. The return value confirms write acknowledgements only; follow the target CPU's clock-processing requirements and verify actual clock application separately. Q/L and iQ-R/iQ-F require END processing. Do not automatically retry partial failures. | Series / profiles | Clock registers | Encoding | Clock specification reference | | --- | --- | --- | --- | | QCPU, QnU, QnUDV, including QJ71E71-100 | SD210..SD213 | Four packed BCD words: YY/month, day/hour, minute/second, century/weekday | QCPU User's Manual (Hardware Design, Maintenance and Inspection), SH-080483ENG-BB, Appendix 2 (SM210/SM213), Appendix 3 (SD210..SD213); QnUCPU Function Explanation, SH-080807ENG-AF, 3.5 | | LCPU, including LJ71E71-100 | SD210..SD213 | Same four-word BCD layout | SH-080483ENG-BB, Appendix 2 and 3, corresponding CPU columns for LCPU | | iQ-R, including RJ71EN71 | SD210..SD216 | Seven BIN words: year, month, day, hour, minute, second, weekday | MELSEC iQ-R Programmable Controller CPU Module User's Manual, SH-082488ENG-G, Clock Function and special register list | | iQ-F (FX5) | SD210..SD216 | Same seven-word BIN layout | MELSEC iQ-F FX5 User's Manual (Application), JY997D54301AF, 18.1 | | iQ-L | SD210..SD216 | Same seven-word BIN layout | MELSEC iQ-L CPU Module User Manual (Application), SH-082170CHN-H, 4.1 and Appendix 5 (SD210..SD216) | | MX-F | SD210..SD216 | Same seven-word BIN layout | MELSEC MX Controller MX-F Model User's Manual, SH-082633-E, Appendix 4 (Clock Data), Appendix 7 (SD210..SD216) | | MX-R, including RJ71EN71 | SD210..SD216 | Same seven-word BIN layout | MELSEC MX Controller MX-R Model User's Manual, SH-082640-D, Appendix 4 (Clock Data), Appendix 7 (SD210..SD216) | All listed series use SM210 OFF-to-ON to request setting and SM213 ON to refresh the clock registers for reading. Q/L and iQ-F do not document the automatic SM210 reset used by iQ-R/iQ-L/MX-F/MX-R; an acknowledged write alone does not guarantee that SM210 is OFF. The iQ-R example's SM210-OFF completion check is specific to that example. Coordinate these special devices with the PLC program and other clients. Clock layout references: [FX5 clock setting (SD210..SD216)](https://fa-faq.mitsubishielectric.com/faq/show/44365), [QnU clock function (SD210..SD213)](https://dl.mitsubishielectric.com/dl/fa/document/manual/plc/sh080807eng/sh080807engaf.pdf), and [iQ-R CPU clock function](https://www.mitsubishielectric.com/dl/fa/document/manual/plc/sh082488eng/sh082488engf.pdf). This helper uses Device Write (1401), not a dedicated SLMP clock command.