Skip to main content

Process Data

Process data refers to the I/Q bytes exchanged with the controller every cycle. Once the I/Q is mapped to a structure, reading and writing the fields is equivalent to reading and writing the current process data, without the need for copying or flushing.

There are only two directions: Write Q (device → controller), Read I (controller → device). Zone I is read-only; writing to it returns "Not supported." Do not copy the value from I back to Q. After writing to Q, the controller will read the value you wrote, and it will be automatically transmitted in the next cycle—there is no need to call the commit function again.

The bus cycle is handled by the service process.SDK It does not create its own cycle loop, nor does it have user callbacks—you determine the scheduling (loop/timer) yourself.

If the process data cannot be read, simply discard those records as过程数据未就绪 is.

The equipment isFixed Single Module: Slot 1 / subslot 1. None of the entries on this page accept slot parameters, nor should they.

Don't get confused

The 20-byte input in GSDML (device → controller) is the SDK's Q; the 32-byte output in GSDML (controller → device) is the SDK's I.

20 / 32 are just common sizes in the factory configuration, Don't be too rigid. The length is subject to change during the performance.

Two Ways to Retrieve Data

The first ismapping to a structure: getInputsMapping / getOutputsMapping(structure, or ByteBuffer). Second, Directly access the data pointer: tryGetLiveIoPayload Provide you Pointer with the I/Q data and the number of bytes.

The elements retrieved by offset (getIn().get(i) this family) areCopy. Each time a value is retrieved, it is read on the spot and then interpreted as a value.

Use Cases​

Everyday Use​

① mapping to a class (for ongoing use): Once the structure is defined and mapped once, it can be used as a variable thereafter.

import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;

@FieldOrder({"present", "recipeHi", "recipeLo", "flag"})
public static class FromPlc extends Structure { // I: Controller → Device
public byte present; // Offset 0
public byte recipeHi; // Offset 1
public byte recipeLo; // Offset 2
public byte flag; // Offset 3
public FromPlc() { super(ALIGN_NONE); } // ALIGN_NONE = Pack 1, Required
}

@FieldOrder({"ready", "busy"})
public static class ToPlc extends Structure { // Q: Equipment → Controller
public byte ready;
public byte busy;
public ToPlc() { super(ALIGN_NONE); }
}
import com.darra.pns.service.PnSService;

try (PnSService device = new PnSService()) {
device.start();

FromPlc inp = device.getProcessData().getInputsMapping(FromPlc.class); // Map once
ToPlc outp = device.getProcessData().getOutputsMapping(ToPlc.class);

inp.read(); // Current Cycle I Data → Cached in Host: The data read is from the current cycle
byte present = inp.present;
outp.ready = (byte) (present + 1);
outp.write(); // Cache Management → Q Data: Changes take effect immediately after being written; sent in the next cycle
}

The field is a managed cache: read() has already been called once automatically at mapping time; afterwards you must call read() to get the latest value and write() after changing it.

② Single-read (one-time retrieval): Do not create a mapping; read the entire byte sequence at once, or retrieve a single value based on an offset.

byte[] i = device.getProcessData().getInputs();                    // I Entire passage (read in one go; self-contained within a single beat)
short recipe = device.getProcessData().getIn().get(2).getInt16(); // Big-endian with offset 2 i16

String fields are fixed-length bytes in the process data; they are extracted from the bytes read in a single operation:

byte[] i = device.getProcessData().getInputs();
String partNo = new String(i, 4, 16, java.nio.charset.StandardCharsets.US_ASCII).trim(); // Offset 4, starting at 16 bytes

③ Read and write by address (area + byte + bit): If you don't want to calculate the offset yourself, just use the address shown in the engineering software.

boolean done  = device.readBool("I0.0");        // position
short recipe = device.readInt16("IW2"); // word
int counter = device.readInt32("ID4"); // double word

device.writeBool("Q0.0", true);
device.writeInt16("QW2", (short) 123);
device.writeInt32("QD4", 10000);

Cyclical Changes​

Place the same mapping directly into your own loop (the mapping is fetched only once, and the service is moved every cycle).

FromPlc inp = device.getProcessData().getInputsMapping(FromPlc.class);
ToPlc outp = device.getProcessData().getOutputsMapping(ToPlc.class);

while (running) { // Your recurring tasks—set your own schedule
inp.read(); // Current Cycle → Cached in Storage
outp.ready = (byte) (inp.present + 1);
outp.write(); // To be sent in the next cycle
Thread.sleep(10); // Throw InterruptedException: The method in question must either declare `throws` or catch the exception itself.
}

Don't remap within the loop: Once you've mapped a value, use it for the rest of the loop to avoid having to resolve it again each time. Cost: A mapping recognizes the data layout at the moment the mapping is created; as soon as the layout changes, it becomesSilent misalignment(No exceptions are thrown; the data is read as incorrect bytes.) When the data layout changes, remap it each time, or switch to readStruct / readArea Retrieve by offset.

Event streams (getEvents()) report operational metrics such as connections, ST, links, and quality IO ; you can retrieve data updates at your own pace (read() / getIo() / (Mapped View).

Structure Mapping​

mapping Structure "packed" to I/Q data: This provides a continuous view (not a snapshot), and reading or writing fields directly modifies the current process data. close() / After remapping, the old view becomes invalid and must be reacquired.

Structure There are two mandatory requirements on this side; if they are not met, the data cannot be mapped or dirty data will be read:

@FieldOrder({"statusWord", "flag"})            // All fields must be explicitly listed, and their order must match the byte order in the process data.
public static class ServoIn extends Structure {
public short statusWord; // A multi-byte field is**Online Bytes**... Reading in host order will result in errors
public byte flag;
public ServoIn() { super(ALIGN_NONE); } // Pack 1, Required
}
  • Fields contain only value types and are packed tightly in the order they are declared (without padding). For bit/boolean fields, use byte(JNA to treat boolean the field as a 4-byte native type int).
  • ALIGN_NONE power-off automatic JNA alignment padding. If you forget to do this, the field positions will be misaligned overall.
  • Non-compliant structures (missing @FieldOrder, or fields that do not match their declarations) are rejected by JNA itself; this SDK performs no extra validation.

getInputsMapping(Class<T> type)​

public <T extends Structure> T getInputsMapping(Class<T> type)   // ProcessData

mapping the data in Zone I to a view JNA Structure and return it. In read-only mode, reading or writing a field is equivalent to reading or writing the current process data.

Return value:

  • T — A Structure subclass instance that has already been automatically mapped once and has default values in its read() fields

Note:

  • type For null → NullPointerException, message type 不能为 null.
  • Session not established (no start() / connect()), data channel not ready → IllegalStateException, message 过程数据输入映像不可用.
  • Structure size() <= 0, or a length greater than I IllegalStateException→ message 结构体大于输入过程映像.
  • Maps toOnline Bytes(Web application). Using the short / int field as a host value will return an incorrect value — to get the host value, please go to readStruct, or switch toElement Port(It includes big-endian decoding.)
  • The field is a managed cache: to read the latest value, you must inputs.read(). Otherwise, it read() will always be the old value you read last time.
  • Zone I is read-only; writing to I returns "Not supported"; calls to the input view write() are also rejected. If you want to write, write to Q.
  • close() After that, the old view becomes invalid and must be re-fetched.
  • Mapping from I dataByte 0To begin with, there are no offset parameters. To mapping the middle segment, place a placeholder field at the very beginning @FieldOrder of to push it aside. (public byte[] _skip = new byte[4];, JNA which recognizes this type of fixed-length array declaration); or use readArea Retrieve bytes based on the offset.

Example:

FromPlc inp = device.getProcessData().getInputsMapping(FromPlc.class);
inp.read();
byte present = inp.present;
Dimensions and offsets are determined at runtime.

The usable length of the mapping is less than the length of the input region, and the structure size is equal toAvailable Data LengthHowever, dimensions alone cannot prevent changes in layout.

  • It is still recommended to retrieve the mapping once outside the loop to avoid having to parse it every time. The downside is that any change in the layout causes silent read misalignments. — Do not throw an exception; reading the data results in incorrect bytes. If the data content is likely to change, please remap it each time, or switch to readStruct / readArea.
  • Use the return value at runtime to determine the length; do not hard-code it, and do not extrapolate beyond the length of the input area.

getOutputsMapping(Class<T> type)​

public <T extends Structure> T getOutputsMapping(Class<T> type)   // ProcessData

mapping the data from Zone Q to a view JNA Structure and return it. This is writable; simply modify the fields as needed.

Return value:

  • T — View instance; has already been automatically mapped once read()

Note:

  • type For null → NullPointerException, message type 不能为 null.
  • Session not established / Data channel not ready → IllegalStateException, message 过程数据输出映像不可用.
  • The structure's size() <= 0, or it exceeds the available data length of Q → IllegalStateException with message 结构体大于输出过程映像.
  • After modifying the field, you must save it outputs.write(); otherwise, the changes will only be stored in the JNA managed cache and will not be written to the Q zone.
  • write() Changes take effect immediately upon completion, and the next cycle will be triggered automatically—no need to call the commit function again.
  • Multi-byte fields are alsoOnline Bytes.
  • The view's lifecycle aligns with that of the I side: close() It can be reacquired later, so do not retain old references.
  • The mapping is also based on the Q dataByte 0First, refer to the code for getInputsMapping that placeholder field in the middle section above.

Example:

ToPlc outp = device.getProcessData().getOutputsMapping(ToPlc.class);
outp.ready = 1;
outp.busy = 0;
outp.write();

getInputsMapping() / getOutputsMapping()​

public ByteBuffer getInputsMapping()    // ProcessData: I Data, Read-Only
public ByteBuffer getOutputsMapping() // ProcessData: Q data, writable

The ByteBuffer form of the same process data. If you do not want to write a Structure subclass, or need to move the bytes yourself, use these two.

Return value:

  • ByteBuffer — DirectByteBuffer (not allocateDirect), byte order has been set to BIG_ENDIAN

Note:

  • Session unavailable → IllegalStateException, Message 过程数据输入映像不可用 / 过程数据输出映像不可用.
  • I returns the result asReadOnlyBuffer() of : Writing to it will throw an exception ReadOnlyBufferException.
  • Q is writable. Modifying the bytes in the buffer writes to Q; the changes take effect immediately and are transmitted in the next cycle, without requiring an additional commit call.
  • The byte order is already network-big-endian. Do not order() change to LITTLE_ENDIAN —— In an online system, process data is the "big-endian (network byte order)."
  • close() After that, the buffer became invalid.
  • Position / Upper Limit is up to you:SDK Return a new buffer each time, position starting from 0.

Example:

java.nio.ByteBuffer q = device.getProcessData().getOutputsMapping();
q.putShort(2, (short) 123); // Offset 2: write big-endian i16
int first = device.getProcessData().getInputsMapping().get(0) & 0xFF;

tryGetLiveIoPayload(boolean output, Pointer[] pointer, int[] byteCount)​

public boolean tryGetLiveIoPayload(boolean output, Pointer[] pointer, int[] byteCount)   // PnSService

Take the I/Q dataLive PointerHere's the task: pointer[0] Point to the current data; the bytes read correspond to the current cycle. output = true Retrieve Q (device → controller) andfalse retrieve I (controller → device).

Return value:

  • boolean — true: pointer[0] is the starting address of the data, byteCount[0] is the number of bytes of data; false: pointer[0] = null, byteCount[0] = 0

Note:

  • ItDo not discard: The two arrays are null or the length is insufficient, the session has not been established, the data channel is not ready, or data cannot be retrieved (pointer is null / data length ≤ 0) Always return a value false; the caller determines the next rung based on the return value.
  • The pointer points toAliveData is not a snapshot—what you read are the bytes from the current cycle.
  • byteCount[0] = Available data length (I actual length GET /api/io = outputLength, Q actual length = inputLength; field names are in the opposite order of I/Q, so do not rely on the names). Use this value as the standard; do not hard-code it, and do not extrapolate based on the zone capacity.
  • close() After that, the pointer is no longer valid; do not use the old pointer to read from or write to it.
  • When you move bytes yourself, remember: the bytes on the wire are big-endian, and multi-byte fields are decoded as big-endian (consistent with the value-access family).

Example:

com.sun.jna.Pointer[] p = new com.sun.jna.Pointer[1];
int[] n = new int[1];

if (device.tryGetLiveIoPayload(false, p, n)) { // I Data
byte first = p[0].getByte(0);
int len = n[0];
}

readStruct(byte[] dest) / readStruct(int size)​

public int     readStruct(byte[] dest)   // ProcessData: I Data → Caller Buffer
public byte[] readStruct(int size) // ProcessData: I Data → New Array

Snapshot, not a view: The bytes copied out will not change as they travel down the bus. Read-only direction in Zone I.

Return value:

  • readStruct(byte[]) → int, actual number of bytes copied (= dest.length)
  • readStruct(int) → byte[], newly allocated instance, length = size

Note:

  • dest For null → NullPointerException, message dest 不能为 null.
  • size < 0 → IllegalArgumentException, News size 不能为负: N.
  • dest.length == 0 / size == 0 → Returns 0 / an empty array; no data is read.
  • Insufficient bytes in Zone I → PnSServiceException, message I 区 21 字节不足结构体 24 字节(the number is the actual value).
  • From I DataByte 0Start copying; there are no offset parameters. To copy the middle section, use readArea.
  • What was copied out wasBig-Endian Bytes, no byte-order conversion — it only guarantees that "this is a self-consistent slice of the same beat."

Example:

byte[] packed = device.getProcessData().readStruct(4);       // The first 4 bytes
short recipe = (short) (((packed[1] & 0xFF) << 8) | (packed[2] & 0xFF));

readStruct(T dest)​

public <T extends Packed> T readStruct(T dest)   // ProcessData

Data from Zone I is unpacked into your structure Packed in big-endian order, and the return value is formatted for dest chaining. Snapshot.

Return value:

  • T — The input itself dest ; the fields are already filled in

Note:

  • dest For null → NullPointerException, message dest 不能为 null.
  • dest.packedSize() < 0 → IllegalArgumentException, News packedSize 不能为负: N.
  • Insufficient bytes in Zone I packedSize() → PnSServiceException, same message as above I 区 N 字节不足结构体 M 字节.
  • The ByteBuffer used for unpacking is already set to BIG_ENDIAN, position = 0, and capacity = packedSize(). In unpack you can just read in big-endian order directly.
  • What you get is a snapshot: whatever changes occur in Zone I from now on will have no effect on it; to get a new value, you'll need to call the function again.

Example:

PackedRecipe r = device.getProcessData().readStruct(new PackedRecipe());
if (r.recipe > 1000) startWash();

writeStruct(byte[] packed) / writeStruct(Packed src)​

public void writeStruct(byte[] packed)   // ProcessData: Big-endian packed byte → Q
public void writeStruct(Packed src) // ProcessData: Structure → Q (Submit after big-endian packing)

Snapshot Submission(Copy path), write in the Q direction.

Return value:

  • None (void). Normal return ⟺ Byte has entered the Q area.

Note:

  • packed For null → NullPointerException, message packed 不能为 null.
  • src For null → NullPointerException, message src 不能为 null.
  • src.packedSize() < 0 → IllegalArgumentException, News packedSize 不能为负: N.
  • Empty array / packedSize() == 0 → Do not write anything; return it directly (this is not an fault).
  • Data length + starting offset 0 exceeds the writable range of Q → PnSServiceException, message 区域越界: 偏移 0 + 长度 M 超出过程映像区 K 字节.
  • Cover onlyPrevious packedSize() Byte, while the remaining bytes retain their original values. This is a partial overwrite, not a full-frame replacement.
  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).

