Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

calllib function for dll in Matlab - Init USMC

78 views
Skip to first unread message

Aylin

unread,
Mar 11, 2014, 12:35:12 PM3/11/14
to
hello everybody,

i am trying to control a stepper motor in a windows dll by using functions.
The library is loaded with loadlibrary('USMCDLL','USMCDLL.h');
and i can also look up the functions with libfunctionsview('USMCDLL');
Now i have to call the Init function as the user manual says:

The USMC_Init function initializes dll and/or searches for connected devices. It must be called before any other function of the dll.

DWORD USMC_Init( USMC_Devices &Str );


-> I tried it with the libstruct function - explained in the external interface in Matlab:
and than try to call the Init function with calllib.

Devices_st=libstruct('USMC_Devices_st');
calllib('USMCDLL', 'USMC_Init', Devices_st);

I get always the value 4.294967295000000e+09 as return and I don't know what these means.
When i try to call other functions to move the stepper motor it does not work.
I think the stepper is not initialized.
I don't know what i am doing wrong.
Thanks for any help

S

unread,
Mar 11, 2014, 12:45:08 PM3/11/14
to

Steven Lord

unread,
Mar 11, 2014, 1:42:08 PM3/11/14
to

"S " <a_du...@web.de> wrote in message
news:lfneik$lsq$1...@newscl01ah.mathworks.com...
I'm not familiar with this library, but that return value looks like the
maximum unsigned 32-bit integer, intmax('uint32'). Does the documentation
for that library state that this particular value (or perhaps -1) being
returned as a status code indicates a particular type of error?

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Philip Borghesani

unread,
Mar 11, 2014, 6:20:57 PM3/11/14
to
Your code will pass a null pointer to USMC_Init. To pass a pointer to a
valid structure you must initialize at least one field of the structure
as per the documentation.
http://www.mathworks.com/help/matlab/ref/libstruct.html


S

unread,
Mar 13, 2014, 7:03:07 AM3/13/14
to
Okay, so i try to initialize one field of this structure of USMC_Device(user manual):


USMC_Devices
The USMC_Devices structure describes devices connected to computer.


Type Name Description
DWORD NOD Number of devices connected to computer
char ** Serial Array of pointers to 16–byte ASCII strings of length – NOD
char ** Version Array of pointers to 4–byte ASCII strings of length – NOD


Does this mean, it should be okay if i only initialize NOD like this:
(I think it must be zero because i only have one stepper, but i am not sure if 1 or 0 ist right here)

Devices_st.NOD=0;
Devices_st=libstruct('USMC_Devices_st');
calllib('USMCDLL', 'USMC_Init', Devices_st);


If i try this code Matlab crashes abd needs to close and i get this message:

Fault Count: 1


Abnormal termination:
Access violation

Register State (from fault):
RAX = 0000000000000000 RBX = 0000000000000000
RCX = 3ee8ca97553b0000 RDX = 0000000000000000
RSP = 000000000402aa90 RBP = 000007fefb831000
RSI = 000000000000127f RDI = 0000000027a7c3c0

R8 = 000000000402a9a8 R9 = 00000000001202c4
R10 = 0000000000000000 R11 = 0000000000000000
R12 = 0000000029431d90 R13 = 0000000027a7c3c0
R14 = 000000000402ad90 R15 = 0000000000000001

RIP = 0000000029431f31 EFL = 00010246

CS = 0033 FS = 0053 GS = 002b

Stack Trace (from fault):
[ 0] 0x0000000029431f31 C:\Windows\system32\USMCDLL.dll+00007985 USMC_Refresh+00000065
[ 1] 0x000007fefb831037 C:\Users\durmus\AppData\Local\Temp\tp5bb9ab27_c429_43de_a819_422f7c8ffd46\USMCDLL_thunk_pcwin64.dll+00004151 ulongvoidPtrThunk+00000055
[ 2] 0x00000000293e5df3 C:\Program Files\MATLAB\R2013b\bin\win64\libmwcli.dll+00024051 MLTerminate_libmwcli+00019059
[ 3] 0x00000000293e6065 C:\Program Files\MATLAB\R2013b\bin\win64\libmwcli.dll+00024677 MLTerminate_libmwcli+00019685
[ 4] 0x00000000293e735d C:\Program Files\MATLAB\R2013b\bin\win64\libmwcli.dll+00029533 MLTerminate_libmwcli+00024541
[ 5] 0x00000000293fcfec C:\Program Files\MATLAB\R2013b\bin\win64\libmwcli.dll+00118764 PointerMapSize+00072076
[ 6] 0x00000000293fd6a0 C:\Program Files\MATLAB\R2013b\bin\win64\libmwcli.dll+00120480 PointerMapSize+00073792
[ 7] 0x000000018000d7ff C:\Program Files\MATLAB\R2013b\bin\win64\m_dispatcher.dll+00055295 Mfh_file::dispatch_fh+00001167
[ 8] 0x000000018000ddb7 C:\Program Files\MATLAB\R2013b\bin\win64\m_dispatcher.dll+00056759 Mfunction_handle::dispatch+00000487
[ 9] 0x0000000004f16a81 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00486017 inFunctionHandleInterface::DestroyWorkspace+00308737
[ 10] 0x0000000004fa0657 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01050199 inEachVisibleName+00015383
[ 11] 0x0000000004f146c2 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00476866 inFunctionHandleInterface::DestroyWorkspace+00299586
[ 12] 0x0000000004efb85f C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00374879 inFunctionHandleInterface::DestroyWorkspace+00197599
[ 13] 0x0000000004efb7c8 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00374728 inFunctionHandleInterface::DestroyWorkspace+00197448
[ 14] 0x0000000004f1ebbd C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00519101 inFunctionHandleInterface::DestroyWorkspace+00341821
[ 15] 0x0000000004f1b5cc C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00505292 inFunctionHandleInterface::DestroyWorkspace+00328012
[ 16] 0x0000000004efe529 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+00386345 inFunctionHandleInterface::DestroyWorkspace+00209065
[ 17] 0x000000018000d612 C:\Program Files\MATLAB\R2013b\bin\win64\m_dispatcher.dll+00054802 Mfh_file::dispatch_fh+00000674
[ 18] 0x000000018000defa C:\Program Files\MATLAB\R2013b\bin\win64\m_dispatcher.dll+00057082 Mfunction_handle::dispatch+00000810
[ 19] 0x0000000004fb438e C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01131406 inSetWorkSpaces+00001262
[ 20] 0x0000000004fc06f5 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01181429 SetInterpreter+00000325
[ 21] 0x0000000004fc2cb5 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01191093 inEvalCmd+00008789
[ 22] 0x0000000004fc2c82 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01191042 inEvalCmd+00008738
[ 23] 0x0000000004fc2c47 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+01190983 inEvalCmd+00008679
[ 24] 0x00000000053aad0c C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+05287180 inMexPutVariable+00008364
[ 25] 0x00000000053ab066 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+05288038 inMexPutVariable+00009222
[ 26] 0x00000000053ab49e C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+05289118 inMexPutVariable+00010302
[ 27] 0x00000000053ab7dc C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+05289948 inMexPutVariable+00011132
[ 28] 0x00000000052bff91 C:\Program Files\MATLAB\R2013b\bin\win64\m_interpreter.dll+04325265 inEvalCmdWithLocalReturn+00000065
[ 29] 0x000000006c71be9d C:\Program Files\MATLAB\R2013b\bin\win64\libmwbridge.dll+00048797 mnDebugPrompt+00000109
[ 30] 0x000000006c71cf7f C:\Program Files\MATLAB\R2013b\bin\win64\libmwbridge.dll+00053119 mnParser+00000735
[ 31] 0x000000006e4ff4b4 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00193716 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 32] 0x000000006e4e44b0 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00083120 mcr::runtime::setInterpreterThreadToCurrent+00029472
[ 33] 0x000000006e4e4510 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00083216 mcr::runtime::setInterpreterThreadToCurrent+00029568
[ 34] 0x000000006b01fa96 C:\Program Files\MATLAB\R2013b\bin\win64\uiw.dll+00391830 UIW_IsUserMessage+00000086
[ 35] 0x000000006b020175 C:\Program Files\MATLAB\R2013b\bin\win64\uiw.dll+00393589 UIW_SetGLIMUserMsg+00000117
[ 36] 0x000000006b0201f9 C:\Program Files\MATLAB\R2013b\bin\win64\uiw.dll+00393721 UIW_SetGLIMUserMsg+00000249
[ 37] 0x00000000771987fe C:\Windows\system32\USER32.dll+00165886 GetMenuBarInfo+00000638
[ 38] 0x000000007717f5fb C:\Windows\system32\USER32.dll+00062971 SystemParametersInfoW+00000235
[ 39] 0x0000000077184895 C:\Windows\system32\USER32.dll+00084117 IsProcessDPIAware+00000465
[ 40] 0x00000000777511f5 C:\Windows\SYSTEM32\ntdll.dll+00332277 KiUserCallbackDispatcher+00000031
[ 41] 0x000000007718908a C:\Windows\system32\USER32.dll+00102538 PeekMessageW+00000186
[ 42] 0x00000000771850fe C:\Windows\system32\USER32.dll+00086270 GetKeyState+00000238
[ 43] 0x0000000077183a6f C:\Windows\system32\USER32.dll+00080495 PeekMessageA+00000087
[ 44] 0x000000006aff94db C:\Program Files\MATLAB\R2013b\bin\win64\uiw.dll+00234715 UIW_SetCurrentDialog+00000731
[ 45] 0x000000006b021632 C:\Program Files\MATLAB\R2013b\bin\win64\uiw.dll+00398898 ws_FreeSystemFont+00000482
[ 46] 0x000000006f156600 C:\Program Files\MATLAB\R2013b\bin\win64\libmwservices.dll+01009152 services::system_events::PpeDispatchHook::~PpeDispatchHook+00055552
[ 47] 0x000000006f156fc5 C:\Program Files\MATLAB\R2013b\bin\win64\libmwservices.dll+01011653 services::system_events::PpeDispatchHook::~PpeDispatchHook+00058053
[ 48] 0x000000006f157e10 C:\Program Files\MATLAB\R2013b\bin\win64\libmwservices.dll+01015312 services::system_events::PpeDispatchHook::~PpeDispatchHook+00061712
[ 49] 0x000000006f160596 C:\Program Files\MATLAB\R2013b\bin\win64\libmwservices.dll+01050006 sysq::removeProcessPendingEventsHook+00010998
[ 50] 0x000000006f16089a C:\Program Files\MATLAB\R2013b\bin\win64\libmwservices.dll+01050778 svWS_ProcessPendingEvents+00000138
[ 51] 0x000000006e4e552d C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00087341 mcr::runtime::setInterpreterThreadToCurrent+00033693
[ 52] 0x000000006e4e57fb C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00088059 mcr::runtime::setInterpreterThreadToCurrent+00034411
[ 53] 0x000000006e4d9545 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00038213 mcrInstantiationError::operator=+00003221
[ 54] 0x000000006e4dc872 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00051314 mcr_invoke_on_interpreter_thread+00001602
[ 55] 0x000000006e4e98e6 C:\Program Files\MATLAB\R2013b\bin\win64\mcr.dll+00104678 mcrDesktopMain+00000230
[ 56] 0x0000000140004f0b C:\Program Files\MATLAB\R2013b\bin\win64\MATLAB.exe+00020235
[ 57] 0x0000000140006a07 C:\Program Files\MATLAB\R2013b\bin\win64\MATLAB.exe+00027143
[ 58] 0x000000007749652d C:\Windows\system32\kernel32.dll+00091437 BaseThreadInitThunk+00000013
[ 59] 0x000000007772c541 C:\Windows\SYSTEM32\ntdll.dll+00181569 RtlUserThreadStart+00000033


