Search in sources :

Example 1 with PlcList

use of org.apache.plc4x.java.spi.values.PlcList in project plc4x by apache.

the class FirmataProtocolLogic method sendUpdateEvents.

protected void sendUpdateEvents(Consumer<PlcSubscriptionEvent> consumer, String fieldName, List<PlcValue> values) {
    // If it's just one element, return this as a direct PlcValue
    if (values.size() == 1) {
        final PlcSubscriptionEvent event = new DefaultPlcSubscriptionEvent(Instant.now(), Collections.singletonMap(fieldName, new ResponseItem<>(PlcResponseCode.OK, values.get(0))));
        consumer.accept(event);
    } else // If it's more, return a PlcList instead.
    {
        final PlcSubscriptionEvent event = new DefaultPlcSubscriptionEvent(Instant.now(), Collections.singletonMap(fieldName, new ResponseItem<>(PlcResponseCode.OK, new PlcList(values))));
        consumer.accept(event);
    }
}
Also used : PlcList(org.apache.plc4x.java.spi.values.PlcList) ResponseItem(org.apache.plc4x.java.spi.messages.utils.ResponseItem)

Example 2 with PlcList

use of org.apache.plc4x.java.spi.values.PlcList in project plc4x by apache.

the class ModbusEncodeTest method testEncodeFloatREAL.

@Test
public void testEncodeFloatREAL() {
    Float[] object = { 1.1f, 1000.1f, 100000.1f, 3.4028232E38f, -3.4028232E38f, -1f, 10384759934840.0f };
    ModbusFieldHoldingRegister holdingregister = ModbusFieldHoldingRegister.of("holding-register:7:REAL");
    PlcList list = (PlcList) IEC61131ValueHandler.of(holdingregister, object);
    Assertions.assertEquals("[1.1,1000.1,100000.1,3.4028233E38,-3.4028233E38,-1.0,1.03847601E13]", list.toString());
}
Also used : PlcList(org.apache.plc4x.java.spi.values.PlcList) ModbusFieldHoldingRegister(org.apache.plc4x.java.modbus.field.ModbusFieldHoldingRegister) Test(org.junit.jupiter.api.Test)

Example 3 with PlcList

use of org.apache.plc4x.java.spi.values.PlcList in project plc4x by apache.

the class ModbusEncodeTest method testEncodeIntegerINT.

@Test
public void testEncodeIntegerINT() {
    Integer[] object = { 1, -1, 32000, -32000, 5, 6, 7 };
    ModbusFieldHoldingRegister holdingregister = ModbusFieldHoldingRegister.of("holding-register:7:INT");
    PlcList list = (PlcList) IEC61131ValueHandler.of(holdingregister, object);
    Assertions.assertEquals("[1,-1,32000,-32000,5,6,7]", list.toString());
}
Also used : BigInteger(java.math.BigInteger) PlcList(org.apache.plc4x.java.spi.values.PlcList) ModbusFieldHoldingRegister(org.apache.plc4x.java.modbus.field.ModbusFieldHoldingRegister) Test(org.junit.jupiter.api.Test)

Example 4 with PlcList

use of org.apache.plc4x.java.spi.values.PlcList in project plc4x by apache.

the class ModbusEncodeTest method testEncodeBooleanBOOL.

@Test
public void testEncodeBooleanBOOL() {
    Boolean[] object = { true, false, true, false, true, false, true, true, false };
    ModbusFieldCoil coils = ModbusFieldCoil.of("coil:8:BOOL");
    PlcList list = (PlcList) IEC61131ValueHandler.of(coils, object);
    Assertions.assertEquals("[true,false,true,false,true,false,true,true,false]", list.toString());
}
Also used : PlcList(org.apache.plc4x.java.spi.values.PlcList) ModbusFieldCoil(org.apache.plc4x.java.modbus.field.ModbusFieldCoil) Test(org.junit.jupiter.api.Test)

Example 5 with PlcList

use of org.apache.plc4x.java.spi.values.PlcList in project plc4x by apache.

the class ModbusEncodeTest method testEncodeIntegerSINT.

@Test
public void testEncodeIntegerSINT() {
    Integer[] object = { 1, -1, 127, -128, 5, 6, 7, 8 };
    ModbusFieldHoldingRegister holdingregister = ModbusFieldHoldingRegister.of("holding-register:8:SINT");
    PlcList list = (PlcList) IEC61131ValueHandler.of(holdingregister, object);
    Assertions.assertEquals("[1,-1,127,-128,5,6,7,8]", list.toString());
}
Also used : BigInteger(java.math.BigInteger) PlcList(org.apache.plc4x.java.spi.values.PlcList) ModbusFieldHoldingRegister(org.apache.plc4x.java.modbus.field.ModbusFieldHoldingRegister) Test(org.junit.jupiter.api.Test)

Aggregations

PlcList (org.apache.plc4x.java.spi.values.PlcList)37 PlcValue (org.apache.plc4x.java.api.value.PlcValue)18 Test (org.junit.jupiter.api.Test)15 ModbusFieldHoldingRegister (org.apache.plc4x.java.modbus.field.ModbusFieldHoldingRegister)14 BigInteger (java.math.BigInteger)13 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)3 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ResponseItem (org.apache.plc4x.java.spi.messages.utils.ResponseItem)2 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LocalTime (java.time.LocalTime)1 BitSet (java.util.BitSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)1 PlcConnection (org.apache.plc4x.java.api.PlcConnection)1