Example:

device.getProcessData().writeStruct(new byte[] { 1, 0, (byte) 0xF4 });   // Q: First 3 bytes

PackedRecipe r = new PackedRecipe();
r.recipe = 500;
device.getProcessData().writeStruct(r); // Pack into big-endian and submit

Packed (Structure Contract)​

public interface Packed {
int packedSize(); // Number of bytes after packing (without alignment padding)
void pack(java.nio.ByteBuffer buf); // Structure → Big-endian buffer (write bytes packedSize() starting at position 0)
void unpack(java.nio.ByteBuffer buf); // Big-Endian Buffer → Structure
}

readStruct / writeStruct This is the interface you're working with: if you're not a subclass Structure , just implement it. Manual packing and unpacking—no reflection— so the byte layout is entirely up to you—even big-endian formatting is up to you, as long as you follow the contract.

Return value:

  • packedSize() → int, pack / unpack All read this many bytes
  • pack / unpack → None

Note:

  • The input is ByteBuffer already BIG_ENDIAN, position = 0 , and the capacity is packedSize().
  • packedSize() Returning a negative number will result in rejection (packedSize 不能为负: N), so don't treat it as "unknown."
  • Read and write in big-endian yourself (buf.getShort() / buf.putInt() with the already-set byte order is enough); do not flip the byte order here —— The byte order has already been set once.
  • This interface only handles byte layout; it does not hold any data and has no lifecycle issues.

Example:

public static class PackedRecipe implements com.darra.pns.ProcessData.Packed {
public byte flag;
public short recipe;

@Override public int packedSize() { return 3; }
@Override public void pack(java.nio.ByteBuffer buf) { buf.put(flag).putShort(recipe); }
@Override public void unpack(java.nio.ByteBuffer buf) { flag = buf.get(); recipe = buf.getShort(); }
}

Direct Access (Works Even Without Mapping)​

Even without creating a mapping, you can access determinism fields based on an offset: pd.getIn().get(i) read andpd.getOut().get(i) write. The advantage of this approach is that you don't need to declare the entire layout in advance.

Element Mouth isCopy, not a view

getIn().get(2).getInt16() —every time a value is retrieved, it isA new snapshot tile. ..the value read is the value at that exact moment. The same applies to writing.

So itNo"Live view obtained via index-based positioning": get(i) This only sets the offset; the value is still a snapshot from that moment. To obtain a continuous view, use getInputsMapping / getOutputsMapping or tryGetLiveIoPayload.

getIn() / getOut()​

public DataArray getIn()    // ProcessData: I array, read-only
public DataArray getOut() // ProcessData: Q array, writable

Obtain arrays of elements in both directions, then retrieve items based on byte offsets.

Return value:

  • DataArray — Lightweight packaging (service + direction); does not ST data itself; caches freely

Note:

  • Do not throw: Both methods return only wrapper objects. Actual failures (session not established, data unavailable) occur inThat Moment of Reading / WritingJust threw it away.
  • getIn() Read-only, getOut() writable.
  • device.getProcessData() Returns on each callNew ProcessData(Same session), and the getIn() / in there is also getOut() new Wrapper. Functionally equivalent; no need to cache it intentionally.

Example:

var pd = device.getProcessData();
byte b = pd.getIn().get(0).getContent();

DataArray.getLength()​

public int getLength()   // ProcessData.DataArray

In this area, DataNumber of bytes.

Return value:

  • int — Available data length (I true length GET /api/io = outputLength, Q true length = inputLength; field names are opposite to the I/Q directions—do not rely on the names)

Note:

  • This length isCheck the runtime ST each time the function is called., not a cached constant.
  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • Data channel not ready → PnSServiceException, message 过程数据未就绪, 无法读写 IO.
  • It can't "quietly return to 0.": It throws an exception when data cannot be retrieved; it does not return 0. It returns 0 only when the data for that direction is empty.
  • Use the return value as the length; do not extrapolate based on the shielding size.

Example:

int iLen = device.getProcessData().getIn().getLength();
int qLen = device.getProcessData().getOut().getLength();

DataArray.get(int offset)​

public DataItem get(int offset)   // ProcessData.DataArray

Retrieve an element view based on a byte offset.

Return value:

  • DataItem — Only the service, offset, and direction are stored; no data bytes are stored, and no data accesses are performed.

Note:

  • offset < 0 → IndexOutOfBoundsException, News 偏移不能为负: N.
  • Offsides should not be called here.: get Check only for negative values. The service side will report whether the offset + width is out of bounds at the moment of the actual read or write. 区域越界: 偏移 N + 长度 M 超出过程映像区 K 字节(PnSServiceException).
  • Offset isByte address in the data area, it is not a protocol header address, nor is 2/4 alignment required — valid get(3).getInt32() .
  • Returns on each callNew Object(Not cached by offset.) Do not use object identity as a cache key; under steady-ST conditions, a new small object is created with every retrieval.
  • Retrieving an element does not involve reading data, so this rung does not throw a server-side exception.

Example:

var in = device.getProcessData().getIn();
short recipe = in.get(2).getInt16();

DataArray.set(int offset, byte value)​

public void set(int offset, byte value)   // ProcessData.DataArray

Write one byte at the specified byte offset. Equivalent to get(offset).setContent(value). Q-side only.

Return value:

  • None (void). Normal return ⟺ Bytes committed.

