MATLAB x64 issues - no header file?

Post your MATLAB discussions here
GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

MATLAB x64 issues - no header file?

Post by GeoffA »

Hi folks,

I'm trying to get the dll's working in MATLAB 2012bx64. I'm only at the loadlibrary() stage.

The SDK has the x64 DLL's which is great, but there's no x64-compatible header file so it errors immediately. Naively commenting out the "ifndef WIN32" gives the error...

Error using loadlibrary (line 419)
Building usbtc08_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2012b\extern\include" /W3 /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /nologo -I"C:\Users\iprdadmin\Documents\MATLAB"
-I"C:\Program Files (x86)\Pico Technology\Pico Full" "usbtc08_thunk_pcwin64.c" -LD
-Fe"usbtc08_thunk_pcwin64.dll"
usbtc08_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'


I don't have the chops to roll my own header files....any suggestions?

Thanks

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

Hi GeoffA,

I've modified the header file so that if the platform isn't WIN32, it has some other definitions.
usbtc08.h
Updated USB TC-08 header file.
(9.83 KiB) Downloaded 1323 times
Please try this and post back here as to whether it works or not - unfortunately we don't have a 64-bit version of MATLAB to test against.

Another option might be to create a prototype file using the loadlibrary command on a 32-bit version of MATLAB and see if that works on the 64-bit version.

Hope this helps.

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

Matlab gives me the following error when I try that header file:

Error using loadlibrary (line 419)
Building usbtc08_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2012b\extern\include" /W3 /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /nologo -I"C:\Users\iprdadmin\Documents\MATLAB" -I"C:\Program
Files (x86)\Pico Technology\Pico Full\USBTC08sdk_r10_5_0_19\x64" "usbtc08_thunk_pcwin64.c" -LD
-Fe"usbtc08_thunk_pcwin64.dll"
usbtc08_thunk_pcwin64.c
C:\Program Files (x86)\Pico Technology\Pico Full\USBTC08sdk_r10_5_0_19\x64\usbtc08.h(71) : error C2628:
'int64_t' followed by '__int64' is illegal (did you forget a ';'?)
C:\Program Files (x86)\Pico Technology\Pico Full\USBTC08sdk_r10_5_0_19\x64\usbtc08.h(71) : warning C4091:
'typedef ' : ignored on left of '_Longlong' when no variable is declared


...hopefully this is just a typo rather than something more fundamentally wrong?

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

Hi Geoff,

I've commented out the line that perhaps was causing the error based on a post in this area of the forum.
usbtc08.h
Updated header file
(9.83 KiB) Downloaded 1289 times
I've also generated a prototype file using R2012B 32-bit that you can try loading instead of the header file:

[The extension m has been deactivated and can no longer be displayed.]

Code: Select all

loadlibrary 'usbtc08.dll' 'usbtc08MFile';
You can use libfunctionsview ('usbtc08') to view the functions once loaded.

Please try both and post the results back here.

Thanks,

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

Trying the header file...

Code: Select all

Error using loadlibrary (line 419)
Building usbtc08_thunk_pcwin64 failed.  Compiler output is:
cl -I"C:\Program Files\MATLAB\R2012b\extern\include"   /W3  /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0  /nologo  -I"C:\Users\iprdadmin\Documents\MATLAB" -I"C:\Program
Files (x86)\Pico Technology\Pico Full\USBTC08sdk_r10_5_0_19\x64" "usbtc08_thunk_pcwin64.c" -LD
-Fe"usbtc08_thunk_pcwin64.dll"
usbtc08_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
...but I'm going to have to double check this on my personal PC this weekend to see if this isn't anything odd to do with compiler settings.


Using the prototype file (on the matlab path) gives...

Code: Select all

Error using loadlibrary (line 419)
The function call type stdcall is not supported
btw thanks for all your help so far - hopefully we'll be able to get something working so that others can benefit too!

Cheers

Geoff

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

Hi Geoff,

Which compilers are you using? Try

Code: Select all

myCompiler = mex.getCompilerConfigurations()
and

Code: Select all

cLanguageCC = mex.getCompilerConfigurations('C','Supported')

format compact
cLanguageCC.Name
I've taken the above from:

http://www.mathworks.co.uk/help/matlab/ ... tions.html

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

The officially supported compiler (http://www.mathworks.com/support/compil ... win64.html) is the Windows SDK 7.1 (http://www.microsoft.com/en-us/download ... px?id=8279), but unfortunately it errors on installation for reasons that I don't fully understand, but suspect are due to work security/admin settings. Instead I installed Visual C++ 2010 Express. MATLAB won't detect this, so I forced it using 'mex -setup', 'n', option 14. I was going t o try this on my laptop at home to check if it was indeed a settings issue. The work OS is W7x64 Enterprise.

As requested...

Code: Select all

>> myCompiler = mex.getCompilerConfigurations()

myCompiler = 

  mex.CompilerConfiguration
  Package: mex

  Properties:
             Name: 'Microsoft Visual C++ 2010'
     Manufacturer: 'Microsoft'
         Language: 'C++'
          Version: '10.0'
         Location: [1x51 char]
          Details: [1x1 mex.CompilerConfigurationDetails]
       LinkerName: 'Microsoft Visual C++ 2010'
    LinkerVersion: '10.0'

  Methods
and...

Code: Select all

 cLanguageCC.Name
ans =
Intel C++
ans =
Intel C++
ans =
Intel C++
ans =
Intel C++
ans =
Microsoft SDK
ans =
Microsoft Visual C++ 2010
ans =
Microsoft Visual C++ 2005 SP1
ans =
Microsoft Visual C++ 2008
Maybe I'm just being a little bit stupid here - do I need a C rather than C++ compiler for this?

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

On my laptop I install SDK 7.1 without any problem, so this is definitely something I'll have to speak to IT about. The library is loaded just fine, but now at the calllib stage to open communications comes up with a 0..

Code: Select all

tc08Handle = calllib(usbtc08, 'usb_tc08_open_unit')

tc08Handle =

     0
..but I wouldn't be surprised if that's just because I haven't got the unit plugged in at home. I'll bring my laptop in on Monday and try again!

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

0 is returned if no more units are found.

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

Part of the problem I'd had was with using legacy calls from a previous version of the DLL's, but now it more or less seems to be working apart from a couple of niggling things On my laptop running W7HPx64 with compilers properly installed I can now connect properly. libisloaded works fine, so on the work PC obviously there are some compiler configuration issues that I need to see IT about, but that's my problem :)

Some things work and some things don't (all assume a prefix of "usb_tc08_")

Things that work:
open_unit
close_unit
get_minimum_interval_ms
set_channel
get_temp_single (about 0.9 s per call)
run
stop
get_temp (about 1 ms per call :D )


Things that sort of work:

get_formatted_info - works, but causes MATLAB to crash if called repeatedly within a short window of time (say, 5 times in a second).



Things that don't:

get_unit_info - gives an error (0) and an empty structure if using struct([]) (although each field has the right name and some dimensions) and get_last_error says no errors have happened - using libpointer('tUSBTC08InfoPtr') gives the right fieldnames and the right datatypes but all are empty

libsfunctionsview shows up a method of "get_info2" which shouldn't be defined and when you try and call it it doesn't appear to exist.

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

Hi Geoff,

I've been able to call the get_formatted_info call on the 32-bit version using the following:

Code: Select all

% Get unit information
for n = 1:10
    
infostring = blanks(512);

[status, infostring] = calllib('usbtc08', 'usb_tc08_get_formatted_info', ...
    data.unithandle, infostring, 512)

pause(0.2)

end
I'm not sure why get_info2 function is not documented but I am able to query it:

Code: Select all

info = blanks(20);
[status, info] = calllib('usbtc08', 'usb_tc08_get_unit_info2', data.unithandle, info, 20, 0)
The last parameter is the information type and should be in the range 0 - 5 which should correspond to the enUSBTC08InfoLine enumerations.

Could you post the code that shows how you setup the structure and query the get_unit_info function? Are you setting the size parameter in the structure to 40?

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

Your code works! The problem here is that the unit_info argument wasn't right, because the Programming Guide ~= libfunctionsview == yourCode :)

The programming guide says it should be a char pointer (a 1xn char in matlab), where as libfunctionsview says that the unit_info argument should be a cstring (i.e. not a pointer), which is how your code is working. For what its worth, here's what I was doing:

Code: Select all

% function to call open_unit - works fine
%handle = usbtc08connectslow('KKX');

infoBytes = int16(256); % responds with readSuccess == 0 if <256

%initialValue = '';  % crashes
%initialValue = char(1); % crashes
%initialValue = 'X'; % crashes
%initialValue = repmat(char(0), infoBytes, 1) % crashes
%initialValue = repmat(char(1), infoBytes, 1) % gives info == initialValue
initialValue = repmat('X', infoBytes, 1);

%infoPointer = initialValue; - similar behaviour to using libpointer
infoPointer = libpointer('cstring', initialValue); % no other pointer types allowed
    
readSuccess = calllib('usbtc08', 'usb_tc08_get_formatted_info', handle, infoPointer, infoBytes);

if readSuccess
    disp('Should have worked...')
else
    disp('Didn''t read it.')
end

info = get(infoPointer, 'Value')

As for get_info, I was getting empty structures with some of the right properties with:

Code: Select all

initialValue = struct([]);

%infoPointer = initialValue;
%infoPointer = libpointer('tUSBTC08InfoPtr');
infoPointer = libpointer('tUSBTC08InfoPtr', initialValue); % same as if not specified

% reads it    
[readSuccess, info] = calllib('usbtc08', 'usb_tc08_get_unit_info', handle, infoPointer);

if readSuccess
    disp('Should have worked...')
else
    disp('Didn''t read it properly.')
end

disp(info)

disp(get(infoPointer, 'Value'))

...but I can read temperature out of my USB TC-08 which is the most important thing...this is just tidying up loose ends.

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

This code works with the get_unit_info function:

Code: Select all

tc08info.size = int16(40);
tc08info.DriverVersion = int8(['0.0.0.0' 0]);
tc08info.PicoppVersion = int16(0);
tc08info.HardwareVersion = int16(0);
tc08info.Variant = int16(0);
tc08info.szSerial = int8(['ABC12/007' 0]);
tc08info.szCalDate = int8(['01Jan01' 0]);

[status, info] = calllib('usbtc08', 'usb_tc08_get_unit_info', data.unithandle, tc08info)

% Print out the strings
dv = char(info.DriverVersion)
sr = char(info.szSerial)
cd = char(info.szCalDate)
I also tried using the structure from the prototype file:

Code: Select all

[methodinfo,structs,enuminfo,ThunkLibName]= usbtc08MFile;

tc08Info = structs.tUSBTC08Info.members;
tc08Info.size = int16(40);
tc08Info.DriverVersion = int8(['0.0.0.0' 0]);
tc08Info.PicoppVersion = int16(0);
tc08Info.HardwareVersion = int16(0);
tc08Info.Variant = int16(0);
tc08Info.szSerial = int8(['ABC12/007' 0]);
tc08Info.szCalDate = int8(['01Jan01' 0]);

tc08InfoPtr = libpointer('tUSBTC08InfoPtr', tc08Info)

[status, info2] = calllib('usbtc08', 'usb_tc08_get_unit_info', data.unithandle, tc08InfoPtr)

dv2 = char(info2.DriverVersion)
sr2 = char(info2.szSerial)
cd2 = char(info2.szCalDate)

GeoffA
Newbie
Posts: 0
Joined: Wed May 15, 2013 1:51 pm

Re: MATLAB x64 issues - no header file?

Post by GeoffA »

That works for me too - I didn't realise I had to more fully define the structure before populating it. Thanks for your help! Presumably this header file will get rolled into future SDK releases so other people don't run into the same problems?

Hitesh

Re: MATLAB x64 issues - no header file?

Post by Hitesh »

We are in the process of developing generic MATLAB Instrument Drivers for our products, but in the meantime we'll look to provide some helper files in the SDK for Customers looking to create their own scripts.

Post Reply