Thank you for any help.




Philip Borghesani <phi...@mathworks.com> wrote in message <lfo274$iac$1...@newscl01ah.mathworks.com>...

S

unread,
Mar 13, 2014, 8:46:08 AM3/13/14
to
I also tried it this way:

>> Devices_st.NOD=1;
>> Devices_st=libstruct('USMC_Devices_st',Devices_st);
>> get(Devices_st)
NOD: 1
Serial: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Version: [0 0 0 0]

>> calllib('USMCDLL', 'USMC_Init', Devices_st);
>> get(Devices_st)
NOD: 0
Serial: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Version: [0 0 0 0]


After the calllib function, the value always goes back to 0. And the result of this function is still the value 4.294967295000000e+09

Thanks you for any help



Philip Borghesani <phi...@mathworks.com> wrote in message <lfo274$iac$1...@newscl01ah.mathworks.com>...

Philip Borghesani

unread,
Mar 13, 2014, 2:39:59 PM3/13/14
to
On 3/13/2014 8:46 AM, S wrote:
> I also tried it this way:
>
>>> Devices_st.NOD=1;
>>> Devices_st=libstruct('USMC_Devices_st',Devices_st);
>>> get(Devices_st)
> NOD: 1
> Serial: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
> Version: [0 0 0 0]
>
>>> calllib('USMCDLL', 'USMC_Init', Devices_st);
>>> get(Devices_st)
> NOD: 0
> Serial: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
> Version: [0 0 0 0]
>
>
> After the calllib function, the value always goes back to 0. And the
> result of this function is still the value 4.294967295000000e+09
>
> Thanks you for any help
>

I think this is correct, I would go back to Steven's comment and attempt
to decode and resolve any error value returned by USMC_Init

Something is a bit fishy about the values your are seeing for Serial and
Version they are not constant with a structure member type of char**.
Investigate any warnings from you loadlibrary command and post the
relevant lines from a prototype file generated with the mfilename option
to loadlibrary if you continue to have difficulties.

Phil

S

unread,
Mar 14, 2014, 7:40:11 AM3/14/14
to
I don't know if this is important but i get this warning message after loadlibrary:

>> loadlibrary('USMCDLL','USMCDLL.h');
Warning: Warnings messages were produced while parsing. Check the
functions you intend to use for correctness. Warning text can be
viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 343



This is line 343:

warning(message('MATLAB:loadlibrary:parsewarnings'));

Thank you.


Philip Borghesani <phi...@mathworks.com> wrote in message <lfsu0q$ctv$1...@newscl01ah.mathworks.com>...

Steven Lord

unread,
Mar 14, 2014, 10:02:14 AM3/14/14
to

"S " <a_du...@web.de> wrote in message
news:lfupqr$1eg$1...@newscl01ah.mathworks.com...
> I don't know if this is important but i get this warning message after
> loadlibrary:
>
>>> loadlibrary('USMCDLL','USMCDLL.h');
> Warning: Warnings messages were produced while parsing. Check the
> functions you intend to use for correctness. Warning text can be
> viewed using:
> [notfound,warnings]=loadlibrary(...)
>> In loadlibrary at 343

So what are the contents of the variables named notfound and warnings when
you did what the warning message suggested?

Olivier

unread,
Apr 4, 2014, 9:29:11 AM4/4/14
to
Hi,

I am trying to use functions in a windows DLL to control a Standa 8SMC1-USBhF-B1-1 controller. This controller is used to control a Standa 8MRU-1 stepper motor.

I am able to communicate with the controller, but not to turn the motor on, and to make it move. Although I know the motor is working as I was able to make it move using the Standa homemade software. But I need to control it using Matlab.

I am able to load the library, initiate the controller, and get it's state using the following commands :

%Load library
if ~libisloaded('mydmdb')
disp('Loading library ...'
[notfound,warnings]=loadlibrary('USMCDLL.dll','C:\WINDOWS\system32\USMCDLL.h','alias','mydmdb');
disp('... done.')
end

%Initiate controller
Devices_st=libstruct('USMC_Devices_st');
Devices_st.NOD=0; %Initialize at least one member of the structure.
retval_init=calllib('mydmdb', 'USMC_Init', Devices_st);
get(Devices_st)

%Get controller state
State_st=libstruct('USMC_State_st');
State_st.CurPos=0;
retval_getstate=calllib('mydmdb', 'USMC_GetState', 0, State_st);
get(State_st)

However I am not able to turn the motor on, thus to make it move.

I used the following commands, as instructed in the user manual, but it did not work :

%Turn device on
Mode_st=libstruct('USMC_Mode_st');
Mode_st.ResetD = 0;
retval_setmode=calllib('mydmdb', 'USMC_SetMode', 0, Mode_st);

%Check if device is on
retval_getstate=calllib('mydmdb', 'USMC_GetState', 0, State_st);
get(State_st)

I can see with the USMC_GetState function that power is still off.

I tried it with Mode_st.ResetD = 1 as well, but it did not work either.

I am not sure what is wrong.

Thanks for any help,

Olivier
0 new messages