MATLAB & NET. Package

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Hugoneus
Posts: 11
Joined: Tue May 11, 2010 9:01 pm

MATLAB & NET. Package

Post by Hugoneus »

Is there any way to use your functions in MATLAB without having the NET. package installed?

(The function NET.addAssembly is part of the Net Builder package in MATLAB. This is an expensive toolkit and we would like to avoid it.)

Thanks

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: MATLAB & NET. Package

Post by serg »

The .NET component is a wrapper around the main SUB-20 interface library - sub20.dll, located under system\windows32 directory. Most likely you can call exported functions from the Matlab.
Regards

Hugoneus
Posts: 11
Joined: Tue May 11, 2010 9:01 pm

Re: MATLAB & NET. Package

Post by Hugoneus »

What does that mean? Can you post a sample code for MATLAB that doesn't use the NET. functionality of MATLAB? This can be a simple example, like writing a character to the LCD. We are in the process of deciding if we should order 5 more units or not, so please let me know ASAP. The NE builder package in MATLAB is $4000 US dollars, if that is the only way to use your product in MATLAB we may have to go a different direction.

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: MATLAB & NET. Package

Post by serg »

Hi Hugoneus
The following link explains how to do that.
http://www.mathworks.com/access/helpdes ... 4dfi7.html Unfortunatelly we don't have examples which would demonstrate this interface. We can certainly consider preparing some for you, but before doing this can you please confirm that you really need the Builder™ NE to call a third party .NET component from Matlab ? I am not a Matlab expert, but according to the Mathworks website the Builder NE package is intended to provide a mechanism to build Matlab based .NET components and deploy them with no royalty. In order to use existing ones however, like the SUB-20 one, a minimal Matlab installation should be sufficient.
See the MATLAB Builder link for details
http://www.mathworks.com/products/netbuilder/
Regards

Hugoneus
Posts: 11
Joined: Tue May 11, 2010 9:01 pm

Re: MATLAB & NET. Package

Post by Hugoneus »

The examples that you have provided for Matlab all use the NET. package from Mathworks. They all use commands like:

NET.addAssembly('C:\Program Files\SUB-20\bin\sub20dnc.dll');

NET.createArray('System.Byte', 1)

So can you please provide me with some Matlab code that does not invoke those type of NET. commands. A simple example would be sufficient. Like writing one byte to the SPI.

Hugoneus
Posts: 11
Joined: Tue May 11, 2010 9:01 pm

Re: MATLAB & NET. Package

Post by Hugoneus »

This has become quiet urgent.

We are designing a whole bunch of PCBs and we are deciding whether to use the SUB20 headers on the board. Please let me know if you can provide a working code for SPI communication without invoking the NET. package in MATLAB. We will purchase more units (already have purchased 3) if this can be done.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: MATLAB & NET. Package

Post by xol »

Hi,
I'm looking at your discussion with Serg and can not understand what is the problem to use .NET component in Matlab?
As far as I understand from Serg answer you do not have to use Builder™ NE to run .NET calls. So why not to use .NET?

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: MATLAB & NET. Package

Post by serg »

Hi Hugoneus,
We have prepared a simple example which demonstrates direct sub20.dll calls from Matlab


% ------------------------------------------------------------------------------
% The following example demonstrates direct sub20.dll calls
% The main disadvantages of this method (in contrast to the .NET interface) are:
% -incompatible data types
% -numeric constants from the libsub.h are not available
% ------------------------------------------------------------------------------

loadlibrary('C:\WINDOWS\system32\sub20.dll', 'C:\Program Files\SUB-20\inc\libsub.h')

% Open first available SUB-20 device
hSub20=calllib('sub20', 'sub_open', libpointer);

str='Hello world !';

% Write to the LCD
status=calllib('sub20', 'sub_lcd_write', hSub20, str);

% config spi, i.e SPI_ENABLE+SPI_CPOL_RISE+SPI_SMPL_SETUP+SPI_MSB_FIRST+SPI_CLK_4MHZ,
% see libsub.h for details
status=calllib('sub20', 'sub_spi_config', hSub20, hex2dec('40'), libpointer);

