Page 1 of 1
Issue with mha_get(mha,'nchannels_in')
Posted: Wed Oct 28, 2020 4:23 pm
by shaikath
Hello,
I am running an instance of openMHA on a VIM board using the command:
mha --interface=0.0.0.0
In Matlab on the host PC, I then run the following lines:
mha.host='192.168.110.47' % IP of the VIM board
mha.port=33337
However when I run the following line I receive an error:
mha_get(mha,'nchannels_in')
The error message is the following:
Error using mhactl_java>retire_connections (line 119)
Java exception occurred:
java.lang.NullPointerException
at de.hoertech.mha.control.Connection.connect(Connection.java:200)
Error in mhactl_java (line 41)
retire_connections(connections(2,:));
Error in mhactl_wrapper>mhactl_wrapper_2 (line 48)
[r, state] = mhactl_java( h, 'eval', query );
Error in mhactl_wrapper (line 33)
r = interface( handle, query );
Error in mha_query (line 17)
s = mhactl_wrapper( handle, [base '?' query] );
Error in mha_get (line 30)
s.type = mha_query( handle, field, 'type');
Does anyone know why this error occurs? Is there more configuration that should be done on the actual VIM board first. Or is this some other Java related issue?
Re: Issue with mha_get(mha,'nchannels_in')
Posted: Wed Oct 28, 2020 5:16 pm
by shaikath
I think this issue may be a more general problem since I am encountering it with other commands as well. When following the dynamic compression example instructions:
>> openmha = mha_start;
>> mha_query(openmha,'','read:dynamiccompression_live.cfg');
Error using mhactl_java>retire_connections (line 119)
Java exception occurred:
java.lang.NullPointerException
at de.hoertech.mha.control.Connection.connect(Connection.java:200)
Error in mhactl_java (line 41)
retire_connections(connections(2,:));
Error in mhactl_wrapper>mhactl_wrapper_2 (line 48)
[r, state] = mhactl_java( h, 'eval', query );
Error in mhactl_wrapper (line 33)
r = interface( handle, query );
Error in mha_query (line 17)
s = mhactl_wrapper( handle, [base '?' query] );
>> mha_set(openmha,'cmd','start');
Error using mhactl_java>retire_connections (line 119)
Java exception occurred:
java.lang.NullPointerException
at de.hoertech.mha.control.Connection.connect(Connection.java:200)
Error in mhactl_java (line 41)
retire_connections(connections(2,:));
Error in mhactl_wrapper>mhactl_wrapper_2 (line 48)
[r, state] = mhactl_java( h, 'eval', query );
Error in mhactl_wrapper (line 33)
r = interface( handle, query );
Error in mha_set (line 15)
mhactl_wrapper(handle,assignments);
Re: Issue with mha_get(mha,'nchannels_in')
Posted: Wed Oct 28, 2020 5:16 pm
by shaikath
Do I maybe need to install a specific version of JDK?
Re: Issue with mha_get(mha,'nchannels_in')
Posted: Wed Oct 28, 2020 5:28 pm
by tobiasherzke
Thanks for posting this here. I have investigated this and confirm that you have found a bug in the openMHA Matlab tools. It seems this was introduced earlier this year when we changed some aspects of the network communication.
The bug manifests when performing these (or similar) steps:
Code: Select all
mha.host='localhost';
mha.port=2; % or any other TCP port that is closed on mha.host
mha_get(mha,''); % results in matlab-user-visible null pointer exception
% replace host and port with the correct data
mha.host = 'realhost';
mha.port = 33337;
mha_get(mha,'nchannels_in'); Again, user-visible null pointer exception despite corrected host and port
We will develop a fix for this. In the meantime, I can suggest the following workarounds (Either should work):
1)In Matlab / Octave:
Code: Select all
clear all % This will delete all your variables as a side effect!
This will delete all your variables as a side effect. But also make the openMHA matlab tools usable again.
2) Replace your copy of the m-file mhactl_java.m in your openMHA installation with this hotfix:
Code: Select all
function [r,state] = mhactl_java(handle, eval, query)
% [r,state] = mhactl_java(handle, eval, query)
% Use java class to communicate with MHA over TCP.
% Can manage several connections to different MHA instances in parallel.
% handle: struct with fields host and port and optionally timeout in seconds.
% eval: String 'eval'. Historic reasons.
% query: Cell array of strings to send to MHA over TCP.
% r: Cell array of strings with responses.
% state: Vector of result codes: 0 for success, 1 for failure.
%
% This file is part of the HörTech Open Master Hearing Aid (openMHA)
% Copyright © 2011 2013 2014 2017 2020 HörTech gGmbH
% openMHA is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published by
% the Free Software Foundation, version 3 of the License.
%
% openMHA is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License, version 3 for more details.
%
% You should have received a copy of the GNU Affero General Public License,
% version 3 along with openMHA. If not, see <http://www.gnu.org/licenses/>.
% Array of existing connections that may be reused for the current query.
% A connection is identified by the triple host, portname, timeout
persistent connections;
persistent last_mhactl_java_invocation;
if isempty(last_mhactl_java_invocation)
last_mhactl_java_invocation = now();
end
if isequal(handle, 'retire_connections')
retire_connections(connections(2,:));
r=[];state=[];connections={};return
end
if (now() - last_mhactl_java_invocation) * 24 * 3600 > 1.2
retire_connections(connections(2,:));
connections={};
end
last_mhactl_java_invocation = now();
if ~isequal(eval, 'eval')
error('second parameter to mhactl_java has to be string ''eval''.')
end
if isempty(connections)
connections = {};
end
% add field default values if fields not present
if ~isfield(handle,'timeout')
global mhactl_timeout;
if isempty(mhactl_timeout)
mhactl_timeout = 50;
end
handle.timeout = mhactl_timeout;
end
if ~isfield(handle,'host')
handle.host = 'localhost';
end
if ~isfield(handle,'port')
handle.port = 33337;
end
% search for existing connection object
connection = [];
for c = 1:size(connections,2)
if structequal(handle, connections{1,c},{'host','port','timeout'})
connection = connections{2,c};
end
end
if isempty(connection) % No matching existing connection, create new
connection = javaObject('de.hoertech.mha.control.Connection');
connection.setTimeout(handle.timeout * 1000);
connection.setAddress(handle.host, handle.port);
connections = [connections, {handle; connection}];
end
% Communicate
r = {};
state = [];
for q = 1:length(query)
q = query{q};
response = [];
try
response = connection.parse(q);
sResponse = char(response.toString());
r = [r, {sResponse}];
state = [state, ~response.getSuccess()];
catch
e = lasterror();
r = [r, {e.message}];
state = [state, 1];
end
end
% Check struct equality, but only in the given fields
function eq = structequal(s1, s2, fields)
eq = true;
for f = fields;
f = f{1};
if isfield(s1,f) ~= isfield(s2,f)
eq = false; return;
end
if isfield(s1,f)
if ~isequal(s1.(f), s2.(f))
eq = false; return;
end
end
end
function retire_connections(connections)
for c = connections
try
c{1}.connect(false);
catch
% If closing the connection raises an error, then that connection
% was already severed. Can happen e.g. when the initial connection
% was unsuccessful because of a closed target port.
end
end
Re: Issue with mha_get(mha,'nchannels_in')
Posted: Wed Oct 28, 2020 5:31 pm
by tobiasherzke
shaikath wrote: ↑Wed Oct 28, 2020 5:16 pm
Do I maybe need to install a specific version of JDK?
The Matlab installer always installs a complete JRE inside the Matlab installation directory, as far as I know. You do not need to install Java separately.
Re: Issue with mha_get(mha,'nchannels_in')
Posted: Fri Nov 27, 2020 10:49 pm
by tobiasherzke
tobiasherzke wrote: ↑Wed Oct 28, 2020 5:28 pm
We will develop a fix for this.
The fix is part of openMHA 4.13.0 which was released today.