Note:

  • offset < 0 → IndexOutOfBoundsException, News 偏移不能为负: N.
  • Call → on the returned getIn() array UnsupportedOperationException, message In 只读 (控制器→设备); 写请用 getOut().get(i).setContent.
  • Offset out of bounds → PnSServiceException, message 区域越界: 偏移 N + 长度 1 超出过程映像区 K 字节.
  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • It writes the entire byte; no bit operations are performed. Change "bit" to setBit.

Example:

device.getProcessData().getOut().set(0, (byte) 0x11);

DataItem.getOffset()​

public int getOffset()   // ProcessData.DataItem

Returns the byte offset of this element get(i) at the time it was initially created, unchanged.

Return value:

  • int — Non-negative offset

Note:

  • Read-only field; does not throw exceptions and does not access data.
  • Offset isThe moment an element is selectedIt's been recorded. Even if the data length changes, this number won't change along with it.

Example:

var it = device.getProcessData().getOut().get(6);
System.out.println("写到偏移 " + it.getOffset());

Value Family (Read)​

Can read both In and Out: "In" reads the input from the controller, and "Out" reads the Q shadow (reads back the value you just wrote; the read value should match the written value). All multi-byte valuesbig-endian(PROFINET Network Sequence).

public byte    getContent()               // 1-byte raw value
public byte getInt8() // Signed 8-bit
public int getUInt8() // Unsigned 8-bit; returns 0–255
public short getInt16() // big-endian i16
public int getUInt16() // Big-endian u16, returns 0..65535
public int getInt32() // big-endian i32
public long getUInt32() // Big-endian u32, returns 0..2^32-1 (stored in a `long`).
public long getInt64() // Big-endian i64(8 bytes)
public long getUInt64() // Big Endian u64, long with the same bit pattern
public float getFloat() // Big-endian IEEE754 float32(4 bytes)
public double getDouble() // Big-endian IEEE754 float64 (8 bytes)
public boolean isBool() // Whole Bytes,bit0 Semantics
public boolean getBit(int bit) // The bit at position bit in this byte; 0 = LSB

Related Structures:

// Read = take a small segment (copy) and decode it as big-endian
// Offset (bytes) Method Width Sign / Return Type Byte Order
// +0 getContent 1 Original byte ——
// +0 getInt8 1 Signed → byte ——
// +0 getUInt8 1 Unsigned → int (0..255) ——
// +0 isBool 1 Integer byte,bit0 true → boolean ——
// +0 getBit(n) 1 bit n (0..7, where 0 = LSB) → boolean ——
// +0..+1 getInt16 2 Signed → short big-endian
// +0..+1 getUInt16 2 Unsigned → int (0..65535) Big-endian
// +0..+3 getInt32 4 Signed → int Big-endian
// +0..+3 getUInt32 4 Unsigned → long Big-endian
// +0..+3 getFloat 4 IEEE754 → float big-endian
// +0..+7 getInt64 8 Signed → long Big-endian
// +0..+7 getUInt64 8 Unsigned bit-by-bit → long big-endian
// +0..+7 getDouble 8 IEEE754 → double big-endian

Note:

  • Offset + width exceeds the available range in this direction → PnSServiceException, message 区域越界: 偏移 N + 长度 M 超出过程映像区 K 字节.
  • Session not established / Data channel not ready → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect) / 过程数据未就绪, 无法读写 IO.
  • Each time a value is retrieved, it isA single read operation: Two evaluations of the same expressionNot guaranteed to be the same lot. Make sure to capture enough footage in a single take. (read() / getInputs() / readArea / readStruct), if you want both directions, then getIo().
  • Single-pass multibyte value retrieval does not cause fragmentation: the full width is retrieved at once, and then decoded as a whole.
  • isBool() Yes bit0 Semantics: Only when the least significant bit is 1 is it true — 0x01 → true, 0x02 → false, 0x80 → false. It is not "non-zero is true." You must determine true or false based on whether the entire byte is 0 or not 0; read and compare for yourself getContent() .
  • Unsigned values are always rounded up getUInt*: a line value of 0xFFFF is read as 65535 and will not become a negative number.
  • Big-endian decoding is independent JVM of the platform's substitution value byte order.

Example:

var in = device.getProcessData().getIn();
byte raw = in.get(0).getContent();
short sw = in.get(0).getInt16();
int pos = in.get(2).getInt32();
float vel = in.get(6).getFloat();
boolean rdy = in.get(0).getBit(2); // Offset 0 bit2
boolean en = in.get(10).isBool(); // Offset by 10 bit0

Assignment Family (Writing)​

Only the getOut()(Q side) is writable. The value written to it is stored inThe Moment I Wrote ItTake effect; automatically issued in the next cycle.

public void setContent(byte value)               // 1 byte, full-byte overwrite
public void setInt8(byte value)
public void setUInt8(int value) // Take only the lower 8 bits
public void setInt16(short value)
public void setUInt16(int value) // Take only the lower 16 bits
public void setInt32(int value)
public void setUInt32(long value) // Take only the lower 32 bits
public void setInt64(long value)
public void setUInt64(long value)
public void setFloat(float value)
public void setDouble(double value)
public void setBool(boolean value) // Whole Byte: true → 0x01, false → 0x00
public void setBit(int bit, boolean value) // Change only that bit; leave the remaining bits in the same byte unchanged.

Related Structures:

// Write = encode big-endian by width (copy), then write back to the Q area
// Offset (bytes) Method Width Input Type Bit Width Determination / Byte Order
// +0 setContent 1 byte Overwrite the entire byte
// +0 setInt8 1 byte Overwrite the entire byte
// +0 setUInt8 1 int Take only the lower 8 bits
// +0..+1 setInt16 2 short big-endian
// +0..+1 setUInt16 2 int Take only the lower 16 bits, big-endian
// +0..+3 setInt32 4 int big-endian
// +0..+3 setUInt32 4 long Take only the lower 32 bits, big-endian
// +0..+3 setFloat 4 float big-endian, bit types as-is (NaN uncleaned)
// +0..+7 setInt64 8 long big-endian
// +0..+7 setUInt64 8 long big-endian
// +0..+7 setDouble 8 double big-endian, bit types unchanged
// +0 setBool 1 boolean true → 0x01 / false → 0x00(write a full byte)
// +0 setBit(bit, v) 1 int, boolean Read and write: The remaining bits of the same byte retain their original values

Note:

  • For elements of getIn() , write → UnsupportedOperationException, message In 只读 (控制器→设备); 写请用 getOut().get(i).setContent. Zone I is overwritten by the controller every cycle, so writing to it is pointless; therefore, it is rejected outright based on its type.
  • Offset + Width Out of Bounds → PnSServiceException, Message 区域越界: 偏移 N + 长度 M 超出过程映像区 K 字节.
  • Session not established / Data channel not ready → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect) / 过程数据未就绪, 无法读写 IO; If the data channel cannot be obtained during the write phase, an fault is reported 过程数据未就绪, 无法提交 IO.
  • Do not throw a range fault: setUInt8(300) Such excessively large values are written after being moduloed by the bit width; setUInt16(70000) this does not result in an fault or a truncation alarm. If you want to perform range validation, just do it yourself.
  • setBool(boolean) Write the entire byte: true → 0x01, false → 0x00; non-standard bytes are not retained.
  • setBit Bit-level read-and-write: Only that bit is modified; the remaining bits in the same byte retain their original values.
  • There are no additional commit steps for writing—changes take effect immediately upon completion, and when they are pushed out depends on the bus cycle.

Example:

var out = device.getProcessData().getOut();
out.get(6).setFloat(12.5f); // Offset 6..9: write big-endian f32
out.get(0).setInt16((short) 0x000F); // Offset 0..1, big-endian i16
out.get(4).setBit(3, true); // Set only the offset to 4 bit3

getBit(int bit) / setBit(int bit, boolean value)​

public boolean getBit(int bit)                      // , Can be read from both ProcessData.DataItemIn and Out
public void setBit(int bit, boolean value) // ProcessData.DataItem, Out only

Bit-by-bit accessCurrent offset: this one byteOne of the digits in the number. The digit in position 0-7, 0 = the least significant digit.

Return value:

  • getBit → Is this bit a 1 boolean?

Note:

  • bit < 0 || bit > 7 → IllegalArgumentException, News 位索引必须在 0-7 之间: N.
  • Set the In element to → setBit UnsupportedOperationException(the same "read-only" message). Note the order: Check the direction first, then the position number. —— The "In" field setBit(9, true) specifies "read-only," not an out-of-bounds index.
  • setBit Read-modify-write: First, read the byte; then, modify one bit; finally, write the entire byte back. No other bytes are altered in the process.
  • The offset for bit addressing is still a byte offset, so I0.0 is get(0).getBit(0).

Example:

boolean ready = device.getProcessData().getIn().get(0).getBit(0);
device.getProcessData().getOut().get(0).setBit(0, true); // Place only bit0

getValue(PnSDataType type) / setValue(PnSDataType type, Object value)​

public Object getValue(PnSDataType type)                         // ProcessData.DataItem Read
public void setValue(PnSDataType type, Object value) // ProcessData.DataItem Write, Out Only

Enumerates and assigns boxed values by type, saving you the trouble of choosing method names yourself. Equivalent to writing the corresponding getInt16() / / family getFloat() of methods by hand.

Return value:

  • getValue → Object: the boxed value; the concrete type follows type — INTEGER8 maps to Byte, INTEGER16 maps to Short, INTEGER32 maps to Integer, INTEGER64 maps to Long; UNSIGNED8 / UNSIGNED16 (including BYTE / WORD) map to Integer, UNSIGNED32 / UNSIGNED64 (including DWORD / LWORD) map to Long; floating point maps to Float / Double, BOOL maps to Boolean
  • Narrow types do not widen: getValue(INTEGER8 / INTEGER16) yields Byte / Short, casting to (Integer) v throws ClassCastException; when you need Integer, take it via UNSIGNED16 / INTEGER32

Note:

  • type For null → NullPointerException, message type 不能为 null.
  • setValue " " is value null → NullPointerException, message value 不能为 null.
  • PnSDataType 15 possible valuesAll supported: BOOL / INTEGER8·16·32·64 / UNSIGNED8·16·32·64 / REAL32 / REAL64 / BYTE·WORD·DWORD·LWORD. BYTE / WORD / DWORD / LWORD are aliases for UNSIGNED8 / 16 / 32 / 64 (same width, same big-endian).
  • setValue(BOOL, ...) Accepts Boolean, and also accepts any value Number(non-0 means true). For other types, it passes a value Number of false. → ClassCastException; passing to BOOL a value that is neither Boolean nor Number → IllegalArgumentException, Message 无法转为布尔: java.lang.String This shape.
  • Convert the value first, then decide the direction: when you call setValue on an In element and the value itself is illegal, what is thrown is a conversion exception, not a read-only exception. The turn comes only if the value is valid UnsupportedOperationException(for the same read-only message).
  • The values undergo Java's downcasting: setValue(INTEGER8, 300) When written this way 44, no fault is reported. You're responsible for managing the range yourself.
  • Width / out-of-bounds / session-class failures are exactly the same as the assignment family (those few rules: 区域越界, 会话未建立, 过程数据未就绪).

Example:

import com.darra.pns.enums.PnSDataType;

var in = device.getProcessData().getIn();
var out = device.getProcessData().getOut();

Object v = in.get(2).getValue(PnSDataType.UNSIGNED16); // Boxed Integer
out.get(2).setValue(PnSDataType.WORD, 123); // WORD That is UNSIGNED16
out.get(4).setValue(PnSDataType.REAL32, 12.5f);

Related Structures:

public enum PnSDataType {
BOOL, // Boolean:bit0 Semantics — 0 = false, 1 = true (1 byte)
INTEGER8, // Signed 8-bit integer (1 byte)
INTEGER16, // Signed 16-bit integer (2 bytes, big-endian)
INTEGER32, // Signed 32-bit integer (4 bytes, big-endian)
INTEGER64, // Signed 64-bit integer (8 bytes, big-endian)
UNSIGNED8, // Unsigned 8-bit integer (1 byte)
UNSIGNED16, // Unsigned 16-bit integer (2 bytes, big-endian)
UNSIGNED32, // Unsigned 32-bit integer (4 bytes, big-endian)
UNSIGNED64, // Unsigned 64-bit integer (8 bytes, big-endian)
REAL32, // IEEE754 Single-resolution floating-point (4 bytes, big-endian)
REAL64, // IEEE754 Double-resolution floating-point (8 bytes, big-endian)
BYTE, // Byte,UNSIGNED8 also known as (1 byte)
WORD, // Word, UNSIGNED16 Alias (2 bytes, big-endian)
DWORD, // Double word, UNSIGNED32 alias (4 bytes, big-endian)
LWORD // Long word, UNSIGNED64 alias (8 bytes, big-endian)
}

The Cost of Elemental Channels and Forms of Failure​

Every time you retrieve a value from an element buffer, you have to read the entire data set again and then extract the specific bytes you need; the overhead per operation is greater than that of reading the entire segment.

So it's suitable for making changes to a single field or a small number of fields, Not suitable for placement in the 1 ms cyclic heat path. For full-frame / batch / periodic heat paths, please use Structure Mapping or read().

The three types of exceptions are deliberately reported separately to make it easier to determine whether the issue is caused by an incorrect offset, an incorrect direction, or the ST not being ready:

  • Negative offset (get(i) / DataArray.set) → ; IndexOutOfBoundsException
  • Offset + width exceeds the available range in this direction → PnSServiceException(message with 区域越界);
  • Write to the read side → UnsupportedOperationException(the element port behaves the same svc.getIn(offset) way as );
  • Session not ready → PnSServiceException(会话未建立 / 过程数据未就绪).

Thread safety: The element port itself does not use locks. Do not use multiple threads to concurrently read and write process data for the same service object., If you need concurrency, implement your own locking mechanism, or use the entire mapping along with your own scheduling.

The port with the same name on the service side​

PnSService There is also a set of methods for retrieving elements based on offsets, which returnThe same one ProcessData.DataItem(Same implementation), differing only in the exception types for negative offsets:

