0

Using Calimero, I want to read and write signed int values in a KNX system.

I use the readUnsigned and write methods of ProcessCommunicatorImpl for unsigned ints but there are no methods for reading and writing signed ints.

For example these types I can not access:
DataPoint 6.x (8 bit 2's complement)
DataPoint 8.x (16 bit 2's complement)
DataPoint 13.x (32 bit 2's complement)

The only methods available are:
String read(Datapoint)
String readString(GroupAddress)
int readControl(GroupAddress)
double readFloat(GroupAddress, boolean)
int readUnsigned(GroupAddress, String)
bool readBool(GroupAddress)

And I only have a GroupAddress, no Datapoint.


Does anyone know how I can read and write those types of datapoints?

Thanks!

Johan Claes
  • 139
  • 2
  • 14
  • Just a guess but maybe it's `double readNumeric(..)` since a double can represent all ints without precision loss – zapl Jun 01 '18 at 22:36
  • I added the available methods to my question. I have no idea where I can find a readNumeric method. – Johan Claes Jun 01 '18 at 22:50
  • 1
    Ah, seems to be a very recent addition to their github which isn't in your version of the library yet. After browsing some more I think you can create your own StateDp (datapoint) instance using your address then read and write as string, e.g. https://github.com/calimero-project/calimero-core/blob/master/test/tuwien/auto/calimero/process/ProcessCommunicatorTest.java#L451 there is a DPTXlator for signed types – zapl Jun 01 '18 at 23:03
  • Thank you zapl, I got it solved thanks to you! – Johan Claes Jun 02 '18 at 12:09

1 Answers1

0

Using zapl's comment as inspiration, I came up with this code:

int getIntFrom8Bit2Complement(GroupAddress groupAddress) throws KNXException, InterruptedException {

    final Datapoint dp = new StateDP(groupAddress, "my datapoint "+groupAddress.toString());
    dp.setDPT(0, DPTXlator8BitSigned.DPT_VALUE_1_UCOUNT.getID());
    String result = processCommunicator.read(dp);
    try {
        return Integer.parseInt(result);
    } catch (NumberFormatException e) {
        throw new KNXException("Error Parsing 8 bit 2 complement result as int -- result = "+result);
    }
}

I'm not 100% sure about parsing the result as an int, but I can't test because I don't have a KNX device that will send me a signed int.
When I get the chance to test one, I will confirm or adjust this answer.

Johan Claes
  • 139
  • 2
  • 14