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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations