I'm trying to interface with a USB oscilloscope, the Handyscope HS3, through Matlab.
I got a basic interface working a few weeks ago but for some reason a library call now seems to cause Matlab to crash. I've been trying to debug this problem with the manufacturers example file.
The error occurs when trying to call:
Result = calllib( sDLL , 'InitInstrument' , 0 );
I first get an error
Warning: The data type 'FcnPtr' used by function SetDataReadyCallback does not exist.
> In loadlibrary (line 431)
Followed by a crash with the following stack trace.
Stack Trace (from fault):
[ 0] 0x00007ffc83147788 C:\WINDOWS\System32\KERNELBASE.dll+00096136 RaiseException+00000104
[ 1] 0x000000003a1bf466 C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+00062566
[ 2] 0x000000003a1bf49c C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+00062620
[ 3] 0x000000003a4a18db C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03086555 TMethodImplementationIntercept+02492443
[ 4] 0x000000003a49d604 C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03069444 TMethodImplementationIntercept+02475332
[ 5] 0x000000003a49d28c C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03068556 TMethodImplementationIntercept+02474444
[ 6] 0x000000003a49f3aa C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03077034 TMethodImplementationIntercept+02482922
[ 7] 0x000000003a49abcd C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03058637 TMethodImplementationIntercept+02464525
[ 8] 0x000000003a4a3d56 C:\Users\Henrik\Documents\GitHub\WIRELESS-COMMUNICATION\tester\oscilloscope\HS3.dll+03095894 InitInstrument+00000438
[ 9] 0x00007ffc68741037 C:\Users\Henrik\AppData\Local\Temp\tp95f6692f_3c8f_4a85_bc27_5e92591072b8\HS3_thunk_pcwin64.dll+00004151 uint16uint16Thunk+00000055
[ 10] 0x0000000027c313a2 C:\Program Files\MATLAB\R2015a\bin\win64\libmwcli.dll+00005026
[ 11] 0x0000000027c380d5 C:\Program Files\MATLAB\R2015a\bin\win64\libmwcli.dll+00032981
[ 12] 0x0000000027c3b785 C:\Program Files\MATLAB\R2015a\bin\win64\libmwcli.dll+00046981
[ 13] 0x0000000027c52012 C:\Program Files\MATLAB\R2015a\bin\win64\libmwcli.dll+00139282 PointerMapSize+00072146
[ 14] 0x0000000027c5309e C:\Program Files\MATLAB\R2015a\bin\win64\libmwcli.dll+00143518 PointerMapSize+00076382
[ 15] 0x0000000010d62f5e C:\Program Files\MATLAB\R2015a\bin\win64\m_dispatcher.dll+00077662 mdLogging::log_function_exit+00000110
[ 16] 0x0000000010d6295c C:\Program Files\MATLAB\R2015a\bin\win64\m_dispatcher.dll+00076124 Mfunction_handle::dispatch+00000476
[ 17] 0x0000000010e49597 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00103831 in_is_matlab_function+00048455
[ 18] 0x0000000010f631a7 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+01257895 inIsKeyword+00027799
[ 19] 0x0000000010e4b69a C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00112282 in_is_matlab_function+00056906
[ 20] 0x0000000010f1684f C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00944207 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000991
[ 21] 0x0000000010f167b1 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00944049 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000833
[ 22] 0x0000000010e8da75 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00383605 inGetCurrentWS+00155269
[ 23] 0x0000000010e8ce8c C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00380556 inGetCurrentWS+00152220
[ 24] 0x0000000010e8b6e9 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00374505 inGetCurrentWS+00146169
[ 25] 0x0000000010d62757 C:\Program Files\MATLAB\R2015a\bin\win64\m_dispatcher.dll+00075607 Mfh_file::dispatch_fh+00000743
[ 26] 0x0000000010d62a7e C:\Program Files\MATLAB\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[ 27] 0x0000000010f1b268 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00963176 inAnonymousFunction+00000360
[ 28] 0x0000000010f1b864 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00964708 inAnonymousFunction+00001892
[ 29] 0x0000000010f1ba25 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00965157 inAnonymousFunction+00002341
[ 30] 0x0000000010f1b9f2 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00965106 inAnonymousFunction+00002290
[ 31] 0x0000000010f1b9a7 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00965031 inAnonymousFunction+00002215
[ 32] 0x0000000010ecf6bd C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00652989 inGetCallersWorkSpace+00001805
[ 33] 0x0000000010ec854d C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00623949 inEvalCmdWithLocalReturn+00000285
[ 34] 0x0000000010ec8471 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00623729 inEvalCmdWithLocalReturn+00000065
[ 35] 0x0000000010ec8415 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00623637 inEvalCmd+00001605
[ 36] 0x0000000010ec7c32 C:\Program Files\MATLAB\R2015a\bin\win64\m_interpreter.dll+00621618 inEvalCmdWithLocalReturnInDesiredWSAndPublishEvents+00000066
[ 37] 0x00000000106efbba C:\Program Files\MATLAB\R2015a\bin\win64\iqm.dll+00261050 iqm::InternalEvalPlugin::inEvalCmdWithLocalReturn+00000170
[ 38] 0x00000000106ef82c C:\Program Files\MATLAB\R2015a\bin\win64\iqm.dll+00260140 iqm::InternalEvalPlugin::execute+00000252
[ 39] 0x00000000fa709d28 C:\Program Files\MATLAB\R2015a\bin\win64\nativejmi.dll+00236840 nativejmi::JmiIIP::serializeExplicit+00004504
[ 40] 0x00000000fa73bb8f C:\Program Files\MATLAB\R2015a\bin\win64\nativejmi.dll+00441231 NativeLabCmdWinSetup+00199087
[ 41] 0x00000000106e4e9a C:\Program Files\MATLAB\R2015a\bin\win64\iqm.dll+00216730 iqm::Iqm::setupIqmFcnPtrs+00027338
[ 42] 0x00000000106e4d86 C:\Program Files\MATLAB\R2015a\bin\win64\iqm.dll+00216454 iqm::Iqm::setupIqmFcnPtrs+00027062
[ 43] 0x00000000106d4a79 C:\Program Files\MATLAB\R2015a\bin\win64\iqm.dll+00150137 iqm::Iqm::deliver+00001113
[ 44] 0x00000000fb5f85c8 C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00034248 ioReadLine+00000280
[ 45] 0x00000000fb5f83d2 C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00033746 ioCmdLineEditSave+00011986
[ 46] 0x00000000fb5f849b C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00033947 ioReadLine+00000107
[ 47] 0x00000000fb5feef5 C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00061173 mnDebugPrompt+00001509
[ 48] 0x00000000fb5fea2a C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00059946 mnDebugPrompt+00000282
[ 49] 0x00000000fb5ff18e C:\Program Files\MATLAB\R2015a\bin\win64\libmwbridge.dll+00061838 mnParser+00000462
[ 50] 0x00000000fd0e13d4 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00398292 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 51] 0x00000000fd0a9757 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00169815 mcr::runtime::setInterpreterThreadToCurrent+00019751
[ 52] 0x00000000fd0a9793 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00169875 mcr::runtime::setInterpreterThreadToCurrent+00019811
[ 53] 0x00000000fd0a9f91 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00171921 mcr::runtime::setInterpreterThreadToCurrent+00021857
[ 54] 0x00000000fab5d216 C:\Program Files\MATLAB\R2015a\bin\win64\uiw.dll+00512534 UIW_AttachThreadInput+00001270
[ 55] 0x00000000fab5caa5 C:\Program Files\MATLAB\R2015a\bin\win64\uiw.dll+00510629 wsd_to_MSW+00004373
[ 56] 0x00000000fab5cb29 C:\Program Files\MATLAB\R2015a\bin\win64\uiw.dll+00510761 wsd_to_MSW+00004505
[ 57] 0x00007ffc851c28cf C:\WINDOWS\System32\USER32.dll+00207055 EmptyClipboard+00000751
[ 58] 0x00007ffc851af339 C:\WINDOWS\System32\USER32.dll+00127801 GetPropW+00000697
[ 59] 0x00007ffc851af2b6 C:\WINDOWS\System32\USER32.dll+00127670 GetPropW+00000566
[ 60] 0x00007ffc86599c54 C:\WINDOWS\SYSTEM32\ntdll.dll+00695380 KiUserCallbackDispatcher+00000036
[ 61] 0x00007ffc830b10c4 C:\WINDOWS\System32\win32u.dll+00004292 NtUserPeekMessage+00000020
[ 62] 0x00007ffc851ae5bd C:\WINDOWS\System32\USER32.dll+00124349 PeekMessageW+00000397
[ 63] 0x00007ffc851ae3a3 C:\WINDOWS\System32\USER32.dll+00123811 PeekMessageA+00000163
[ 64] 0x00000000fab09bdb C:\Program Files\MATLAB\R2015a\bin\win64\uiw.dll+00170971 UIW_ShowMenuItem+00005179
[ 65] 0x00000000fab5db52 C:\Program Files\MATLAB\R2015a\bin\win64\uiw.dll+00514898 UIW_SuspendAttachThreadInput+00000466
[ 66] 0x0000000100122c83 C:\Program Files\MATLAB\R2015a\bin\win64\libmwservices.dll+01256579 services::system_events::PpeDispatchHook::dispatchOne+00032291
[ 67] 0x000000010012e6f5 C:\Program Files\MATLAB\R2015a\bin\win64\libmwservices.dll+01304309 sysq::addProcessPendingEventsUnitTestHook+00005813
[ 68] 0x000000010012e7a0 C:\Program Files\MATLAB\R2015a\bin\win64\libmwservices.dll+01304480 sysq::addProcessPendingEventsUnitTestHook+00005984
[ 69] 0x0000000100130595 C:\Program Files\MATLAB\R2015a\bin\win64\libmwservices.dll+01312149 sysq::getCondition+00004629
[ 70] 0x0000000100131f52 C:\Program Files\MATLAB\R2015a\bin\win64\libmwservices.dll+01318738 svWS_ProcessPendingEvents+00000162
[ 71] 0x00000000fd0aa6ad C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00173741 mcr::runtime::setInterpreterThreadToCurrent+00023677
[ 72] 0x00000000fd0ab31a C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00176922 mcr::runtime::setInterpreterThreadToCurrent+00026858
[ 73] 0x00000000fd0a2f75 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00143221 mcr_process_events+00007557
[ 74] 0x00000000fd0a4882 C:\Program Files\MATLAB\R2015a\bin\win64\mcr.dll+00149634 mcr_process_events+00013970
[ 75] 0x000000001595b49d C:\Program Files\MATLAB\R2015a\bin\win64\MVMLocal.dll+00177309 mvm_server::inproc::LocalFactory::terminate+00048141
[ 76] 0x00000000fa8fa27a C:\Program Files\MATLAB\R2015a\bin\win64\mvm.dll+00828026 mvm::detail::initLocalMvmHack+00000490
[ 77] 0x00000000fa8fa838 C:\Program Files\MATLAB\R2015a\bin\win64\mvm.dll+00829496 mvm::detail::SessionImpl::privateSession+00000376
[ 78] 0x00000000fa8faa88 C:\Program Files\MATLAB\R2015a\bin\win64\mvm.dll+00830088 mvm::detail::SessionImpl::privateSession+00000968
[ 79] 0x000000014000630d C:\Program Files\MATLAB\R2015a\bin\win64\MATLAB.exe+00025357
[ 80] 0x0000000140007dd0 C:\Program Files\MATLAB\R2015a\bin\win64\MATLAB.exe+00032208
[ 81] 0x00007ffc858d8364 C:\WINDOWS\System32\KERNEL32.DLL+00033636 BaseThreadInitThunk+00000020
[ 82] 0x00007ffc865570d1 C:\WINDOWS\SYSTEM32\ntdll.dll+00422097 RtlUserThreadStart+00000033
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.
Based on previous threads I suspect that this is caused by the header file, however this is the first time I'm using an external library and I'm not knowledgable enough to know what to look for.
The only thing I've really figured out is that the crash doesn't occur if I try running the script without the oscilloscope plugged in. The instrument works fine while using the manufacturers propriety software though so that doesn't seem to be the problem.
The header file looks like this: (I've deleted the last part since it's just definitions of more library calls)
#ifndef __TIEPIE_H__
#define __TIEPIE_H__
/*
* This header file contains the declarations for the low level routines
* for the TiePie engineering instrument dll's
*/
#include <windows.h>
/*
* declarations to match pascal-types to c-types
*/
typedef unsigned char byte;
typedef unsigned short int word;
typedef unsigned int dword;
typedef signed long int integer;
typedef signed long long int64;
typedef void * pointer;
/*
* The instruments
*/
typedef enum {
dtHandyprobe2,
dtHandyscope2,
dtHandyscope3,
dtHandyscope4,
dtHS508,
dtHS801,
dtTP112,
dtTP208,
dtTP508,
dtTP801,
dtPCI801,
dtMultiCh
} TDeviceTypes;
// Return codes = bit values. Non-zero is an error:
#define E_NO_ERRORS 0x0000
#define E_NO_HARDWARE 0x0001
#define E_NOT_INITIALIZED 0x0002
#define E_NOT_SUPPORTED 0x0004
#define E_NO_GENERATOR 0x0008
#define E_INVALID_CHANNEL 0x0010
#define E_INVALID_VALUE 0x0020
#define E_I2C_ERROR 0x0040
#define E_I2C_INVALID_ADDRESS 0x0080
#define E_I2C_INVALID_SIZE 0x0100
#define E_I2C_NO_ACKNOWLEDGE 0x0200
// Channel constants:
#define lCh1 1
#define lCh2 2
#define lCh3 3
#define lCh4 4
// Measure Mode constants, do NOT use for anything else than G/SetMeasureMode().
// When measuring more channels, simply add the required constants together : e.g. mmCh1 + mmCh2 to measure both Ch1 and Ch2
#define mmCh1 1
#define mmCh2 2
#define mmCh3 4
#define mmCh4 8
#define mmCh12 3
// Coupling constants:
#define lctAC 0
#define lctDC 1
// Trigger mode constants:
#define ltkRising 0 // Trigger when signal passes level in positive direction
#define ltkFalling 1 // Trigger when signal passes level in negative direction
#define ltkInWindow 2 // Trigger when signal enters marked window
#define ltkOutWindow 3 // Trigger when signal leaves marked window
#define ltkTVLine 4 // Trigger at TV line sync pulse
#define ltkTVFieldOdd 5 // Trigger at Odd TV field sync pulse
#define ltkTVFieldEven 6 // Trigger at Even TV field sync pulse
#define ltkNet 7 // Trigger on peaks/dips in the line net
#define ltkNthPulse 8 // Trigger on the nth pulse after start of measuring
#define ltkPulseLargerM 9 // Trigger if a pulse is larger than M
#define ltkPulseSmallerM 10 // Trigger if a pulse is smaller than M
#define ltkGlitch 11 // Trigger when the change between two samples is larger than x
// Trigger source constants:
#define ltsCh1 0 // Trigger on Ch1
#define ltsCh2 1 // Trigger on Ch2
#define ltsCh3 2 // Trigger on Ch3
#define ltsCh4 3 // Trigger on Ch4
#define ltsExternal 4 // Trigger on digital external trigger input
#define ltsAnalogExt 5 // Trigger on analog external trigger input
#define ltsAnd 6 // Trigger on Ch1 AND Ch2
#define ltsOr 7 // Trigger on Ch1 OR Ch2
#define ltsXor 8 // Trigger on Ch1 XOR Ch2
#define ltsNoTrig 9 // Do not wait for trigger, measure immediately
#define ltsNeverTrig 10 // not used
#define ltsPxiExt 11 // Trigger on external PXI trigger inputs
#define ltsGenStart 12 // Trigger on Generator Start Signal
#define ltsGenStop 13 // Trigger on Generator Stop Signal
#define ltsGenNew 14 // Trigger on Generator New Period
#define ltsUnknown 15 // not used
// Transfer mode constants:
#define ltmBlock 0
#define ltmStream 1
// Instrument Configuration constants:
#define licHS3Norm 0
#define licHS3256K 1
#define licHS3512K 2
// FuncGen Modes:
#define lfmDDS 1
#define lfmLinear 2
// Signal types
#define lstSine 0
#define lstTriangle 1
#define lstSquare 2
#define lstDC 3
#define lstNoise 4
#define lstArbitrary 5
/*
* definition of Callback function
*/
typedef void (*TDataReady) (void);
/*
* Properly decorate the API functions for either import (default) or export.
*/
#ifdef BUILD_TIEPIE
# define TP_STORAGE_CLASS DLLEXPORT
#else
# define TP_STORAGE_CLASS DLLIMPORT
#endif
/*
* Adjust naming convention to match language in use.
*/
#ifdef __cplusplus
# define TP_EXTERNC extern "C"
#else
# define TP_EXTERNC extern
#endif
/*
* Use the proper storage-class attributes (and order) for the compiler
* in use.
*/
#if (defined(_MSC_VER) || (__BORLANDC__ >= 0x0550) || \
defined(__LCC__) || defined(__WATCOMC__) || \
(defined(__GNUC__) && defined(__declspec)))
# define DLLIMPORT __declspec(dllimport)
# define DLLEXPORT __declspec(dllexport)
# define TP_EXTERN(RTYPE) TP_EXTERNC TP_STORAGE_CLASS RTYPE WINAPI
#elif defined(__BORLANDC__)
/* Pre-5.5 Borland requires the attributes be placed after the */
/* return type instead. */
# define DLLIMPORT __import
# define DLLEXPORT __export
# define TP_EXTERN(RTYPE) TP_EXTERNC RTYPE TP_STORAGE_CLASS WINAPI
#else
# define DLLIMPORT
# define DLLEXPORT
# define TP_EXTERN(RTYPE) TP_EXTERNC RTYPE WINAPI
#endif
/*
* ============================================================================
* Declarations for functions from dynamically loaded librarie(s)
* ============================================================================
*/
// Open / Close the instrument:
#ifdef TP_TYPEDEFS
typedef word (WINAPI * LPFN_InitInstrument) ( word wAddress );
#ifndef TP_NOSTATICIMPORT
extern LPFN_InitInstrument InitInstrument;
#endif
#else
TP_EXTERN( word ) InitInstrument( word wAddress );
#endif
#ifdef TP_TYPEDEFS
typedef word (WINAPI * LPFN_ExitInstrument) ( void );
#ifndef TP_NOSTATICIMPORT
extern LPFN_ExitInstrument ExitInstrument;
#endif
#else
TP_EXTERN( word ) ExitInstrument( void );
#endif