MATLAB Answers

0

Issue with mexNI845x Not Finding Resource Names Properly

Asked by James Maroney on 1 May 2018
Latest activity Commented on by Han Du
on 4 May 2018
I am attempting to utilize a NI-8452 to be a SPI master that will communicate with a test board. Matlab code eventually makes use of NI845xSPILib.m
Tracing through the issue, I found that the problem lies with mexNI845x('findDevices') not returning the proper resource name. On my system it simply returns 'ni845x'. On my coworkers system, it returns USB0::0x3923::0x7514::01BE1159::RAW. Code that exists in the Utility.m file, attempt to parse this resource name and split it based on '::' however, the string being based to it does not contain any '::' and therefore it causes failures.
On my coworkers system, everything runs as expected with no problems he is using (Matlab 2017b) On my system, running a command like instrhwinfo('spi') causes it to hit the line of code mentioned earlier and crash. (I am using Matlab 2018a)

  0 Comments

Sign in to comment.

1 Answer

Answer by Han Du
on 4 May 2018

Make sure the support package is installed. The NI-USB-8452 is supported via a support package, per: https://www.mathworks.com/hardware-support/spi-interface.html
See at the bottom of the page for the support package link.
Here's an example of using the support package:
Unfortunately it doesn't look like the device can be simulated in NI MAX so I cannot try to reproduce the issue in R2018a. I wouldn't expecting running instrhwinfo('spi') to check for devices. It only returns the supported vendors and installed vendors:
>> i2cInfo = instrhwinfo ('spi')
i2cInfo =
HardwareInfo with properties:
SupportedVendors: {'aardvark' 'ni845x'}
InstalledVendors: {'ni845x'}
I would expect instrhwinfo('spi', 'ni845x') to check for devices:
>> i2cInfo = instrhwinfo ('spi', 'ni845x')
i2cInfo =
HardwareInfo with properties:
VendorName: 'ni845x'
VendorDescription: 'National Instruments'
VendorLibraryName: 'Ni845x.dll'
InstalledBoardIds: {1×0 cell}
BoardSerialNumbers: {1×0 cell}
ObjectConstructors: {1×0 cell}

  2 Comments

I have already performed and reviewed the two links that you included but my issue wasn't resolved. When the device is not connected, I can reach the first I2C block you mentioned above:
HardwareInfo with properties:
SupportedVendors: {'aardvark' 'ni845x'}
InstalledVendors: {'ni845x'}
Again with the device NOT connected, I run instrhwinfo('spi','ni845x') and get the same printout you showed above.
When the device is connected, the code hits the mexNI845x('findDevices') module, but doesn't return the correct ResourceName string, which then breaks line 116 in the Utility.m file (Program Files\MATLAB\R2018a\toolbox\instrument\instrument\+instrument\+interface\+spi\+ni845x\Utility.m
This problem is occurring because the incorrect ResourceName is being returned and thus cannot be processed by the code that is designed to split a specific ResourceName string. The NI MAX program shows that the device is functioning and I can see the correct ResourceName in that interface. It just seems like the matlab MEX file is not functioning properly.
From the code, it seems that the function is not doing much other than calling the underlying ni845x.h provided by National Instruments to get the resource names for each device. What is the resource name showing in your NI MAX?

Sign in to comment.