Jump to content

MATLAB Callback Error


Jon
 Share

Recommended Posts

Hi,

I'm trying to run "matlab_example_callback.m" for BrickletVoltageCurrent.

 

When the example code "set(vc, 'PowerReachedCallback', @(h, e) cb_power_reached(e));" is executed MATLAB reports the following error:

 

java.lang.NullPointerException

at com.mathworks.jmi.bean.MatlabBeanInterface.addCallback(MatlabBeanInterface.java:484)

at com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback(MatlabCallbackInterface.java:130)

 

If I type set(vc) there is no callback class listed to register...

                     

Class: [1x1 java.lang.Class]

Configuration: [1x1 com.tinkerforge.BrickletVoltageCurrent$Configuration]

Current: 0

CurrentCallbackPeriod: 1000

CurrentCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$CurrentCallbackThreshold]

DebouncePeriod: 100

Identity: [1x1 com.tinkerforge.Device$Identity]

Power: 0

PowerCallbackPeriod: 0

PowerCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$PowerCallbackThreshold]

Voltage: 0

VoltageCallbackPeriod: 0

VoltageCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$VoltageCallbackThreshold]

 

The example callback won't register. Does anyone have any ideas what could be wrong here?

 

Many thanks

Link to comment
Share on other sites

I tested with this

 

function matlab_example_threshold()
    import com.tinkerforge.IPConnection;
    import com.tinkerforge.BrickletVoltageCurrent;

    ipcon = IPConnection(); % Create IP connection
    vc = BrickletVoltageCurrent('XYZ', ipcon); % Create device object
    set(vc)
end

 

and got this output

 

>> matlab_example_threshold
APIVersion
Class
Configuration
Current
CurrentCallbackPeriod
CurrentCallbackThreshold
DebouncePeriod
Identity
Power
PowerCallbackPeriod
PowerCallbackThreshold
ResponseExpectedAll: [ on | off ]
Voltage
VoltageCallbackPeriod
VoltageCallbackThreshold
PowerReachedCallback: string -or- function handle -or- cell array
VoltageReachedCallback: string -or- function handle -or- cell array
VoltageCallback: string -or- function handle -or- cell array
CurrentReachedCallback: string -or- function handle -or- cell array
CurrentCallback: string -or- function handle -or- cell array
PowerCallback: string -or- function handle -or- cell array

ButtonDownFcn: string -or- function handle -or- cell array
Children
Clipping: [ {on} | off ]
CreateFcn: string -or- function handle -or- cell array
DeleteFcn: string -or- function handle -or- cell array
BusyAction: [ {queue} | cancel ]
HandleVisibility: [ {on} | callback | off ]
HitTest: [ {on} | off ]
Interruptible: [ {on} | off ]
Parent
Selected: [ on | off ]
SelectionHighlight: [ {on} | off ]
Tag
UIContextMenu
UserData
Visible: [ {on} | off ]

 

Did you install the bindings according to the documentation?

 

http://www.tinkerforge.com/en/doc/Software/API_Bindings_MATLAB.html#matlab

 

Also make sure to use the Tinkerforge.jar from the MATLAB bindings zip file. The Tinkerforge.jar from the Java bindings will probably not work.

 

What MATLAB version are you using?

Link to comment
Share on other sites

Hi photron

Thank you for responding. Something strange is happening for me.

 

I am using MATLAB 2015b and the Tinkerforge.jar file from the \MATLAB bindings directory (v2_0_5 file size: 980,064 bytes). In the MATLAB classpath.txt file I have this

 

# DO NOT MODIFY THIS FILE.  IT IS AN AUTOGENERATED FILE.
$<Lots of MATLAB Jar files added to the path>
$matlabroot/Tinkerforge.jar

 

If I execute your simple code I get this:

 

import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletVoltageCurrent;

ipcon = IPConnection(); % Create IP connection
vc = BrickletVoltageCurrent(UID, ipcon); % Create device object

>> set(vc)
ans = 
    CurrentCallbackPeriod: {}
           DebouncePeriod: {}
      PowerCallbackPeriod: {}
      ResponseExpectedAll: {}
    VoltageCallbackPeriod: {}

>> ipcon.connect(HOST, PORT); % Can't use get without executing this
>> get(vc)
                  APIVersion: [3x1 int16]
                       Class: [1x1 java.lang.Class]
               Configuration: [1x1 com.tinkerforge.BrickletVoltageCurrent$Configuration]
                     Current: 0
       CurrentCallbackPeriod: 10
    CurrentCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$CurrentCallbackThreshold]
              DebouncePeriod: 100
                    Identity: [1x1 com.tinkerforge.Device$Identity]
                       Power: 0
         PowerCallbackPeriod: 0
      PowerCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$PowerCallbackThreshold]
                     Voltage: 0
       VoltageCallbackPeriod: 0
    VoltageCallbackThreshold: [1x1 com.tinkerforge.BrickletVoltageCurrent$VoltageCallbackThreshold]

>> ver
ver
----------------------------------------------------------------------------------------------------
MATLAB Version: 8.6.0.232648 (R2015b)
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows 8.1 Version 6.3 (Build 9600)
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB                                                Version 8.6         (R2015b Prerelease)
Signal Processing Toolbox                             Version 7.1         (R2015b Prerelease)

 

Please can I ask what version of MATLAB you are using?

Link to comment
Share on other sites

I tested with R2012a.

 

I think I found the problem. There's a change about how callbacks are handled in R2014a, see

 

http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a

 

According to that blog post you need to replace

 

vc = BrickletVoltageCurrent(UID, ipcon);

 

with

 

vc = handle(BrickletVoltageCurrent(UID, ipcon), 'CallbackProperties');

 

to expose callbacks again. Could you test that?

Link to comment
Share on other sites

Fantastic Photron - problem solved,

Tinkerforge Callbacks are now established in MATLAB R2015b - Don't you just love undocumented features.

For completeness the following updated code now produces this output.

import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletVoltageCurrent;

ipcon = IPConnection(); % Create IP connection
vc = handle(BrickletVoltageCurrent(UID, ipcon),'CallbackProperties');

>> set(vc)
ans = 
     CurrentCallbackPeriod: {}
            DebouncePeriod: {}
       PowerCallbackPeriod: {}
       ResponseExpectedAll: {}
     VoltageCallbackPeriod: {}
      PowerReachedCallback: {}
    VoltageReachedCallback: {}
           VoltageCallback: {}
    CurrentReachedCallback: {}
           CurrentCallback: {}
             PowerCallback: {}

 

My understanding is the listeners only report when a change is detected which means I can't check if the callback is actually executing until tomorrow when I can add a test load.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...