public ProcessData.DataItem getIn(int offset)    // PnSService: Read-Only I
public ProcessData.DataItem getOut(int offset) // PnSService: Write Q

Return value:

  • ProcessData.DataItem — Element view, which also does not hold any data bytes

Note:

  • offset < 0 → PnSServiceException, Message 偏移不能为负: N(Note the pd.getIn().get(i) difference between and IndexOutOfBoundsException (Different).
  • The remaining specifications are DataItem exactly the same as : write to read-only side → UnsupportedOperationException; bit out of bounds → IllegalArgumentException, message 位索引必须在 0-7 之间: N; the scalar method name is also getContent / setContent / getInt8 … getDouble / isBool / getBit / setBit / getValue / setValue.

Example:

short recipe = device.getIn(2).getInt16();
device.getOut(2).setInt16((short) 123);

Entire Region and Entire Frame (Copy)​

You can read and write entire segments even without creating a mapping. The following are allCopy, not a view.

read() / getInputs()​

public byte[] read()      // PnSService: I Entire paragraph
public byte[] getInputs() // ProcessData: I Entire shielding (same as read())

Read the entire Section I in one go; it should be self-consistent within a single beat. This is the standard approach for "getting a snapshot that doesn't change."

Return value:

  • byte[] — I A complete copy of the data, length = getIn().getLength(); returns an array of length 0 if the data is empty, Does not return null

Note:

  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • Data channel not ready → PnSServiceException, message 过程数据未就绪, 无法读写 IO.
  • He received a copy, so whatever changes are made to the data afterward have nothing to do with him.
  • A single call retrieves both Q and I at the same time, even if you only need I (in which case that call is getIo()). Don't put it in the hot path and keep adjusting it.
  • Use this to crop by offset readArea, To use a fixed-length prefix starting at offset 0, use readStruct.

Example:

byte[] i = device.read();
System.out.println("I 区 " + i.length + " 字节");

getIo()​

public byte[][] getIo()   // PnSService: Retrieve Q + I in a single operation

Retrieve all in a single callTwo DirectionsCopy of: [0] Q is the shadow (device → controller), [1] and I is the original (controller → device). Use this when you want to view I and Q in pairs, so you don't have to adjust each direction separately.

Return value:

  • byte[][] — [0] = Q shadow; [1] = I. When the data is empty, it is an array of length 0, Does not return null

Note:

  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • Data channel not ready → PnSServiceException, message 过程数据未就绪, 无法读写 IO.
  • Both of them areCopy: Once you have the data, it doesn't matter how it changes. To maintain a view of it, use getInputsMapping / getOutputsMapping.
  • Q Which one is that? Shadow: Reads the current value of Q; the unit is the same as getOutputs() Consistent.
  • read() uses exactly this underneath — just call read() / getInputs() directly.

Example:

byte[][] io = device.getIo();
byte[] q = io[0]; // Q Shadow (Device → Controller)
byte[] i = io[1]; // I (Controller → Device)

getOutputs()​

public byte[] getOutputs()   // ProcessData: Q Shadow

Take a portion of District QShadowReplica (Device → Controller). For write operations, please use copyToOutputs Or write the entire zone.

Return value:

  • byte[] — Q: A copy of the data; returns an array of length 0 if the data is empty

Note:

  • Session not established / Data channel not ready → PnSServiceException(Same as message read()).
  • It isShadow: The value read back is the current value of Q; it does not precede the write. The value left over from the previous failed write will not appear in it. In that situation, to determine whether "delivery actually took place," check getIoStatus().isOutputValid() to see if it did false—don't just guess based on the reading.
  • Modify this arrayNoWrite it back to sector Q—it's just a copy.

Example:

byte[] q = device.getProcessData().getOutputs();
System.out.println("Q 区 " + q.length + " 字节,第 0 字节 = " + (q[0] & 0xFF));

write(byte[] data)​

public void write(byte[] data)   // PnSService: Write Q starting at offset 0

Partial overwrite starting at offset 0 in Q zone, Abbreviations allowed. Normal response ⟺ The write has taken effect and will be automatically sent in the next cycle.

Return value:

  • None (void)

Note:

  • data For null or length 0 → PnSServiceException, message 写数据不能为空.
  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • Data length exceeds the writable range of Q → PnSServiceException, message 区域越界: 偏移 0 + 长度 M 超出过程映像区 K 字节.
  • Only the first data.length bytes are overwritten; the remaining bytes retain their original values — this is not a full-frame replacement.
  • Write failed (channel not ready) → PnSServiceException, message ; 过程数据未就绪, 无法提交 IO the next write will be retried, getIoStatus().isOutputValid() For false(not to be construed as having been served).

Example:

device.write(new byte[] { 0x01, 0x00 });     // 2 bytes starting at offset 0

readArea(PnSServiceArea area) / readArea(PnSServiceArea area, int offset, int length)​

public byte[] readArea(PnSServiceArea area)                                  // PnSService
public byte[] readArea(PnSServiceArea area, int offset, int length) // PnSService

Read the entire paragraph or a single paragraph by section. Both I and Q can be read.

Return value:

  • byte[] — Full-page or cropped copies

Note:

  • area Not INPUT / OUTPUT(for example UNKNOWN / MEMORY / DB) → PnSServiceException, News 区域非法: MEMORY This shape.
  • offset < 0 or length < 0 → PnSServiceException, message offset / length 不能为负.
  • offset + length Outside this area → PnSServiceException, message 区域越界: 偏移 N + 长度 M 超出过程映像区 K 字节.
  • Session not established / Data channel not ready → PnSServiceException(Same as message read()).
  • This isCopy: It works even without creating a mapping, and the values you retrieve do not change accordingly.
  • Offsets are not required to be aligned; readArea(INPUT, 3, 2) this is valid.

Example:

import com.darra.pns.service.PnSService.PnSServiceArea;

byte[] all = device.readArea(PnSServiceArea.INPUT); // I Entire Paragraph
byte[] part = device.readArea(PnSServiceArea.INPUT, 4, 2); // Offset 4, starting at 2 bytes

Related Structures:

// Declaration PnSService within (com.darra.pns.service.PnSService.PnSServiceArea)
public class PnSService {
public enum PnSServiceArea {
UNKNOWN, // Unknown
INPUT, // Zone I: Read-only (Controller → Device)
OUTPUT, // Section Q: Write only (device → controller)
MEMORY, // Zone M: Used only for "not supported" reports (resolution failed, no mapping)
DB // DB Zone: Used only for "not supported" reports (resolution failed, no mapping)
}
}

Of all the regional parameters for the read/write port, the only ones that can actually be used are INPUT and OUTPUT. MEMORY / DB is simply included to provide a concrete value for the "not supported" ST in address resolution; when passed to the read/write port, it always takes the form 区域非法: MEMORY of .

writeArea(PnSServiceArea area, byte[] data) / writeArea(PnSServiceArea area, int offset, byte[] data)​

public void writeArea(PnSServiceArea area, byte[] data)                        // PnSService
public void writeArea(PnSServiceArea area, int offset, byte[] data) // PnSService

Write with partial coverage based on regional offsets. Effective immediately, no delay, no beat.

Return value:

  • None (void). Normal return ⟺ The write has taken effect.

Note:

  • Write INPUT → PnSServiceException, message I 区 (控制器 -> 设备) 只读, 不支持写.
  • area Not OUTPUT → PnSServiceException, message 区域非法: N.
  • data If null or empty → PnSServiceException, message 写数据不能为空.
  • offset < 0 → PnSServiceException, News offset 不能为负.
  • Out of bounds → PnSServiceException, message 区域越界: 偏移 N + 长度 M 超出过程映像区 K 字节.
  • Write failed → PnSServiceException, message 过程数据未就绪, 无法提交 IO; will retry on the next write.
  • Write one at a timeA continuous segmentBytes. Non-adjacent changes are processed in two passes, with one write operation per pass.

Example:

device.writeArea(PnSServiceArea.OUTPUT, 4, new byte[] { 0x11 });   // Offset 4, write 1 byte
device.writeArea(PnSServiceArea.OUTPUT, new byte[] { 0x0F, 0x00 }); // 2 bytes starting at offset 0

copyInputsTo(byte[] destination) / copyToOutputs(byte[] source)​

public int copyInputsTo(byte[] destination)   // ProcessData: I → Caller's buffer
public int copyToOutputs(byte[] source) // ProcessData: Caller buffer → Q

A pair of copy ports: one copies I into your buffer, and the other writes your buffer to Q. Both support short copies.

Return value:

  • copyInputsTo → int, Actual number of bytes copied = ; min(I 长度, destination.length) 0 when the data is empty
  • copyToOutputs → int, number of bytes written = ; source.length 0 if the array is empty

Note:

  • destination / source For null → NullPointerException, Message destination 不能为 null / source 不能为 null.
  • Empty arrayIt's not a mistake: copyInputsTo Returns 0; copyToOutputs returns 0 and does not write anything.
  • Data exceeds the destination's length: copyInputsTo Truncate to the shorter length (short copy, returns normally); copyToOutputs write to the entire region, Exceeds the writable range of Q → PnSServiceException, message 区域越界: ....
  • Session not established / Data channel not ready → PnSServiceException(Same message as read() / write()).
  • When repeatedly adjusting the fixed buffer, be sure to check the return value: the number of bytes returned is the actual amount transferred during that operation.

Example:

byte[] buf = new byte[16];
int n = device.getProcessData().copyInputsTo(buf); // The first n bytes
System.out.println("拷到 " + n + " 字节");

byte[] out = new byte[] { 0x0F, 0x00, 0x00 };
int sent = device.getProcessData().copyToOutputs(out); // Write Q starting at offset 0

setByte(int offset, int value)​

public void setByte(int offset, int value)   // PnSService: Write a single byte in the Q zone

out(offset).setContent(v) A convenient writing position, all at the same spot.

Return value:

  • None (void)

Note:

  • Only the lower 8 bits value of are valid; the upper 24 bits are discarded (256 which has the same effect 0 as ).
  • offset < 0 → PnSServiceException, News offset 不能为负.
  • Out of Bounds / link Failed / Submission Failed → PnSServiceException, same message as writeArea.
  • Do not write "I" in Zone I: There is no zone parameter here; only "Q" is written.

Example:

device.setByte(0, 0x0F);

Read/Write by Address (Region + Byte + Bit)​

Use this group when you don't want to calculate the offset yourself and want to write the address exactly as it appears in the engineering software: Region Letter + Byte Offset + Bit.

parseAddress(String address)​

public static Address parseAddress(String address)   // PnSService

Parse an address string into a structured address. The same parsing method is used for the six read/write ports mentioned above.

Return value:

  • Address — Includes getArea() / getSlot() / getSubslot() / getByteOffset() / getBit()(-1 = non-bit addressing) / getLength()

Related Structures:

public static final class Address {
public PnSServiceArea getArea() { } // INPUT (I) / OUTPUT (Q)
public int getSlot() { } // Pinned 1
public int getSubslot() { } // Pinned 1
public int getByteOffset() { } // Byte offset in the data area (not a bit offset)
public int getBit() { } // 0–7 = bit addressing; –1 = non-bit addressing
public int getLength() { } // Address = 1;IB/QB = 1;IW/QW = 2;ID/QD = 4
}

Note:

  • Parsing does not check boundaries: it only looks at the format. Whether the offset is out of bounds is compared against the length only at the moment of the actual read or write.
  • Digit values must be between 0 and 7; I0.8 this is simply a formatting fault, not an out-of-range fault.
  • No mandatory 2/4 alignment: IW3 Both are valid; ID2 the offset refers to a byte offset.
  • getSlot() / getSubslot() Hengwei 1 (fixed single module); there are no parameters that can change this value.

Example:

var a = PnSService.parseAddress("IW2");
System.out.println(a.getArea() + " 偏移 " + a.getByteOffset() + " 长度 " + a.getLength());

readBool(String address) / writeBool(String address, boolean value)​

public boolean readBool(String address)                    // PnSService
public void writeBool(String address, boolean value) // PnSService

Read or write a single bit using a bit-address. The address takes the form I0.0 / Q0.0.

Return value:

  • readBool → Is this bit a 1 boolean?

Note:

  • Failed to parse the address string → PnSServiceException.
  • Addresses are in byte / word / double word form (without bit numbers) → PnSServiceException, message 位地址必须带位号: IB0.
  • Address out of bounds → PnSServiceException, message 地址越界: 偏移 N + 长度 1 超出过程映像区 K 字节.
  • writeBool YesRead and Rewrite: First, read the byte back, change only that bit, and then write the entire byte back—the other bits in the same byte will not be affected.
  • writeBool("I0.0", ...) → PnSServiceException, News I 区 (控制器 -> 设备) 只读, 不支持写.
  • readBool("Q0.0") Valid: Readable in Q (the shadow value you wrote down).

Example:

boolean done = device.readBool("I0.0");
device.writeBool("Q0.0", true);

readInt16(String address) / writeInt16(String address, short value)​

public short readInt16(String address)                  // PnSService
public void writeInt16(String address, short value) // PnSService

Read and write 2 bytes at a word address, big-endian.

Return value:

  • readInt16 → short

Note:

  • The address is not in 2-byte form (e.g. IB2 / I0.0) → PnSServiceException, message 字地址必须为 2 字节且非位寻址: IB2.
  • Write I side → PnSServiceException, message I 区 (控制器 -> 设备) 只读, 不支持写.
  • Out of bounds → PnSServiceException, message 地址越界: 偏移 N + 长度 2 超出过程映像区 K 字节.
  • Big-endian decoding matches the element port, so the same value is read from both locations at the same address.
  • For unsigned values, use the element port getUInt16()(this port returns short, 0xFFFF which reads as -1).

Example:

short recipe = device.readInt16("IW2");
device.writeInt16("QW2", (short) 123);

readInt32(String address) / writeInt32(String address, int value)​

public int  readInt32(String address)                // PnSService
public void writeInt32(String address, int value) // PnSService

Read or write 4 bytes using a double word address, big-endian.

Return value:

  • readInt32 → int

Note:

  • The address is not in 4-byte form → PnSServiceException, message 双字地址必须为 4 字节且非位寻址: IW2.
  • Write I side → PnSServiceException, message I 区 (控制器 -> 设备) 只读, 不支持写.
  • Out of bounds → PnSServiceException, message 地址越界: 偏移 N + 长度 4 超出过程映像区 K 字节.
  • Unsigned requirements use the element port getUInt32()(return long).

Example:

int counter = device.readInt32("ID4");
device.writeInt32("QD4", 10000);

Address Formatting and Common Mistakes​

How to Write an AddressWhat is it?
I0.0 / Q0.0Bit address: Bit 0 of byte 0 (bit numbers must be between 0 and 7)
IB0 / QB0Byte (Whether or not a regional character follows, it is still B a byte andI0 is equivalent IB0 to )
IW2 / QW2Word (2 bytes)
ID4 / QD4Double word (4 bytes)
  • Do not enforce 2/4 alignment: IW3 / ID2 Both are valid; "offset" refers to a byte offset.
  • Does not support the M zone / DB zone, sell as is.
  • Regional CharactersCase-insensitive: i0.0 Same I0.0 as .
  • The type letter must be capitalized: iw2 is not a word address; it will be parsed as a pure number, reporting 字节偏移非法: iw2.
  • Upper offset limit 0xFFFF; report if exceeded 字节偏移超出范围.

array of all failed operations (the string in parentheses after PnSServiceException is the "detail" part of the message):

NewsWhen?
地址不能为空Passed null / Empty string / All spaces
不支持 DB 地址: DB1.DBX0.0starts with DB / db
不支持的地址区域: X0.0The initials are neither "I" and "Q" nor "M" and "DB."
不支持 M 地址: M0.0The first letter is M
地址缺少偏移量: IWOnly the region code and type code remain
地址格式非法 (位地址应为 I0.0 形式): I.0There are some dots, but they're placed at the beginning or end.
位号必须在 0-7 之间: I0.8Index out of bounds
字节偏移非法: IX0 / 位号非法: I0.xPunctuation / Type: The character following the letter is not a number
字节偏移超出范围: I70000Offset greater than 0xFFFF
位地址必须带位号: IB0Addressing non-bit addresses / readBool writeBool
字地址必须为 2 字节且非位寻址: IB2Calling readInt16 / writeInt16 on a non-word address
双字地址必须为 4 字节且非位寻址: IW2Access to non-double-word addresses readInt32 / writeInt32
地址越界: 偏移 N + 长度 M 超出过程映像区 K 字节Offset + width exceeds the available range in that direction
I 区 (控制器 -> 设备) 只读, 不支持写Go I / IB / IW / ID / I0.0 Write
不支持 M/DB 地址The region is assigned to M/DB (the address port has already been blocked upstream; this is a fallback).
PnSServiceException Messages with prefixes

PnSServiceException getMessage() take 未知错误 (<detail>) this form: PnSErr.UNKNOWN Chinese name + the details in parentheses. The error code can be taken with getCode() (PnSErr), and the raw server code with getServerErrorCode(). The table above lists only the portion in parentheses.

Length, Subscripts, and Record Index Space​

How do I measure the length?​

The length is determined by the available data length at runtime (I actual length GET /api/io = outputLength, Q actual length = inputLength; the field names are opposite to the I/Q directions—do not use the names as references). The length is determined by the value negotiated by the PLC (IO controller) and is automatically matched after link, Don't be too rigid 20 / 32, and do not extrapolate based on district capacity.

What you wantWhere to get it
I Data Lengthdevice.read().length / getProcessData().getInputs().length / pd.getIn().getLength()
Q Data LengthgetProcessData().getOutputs().length / pd.getOut().getLength()
Available data length in both directionsThere is no separate query entry: the length returned by readArea() / getIo() is the data length. getDiagSnapshot().getInputAreaLength() / .getOutputAreaLength() are the zone capacities, not the data length, and do not act as the write boundary

For read/write and mapping operations, always use the return value (readArea() / getIo() / getLength()) as the data length. Do not confuse the shielding capacity with the data length; they are not the same value. If you need the number of bytes for a structure, use the return length.

Retrieving Elements by Subscript: A Comparison of Four Methods​

There are four ways to perform the same operation (reading or writing a value using an offset) in Java; the implementation is identical, with the only differences being the exception types and names:

entry pointReadWriteNegative offsetWrite to the read-only sideIndex out of boundsYes getValue
pd.getIn().get(i) / pd.getOut().get(i)YesYes (out only)IndexOutOfBoundsExceptionUnsupportedOperationExceptionIllegalArgumentExceptionYes
svc.getIn(offset) / svc.getOut(offset)YesYes (out only)PnSServiceExceptionUnsupportedOperationExceptionIllegalArgumentExceptionYes
pd.getOut().set(i, b)——Yes (out only)IndexOutOfBoundsExceptionUnsupportedOperationException————
svc.setByte(i, v)——YesPnSServiceException——————

Either one is fine, Don't mix and match the same offset: Both sides are calculating the same data offset; mixing them won't cause an fault, but it will just confuse you.

Two Record Index Spaces​

In addition to periodic I/Q exchanges, there are also non-periodic record reads and writes. The offsets for user-space records and I&M are separate; they use different entry points, so do not mix them:

Index SpaceScopeWhich entry point should I use?Low-level endpoints
User Area Records0x0000–0x7FFFdevice.getRecords()GET /api/records
I&M (Identification and Maintenance)0xAFF0–0xAFF4device.getImData()GET /api/im
Don't mix

getRecords() the two spaces. Covers only the user area, those I&M indexesNot inside it — I&M cannot API be retrieved from the records. I&M goes through getImData() (ImData: manufacturer ID / device identity / order number / serial number / hardware version / software version / station name / product name, as well as the engineering ID field in I&M1–4).

The same applies in reverse: getImData() records are provided only to I&M, not to the user zone.

public UserRecords getRecords()   // PnSService: User Area Record Table
public ImData getImData() // PnSService: I&M Observation Data

Return value:

  • getRecords() → UserRecords: getRecords() (UserRecord[], each line has getSlot() / getSubslot() / getIndex() / getLength() / getDataHex()), getCount(), getTimestamp()
  • getImData() → ImData: See above

Note:

  • Session not established → PnSServiceException, message 会话未建立 (请先 start() 或 WebAPI connect).
  • Service Unreachable / Invalid Response → Report it as is PnSServiceException; do not fabricate a "No record" message.
  • No record ≠ failure: An empty table is just an empty table—getCount() it's 0.
  • Missing fields are returned with their default values (empty string / 0 / false), not fabricated.
  • These two are acyclic data channels; they are distinct from process data and do not consume bus cycle time.

Example:

for (var r : device.getRecords().getRecords()) {
System.out.printf("槽 %d 索引 0x%04X 长度 %d%n", r.getSlot(), r.getIndex(), r.getLength());
}
String orderId = device.getImData().getOrderId();