Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Potentiometer and analogue channels (http://www.chiefdelphi.com/forums/showthread.php?t=103307)

joelg236 19-02-2012 18:09

Potentiometer and analogue channels
 
Hey guys, our code returns a NullPointerException because it was already allocated to that channel, but we are 100% sure that it was not. We have code specifically designed to prevent this here:

Code:

if(potentiometerOn) {
            if(potentiometer instanceof AnalogChannel) {
                potentiometerEnabled = true;
            }else {
                potentiometerEnabled = false;
                potentiometer = new AnalogChannel(potentiometerChannel);
                if(potentiometer instanceof AnalogChannel) {
                    potentiometerEnabled = true;
                }
            }
        }

Is it that the variable potentiometer is not registered as an instance of AnalogueChannel (A weird class or something?) Maybe if we used potentiometerEnabled as our qualifier to create the new instance it would work? We are a bit confused at this.

sjspry 20-02-2012 10:58

Re: Potentiometer and analogue channels
 
If the code says it was enabled somewhere, it was enabled somewhere (I think the channel used to read the battery voltage is exposed on the header pins - you might be trying to use it).

However, since that exception throwing is mostly to keep you from mixing up what you are using channels for (if, for example, you happen to double-allocate a channel), you can bypass it and get the reading for that channel number with:

Code:

AnalogModule.getInstance(slot).getVoltage(chan);
Optionally storing the instance of the AnalogModule in your own variable.

joelg236 20-02-2012 11:32

Re: Potentiometer and analogue channels
 
Yeah I ended up removing all potentiometer code and starting from scratch on it. Havn't tested yet but it should work. Otherwise, I'll just set up a singleton like you said. Thanks :)


All times are GMT -5. The time now is 09:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi