GPIO_Read and Matlab .NET interface

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

Moderator: serg

Post Reply
mbaybutt
Posts: 4
Joined: Tue Aug 31, 2010 4:34 pm

GPIO_Read and Matlab .NET interface

Post by mbaybutt »

Hello,

I am attempting to use the .NET interface in Matlab to read the GPIO pins. I have been successful in using the GPIO_SetConfig and GPIO_Write (confirmed by reading the settings with the SUB-20 tool); however, when I call the GPIO_Read function the variable I pass it does not appear to update when I toggle the GPIO line(s).

My first attempt was:
GPIOin = 0;
if ~sub20.GPIO_Read(GPIOin)
sub20_close_handle_error(sub20);
end

Matlab did not complain using this data type despite it nativity being a double in Matlab and the SUB-20 .NET component manual calls for a ByRef Int Value, but the variable did not change from 0 despite pulling the configured GPIO input line high.

Second attempt:
GPIOin = System.UInt32;
if ~sub20.GPIO_Read(GPIOin)
sub20_close_handle_error(sub20);
end

This caused Matlab to generate the following error: "No method 'GPIO_Read' with matching signature found for class 'Xdimax.Sub20'."

What is the correct way to use GPIO_Read from Matlab?

Thanks very much,

- Mark

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

Re: GPIO_Read and Matlab .NET interface

Post by serg »

Hello Mark,

The correct way to read GPIO pins is the following

Code: Select all

   % Read all input pins to the 'val' variable
    [success val] = sub20.GPIO_Read(0) ;
    if ~ success
        break;
    end
See the C:\Program Files\SUB-20\sample\.NET\matlab\gpio.m for more information

Post Reply