try catch not working with addinput (data acquisition toolbox)
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Here is some sample code:
close all
clear all
clc
try
d = daq('directsound');
c = addinput(d, 'Audio1', 1, 'Audio');
catch msg
disp('error caught')
disp(msg)
end
Here is the error message I get, after a computer reboot:
Error using matlabshared.asyncio.internal.MessageHandler/onError
Audio input device has become unresponsive: 1024 sample(s) remain after timeout.
Error in daq.audio.internal.ChannelGroupAudio/doVerifyAudioDeviceRates (line 275)
pause(0.01);
Error in daq.audio.internal.ChannelGroupAudioStatePrepared/verifyRates (line 38)
hasValidRates = obj.ChannelGroupAudio.doVerifyAudioDeviceRates(rates);
Error in daq.audio.internal.ChannelGroupAudio/verifyAudioDeviceRates (line 151)
hasValidRates = obj.State.verifyRates(rates);
Error in daq.audio.internal.ChannelGroupManager/verifyDeviceRates (line 377)
validRates = channelGroup.verifyAudioDeviceRates(rates);
Error in daq.audio.internal.ChannelGroupManager/verifyRates (line 177)
validRates(i, :) = obj.verifyDeviceRates(device, rates);
Error in daq.audio.Session/checkForValidRateLimits (line 892)
verifiedRates = obj.ChannelGroupManager.verifyRates(rateBounds);
Error in daq.audio.Session/updateRateLimit (line 205)
[imin, imax, hasValidRateLimits] = obj.checkForValidRateLimits(rates);
Error in daq.audio.Session/updateRateLimitInfoHook (line 538)
obj.updateRateLimit();
Error in daq.Session/doAddChannel (line 2372)
obj.updateRateLimitInfoHook();
Error in daq.internal.StateNoChannels/addChannel (line 39)
[channel,index] = obj.Session.doAddChannel(varargin{:});
Error in daq.Session/addChannelInternal (line 2134)
[channel,index] = obj.InternalState.addChannel(varargin{:});
Error in daq.Session/addAudioInputChannel (line 1362)
[channel,index] = obj.addChannelInternal(...
Error in daq.interfaces.DataAcquisition/doAddChannel (line 1757)
[channels,indices] = feval(['add' subsystemType 'Channel'],obj.Session,varargin{1:end-1});
Error in daq.interfaces.internal.DaqStateNoChannels/addchannel (line 21)
[channels,indices] = obj.Daq.doAddChannel(varargin{:});
Error in daq.interfaces.internal.DaqStateProxy/addchannel (line 23)
[channels, indices] = obj.State.addchannel(varargin{:});
Error in daq.interfaces.DataAcquisition/addchannel (line 1362)
[channels,indices] = obj.InternalState.addchannel(varargin{:});
Error in daq.interfaces.DataAcquisition/addinput (line 57)
[channels,indices] = addchannel(obj,varargin{:},'input');
Error in test_daq (line 7)
c = addinput(d, 'Audio1', 1, 'Audio');
Error using matlabshared.asyncio.internal.MessageHandler/onError
Audio input device has become unresponsive: 1024 sample(s) remain after timeout.
The error message is peculiar to the particular microphone I am attempting to use, and I am not after help with getting it working. Though if there is some other way to detect the problem without throwing an error that would be good.
Rather, I am after help with catching the error message. The error is not caught in the sample code above.
Here is the output of daqlist:
>> x=daqlist
x =
6×5 table
VendorID DeviceID Description Model DeviceInfo
_____________ ________ _______________________________________________________ ___________________________________________ ________________________
"directsound" "Audio0" "DirectSound Primary Sound Capture Driver" "Primary Sound Capture Driver" 1×1 daq.audio.DeviceInfo
"directsound" "Audio1" "DirectSound Microphone (HS-720 V2)" "Microphone (HS-720 V2)" 1×1 daq.audio.DeviceInfo
"directsound" "Audio2" "DirectSound Primary Sound Driver" "Primary Sound Driver" 1×1 daq.audio.DeviceInfo
"directsound" "Audio3" "DirectSound Headphones (HS-720 V2)" "Headphones (HS-720 V2)" 1×1 daq.audio.DeviceInfo
"directsound" "Audio4" "DirectSound Realtek Digital Output (Realtek(R) Audio)" "Realtek Digital Output (Realtek(R) Audio)" 1×1 daq.audio.DeviceInfo
"directsound" "Audio5" "DirectSound ASUS VP247 (NVIDIA High Definition Audio)" "ASUS VP247 (NVIDIA High Definition Audio)" 1×1 daq.audio.DeviceInfo
>> x.DeviceInfo(2,1)
ans =
directsound: DirectSound Microphone (HS-720 V2) (Device ID: 'Audio1')
Audio input supports:
-1.0 to +1.0 range
Rates from 80.0 to 1000000.0 scans/sec
1 channel ('1')
'Audio' measurement type
Properties, Methods, Events
Vendor: DirectSound
ID: 'Audio1'
Model: 'Microphone (HS-720 V2)'
Subsystems: [1x1 daq.audio.AudioInputInfo]
DisplayInoperationalVendorDiagnostics: false
Description: 'DirectSound Microphone (HS-720 V2)'
RecognizedDevice: true
Methods for class daq.audio.DeviceInfo:
disp get
Methods of daq.audio.DeviceInfo inherited from handle.
Events for class daq.audio.DeviceInfo:
ObjectBeingDestroyed
>> x.DeviceInfo(2,1).Vendor
ans =
Data acquisition vendor 'DirectSound':
ID: 'directsound'
FullName: 'DirectSound'
AdaptorVersion: '23.2 (R2023b)'
DriverVersion: 'n/a'
IsOperational: true
Properties, Methods, Events
Additional data acquisition vendors may be available as downloadable support packages.
Open the Support Package Installer to install additional vendors.
>> x.DeviceInfo(2,1).Subsystems
ans =
Audio input supports:
-1.0 to +1.0 range
Rates from 80.0 to 1000000.0 scans/sec
1 channel ('1')
'Audio' measurement type
Properties, Methods, Events
RangesAvailable: -1.0 to +1.0
Resolution: 24
RateLimit: [80.0 1000000.0]
MeasurementTypesAvailable: [1x1 cell]
DefaultMeasurementType: 'Audio'
NativeDataType: 'double'
SubsystemType: AudioInput
NumberOfChannelsAvailable: 1
ChannelNames: [1x1 cell]
Methods for class daq.audio.directsound.directsound:
disp get
Methods of daq.audio.directsound.directsound inherited from handle.
Events for class daq.audio.directsound.directsound:
ObjectBeingDestroyed
RangesAvailable: -1.0 to +1.0
Resolution: 24
RateLimit: [80.0 1000000.0]
MeasurementTypesAvailable: [1x1 cell]
DefaultMeasurementType: 'Audio'
NativeDataType: 'double'
SubsystemType: AudioInput
NumberOfChannelsAvailable: 1
ChannelNames: [1x1 cell]
Methods for class daq.audio.AudioInputInfo:
get
Methods of daq.audio.AudioInputInfo inherited from handle.
Events for class daq.audio.AudioInputInfo:
ObjectBeingDestroyed
>>
0 comentarios
Respuestas (1)
Walter Roberson
el 12 de Sept. de 2025
Error using matlabshared.asyncio.internal.MessageHandler/onError
We can deduce from the error message that it is performing an asynchronous operation. try/catch is only suitable for synchronous operations.
Ver también
Categorías
Más información sobre Multichannel Audio Input and Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!