Search in sources :

Example 81 with PlcRuntimeException

use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.

the class PlcStruct method serialize.

@Override
public void serialize(WriteBuffer writeBuffer) throws SerializationException {
    writeBuffer.pushContext("PlcStruct");
    for (Map.Entry<String, PlcValue> entry : map.entrySet()) {
        String fieldName = entry.getKey();
        writeBuffer.pushContext(fieldName);
        PlcValue fieldValue = entry.getValue();
        if (!(fieldValue instanceof Serializable)) {
            throw new PlcRuntimeException("Error serializing. List item doesn't implement XmlSerializable");
        }
        ((Serializable) fieldValue).serialize(writeBuffer);
        writeBuffer.pushContext(fieldName);
    }
    writeBuffer.popContext("PlcStruct");
}
Also used : PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException) PlcValue(org.apache.plc4x.java.api.value.PlcValue) Serializable(org.apache.plc4x.java.spi.utils.Serializable) Map(java.util.Map)

Example 82 with PlcRuntimeException

use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.

the class ReadBufferJsonBased method readLong.

@Override
public long readLong(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
    logicalName = sanitizeLogicalName(logicalName);
    move(bitLength);
    Map element = getElement(logicalName);
    validateAttr(logicalName, element, rwIntKey, bitLength);
    Integer value = (Integer) element.get(logicalName);
    if (value == null) {
        throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
    }
    return Long.valueOf(value);
}
Also used : BigInteger(java.math.BigInteger) PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException)

Example 83 with PlcRuntimeException

use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.

the class ReadBufferJsonBased method readUnsignedShort.

@Override
public short readUnsignedShort(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
    logicalName = sanitizeLogicalName(logicalName);
    move(bitLength);
    Map element = getElement(logicalName);
    validateAttr(logicalName, element, rwUintKey, bitLength);
    Integer value = (Integer) element.get(logicalName);
    if (value == null) {
        throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
    }
    return value.shortValue();
}
Also used : BigInteger(java.math.BigInteger) PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException)

Example 84 with PlcRuntimeException

use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.

the class ReadBufferJsonBased method readBigInteger.

@Override
public BigInteger readBigInteger(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
    logicalName = sanitizeLogicalName(logicalName);
    move(bitLength);
    Map element = getElement(logicalName);
    validateAttr(logicalName, element, rwIntKey, bitLength);
    Integer value = (Integer) element.get(logicalName);
    if (value == null) {
        throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
    }
    return BigInteger.valueOf(value);
}
Also used : BigInteger(java.math.BigInteger) PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException)

Example 85 with PlcRuntimeException

use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.

the class ReadBufferJsonBased method readUnsignedByte.

@Override
public byte readUnsignedByte(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
    logicalName = sanitizeLogicalName(logicalName);
    move(bitLength);
    Map element = getElement(logicalName);
    validateAttr(logicalName, element, rwUintKey, bitLength);
    Integer value = (Integer) element.get(logicalName);
    if (value == null) {
        throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
    }
    return value.byteValue();
}
Also used : BigInteger(java.math.BigInteger) PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException)

Aggregations

PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)95 BigInteger (java.math.BigInteger)17 CompletableFuture (java.util.concurrent.CompletableFuture)14 PlcResponseCode (org.apache.plc4x.java.api.types.PlcResponseCode)14 PlcValue (org.apache.plc4x.java.api.value.PlcValue)14 ResponseItem (org.apache.plc4x.java.spi.messages.utils.ResponseItem)14 Duration (java.time.Duration)13 PlcField (org.apache.plc4x.java.api.model.PlcField)13 PlcConnectionException (org.apache.plc4x.java.api.exceptions.PlcConnectionException)10 HasConfiguration (org.apache.plc4x.java.spi.configuration.HasConfiguration)10 ParseException (org.apache.plc4x.java.spi.generation.ParseException)10 RequestTransactionManager (org.apache.plc4x.java.spi.transaction.RequestTransactionManager)10 Collections (java.util.Collections)9 DefaultPlcReadRequest (org.apache.plc4x.java.spi.messages.DefaultPlcReadRequest)9 DefaultPlcWriteRequest (org.apache.plc4x.java.spi.messages.DefaultPlcWriteRequest)9 IOException (java.io.IOException)8 org.apache.plc4x.java.modbus.readwrite (org.apache.plc4x.java.modbus.readwrite)8 DefaultPlcReadResponse (org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse)8 ModbusField (org.apache.plc4x.java.modbus.base.field.ModbusField)7 PlcList (org.apache.plc4x.java.spi.values.PlcList)7