Use Calimero for Java to read and write signed int values of KNX system

486 views Asked by At

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!

1

There are 1 answers

0
Johan Claes On BEST ANSWER

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.