% send string str over SPI. Use SS2 SS_LO, see libsub.h for details
status=calllib('sub20', 'sub_spi_transfer', hSub20, str, libpointer, length(str), hex2dec('25'));

% close the device
status=calllib('sub20', 'sub_close', hSub20);
% ------------------------------------------------------------------------------


Regards

hero_hont
Posts: 2
Joined: Fri Aug 20, 2010 10:39 am

Re: MATLAB & NET. Package

Post by hero_hont »

serg wrote:Hi Hugoneus,
We have prepared a simple example which demonstrates direct sub20.dll calls from Matlab


% ------------------------------------------------------------------------------
% The following example demonstrates direct sub20.dll calls
% The main disadvantages of this method (in contrast to the .NET interface) are:
% -incompatible data types
% -numeric constants from the libsub.h are not available
% ------------------------------------------------------------------------------

loadlibrary('C:\WINDOWS\system32\sub20.dll', 'C:\Program Files\SUB-20\inc\libsub.h')

% Open first available SUB-20 device
hSub20=calllib('sub20', 'sub_open', libpointer);

str='Hello world !';

% Write to the LCD
status=calllib('sub20', 'sub_lcd_write', hSub20, str);

% config spi, i.e SPI_ENABLE+SPI_CPOL_RISE+SPI_SMPL_SETUP+SPI_MSB_FIRST+SPI_CLK_4MHZ,
% see libsub.h for details
status=calllib('sub20', 'sub_spi_config', hSub20, hex2dec('40'), libpointer);

% send string str over SPI. Use SS2 SS_LO, see libsub.h for details
status=calllib('sub20', 'sub_spi_transfer', hSub20, str, libpointer, length(str), hex2dec('25'));

% close the device
status=calllib('sub20', 'sub_close', hSub20);
% ------------------------------------------------------------------------------
Regards
thanks you
your reply is very good.
str = str='Hello world !';
status=calllib('sub20', 'sub_lcd_write', hSub20, str);
status=calllib('sub20', 'sub_spi_config', hSub20, hex2dec('40'), libpointer)
This LCD have to demo display as GUI in the matlab, or We work LCD display connection with PC output signal out as COM or USB.
I want to make the block in the simulink which I will use when I need to interface with LCD, but have no idea how and where to start?
I was thinking to make interface via SPI interface and connection LCD with 74HC595 ,but first I would like to know how to implement the above code with the simulink.
Before writing to the LCD display, a set of commands must be issued to configure the LCD for the data write operation. These are:
1. Waiting: Wait for display to get ready after power-on.
Value: 0x00
Execution Time: 15 ms = 750000 cycles
2. Function Set: This is used to set the number of display lines, the character font and the data length (in bits)
Value used*: 0x3C
Execution Time: 8.4 ms = 420000 cycles
* Please note that some of the value used can be changed by setting the DB0 and DB1. Please refer to the user manual for details.
3. Set Display On: Turn the display on, cursor off and cursor position off.
Value used: 0x0C
Execution Time: 4.2 ms = 210000 cycles
4. Clear Display:
Value used: 0x01
Execution Time: 4.2 ms = 210000 cycles
5. Entry Mode Set: This is a powerful command! It can be used to set the direction in which the cursor moves and to specify whether to shift the display or not.
Value used: 0x06
Execution Time: 4.2 ms = 210000 cycles
Once the LCD is configured for writing, the characters to be displayed can be transferred:
1. Char_h:
Value: 0x48
Execution Time: 4.2 ms = 210000 cycles
2. Char_o:
Value: 0x4F
Execution Time: 4.2 ms = 210000 cycles
3. Char_l:
Value: 0x4C
Execution Time: 4.2 ms = 210000 cycles
4. Char_a:
Value: 0x41
Execution Time: 4.2 ms = 210000 cycles
After writing the characters, it is good to wait for additional 4.2 ms (210000 cycles) before exiting the program.
Last edited by hero_hont on Sat Aug 21, 2010 1:22 am, edited 1 time in total.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: MATLAB & NET. Package

Post by xol »

Hi,
You do not need all this stuff. It is done inside SUB-20. All you need is to call sub_lcd_write

Post Reply