File Exchange

image thumbnail

Test_FTD2XX_NET_Bit​Bang

version 1.0.0.0 (2.22 KB) by Roger M. Ellingson
Demonstration of calling FTDI's FTD2XX_NET.dll BitBang functions from Matlab.

2 Downloads

Updated 28 Sep 2010

View License

File demonstrates calling directly into the FTD2XX_NET.dll library from Matlab code. FTDI makes USB compatible devices which can make the creation of USB-based electronic instruments much easier. The FTD2XX_NET.dll (downloadable ftdichip.com) is a .Net wrapper for the FTDI D2XX USB device driver programming library. This library eliminates the need for device developers to write custom USB drivers when developing custom instrumentation which interfaces to a PC via the USB ports.

Test_FTD2XX_NET_BitBang.m demonstrates opening the dll, opening a FTDI FT245-based USB device, and setting the device up for BitBang mode. In BitBang mode, the FT245 device functions as an 8-bit parallel I/O port. Modern PCs and laptops do not typically contain such parallel interfaces anymore. Hanging a simple module containing the FTDI FT245 chip, such as the DLP-USB245M, on a PC USB bus can add parallel port I/O capability to your PC which can be useful when controlling or communicating with external hardware.

Via the FTD2XX_NET.dll, Test_FTD2XX_NET_BitBang.m 'bangs' all eight ouput bits of the DLP-USB245M 5 times then quits. The scope displays 'D0' bit waveform.

No .mex files, header files, or other fussing around is necessary as (at least the most recent versions) Matlab user code can directly call into .NET assemblies such as the FTD2XX_NET.dll.

Cite As

Roger M. Ellingson (2021). Test_FTD2XX_NET_BitBang (https://www.mathworks.com/matlabcentral/fileexchange/28875-test_ftd2xx_net_bitbang), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

FARRUKH WAHEED

Thanks a lot Roger. Great job!

I would like to know how can we access the Device type from the list of available/ supported FTDI devices from the list. Like I am using FT2232H device and I want my application to detect the device type. I don't know how to use GetDeviceType in following piece of code.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
clear all;
clc;
% Place dll in directory of your choice.
f = NET.addAssembly('C:\Users\farru\Downloads\FTD2XX_NET_v1.1.0\FTD2XX_NET_v1.1.0\FTD2XX_NET.dll');
% Helpful to view other function calling parameters.
methodsview( 'FTD2XX_NET.FTDI');
fo=FTD2XX_NET.FTDI;
FT_OK = 0;
DeviceType = {'DEVICE_232BM','DEVICE_232AM','DEVICE_100AX','DEVICE_UNKNOWN','DEVICE_2232C','DEVICE_232R','DEVICE_2232H','DEVICE_4232H','DEVICE_232H'};
disp('**********************************************');
pause( 1);
disp( 'Opening Device indexed at 0');
Index = OpenByIndex(fo,0);
pause( 1);
[desc_response_flag, description] = GetDescription(fo);
disp('DEVICE DESCRIPTION:');
disp(description);

[serial_num_response_flag, serial_num] = GetSerialNumber(fo);
disp( 'SERIAL NUMBER:');
disp(serial_num);

hash_code = GetHashCode(fo);
disp( 'RANDOM HASH CODE:');
disp(hash_code);
disp('**********************************************');
CyclePort(fo);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Any help would be highly appreciated, please.

David T

stephane poujouly

Roger M. Ellingson

Andrew,
I have not experienced this problem. It has been suggested that this security issue could be related to the incorrect version of the Microsoft .Net Framework that is installed on your machine. I probably used v3.5 when testing this demo. Now I think the version is 4.0. I generally try to use the latest version.

BTW, I posted an updated demo:
FTD2XX_NET_Write_GetPinStates
that should appear in a few days. It demos both writing and reading the USB245 using the .Net dll.

Roger.

Andrew

Looks great. However, I seem to be missing something fundamental about using the .NET assembly. I get this error:

Message: System.Security.Permissions.SecurityPermission
Source: FTD2XX_NET

The methodsview( 'FTD2XX_NET.FTDI'); works just fine, so I clearly am pointing to the DLL. I

Any advice would be greatly appreciated. Thanks,

Roger M. Ellingson

Hi Gianluca,

Finally got system up to look into your issue.

Here is some Matlab help on the subject: "Creating .NET Arrays in MATLAB" http://www.mathworks.com/help/techdoc/matlab_external/brxe1ww-1.html

Following are some quick hacks to get the Device List Info.

I hope this helps. Roger.

%How many devices max in your system
numDevicesMax = 5

%Declare an array in Matlab
myArray = NET.createArray('FTD2XX_NET.FT_DEVICE_INFO_NODE', numDevicesMax)

%Call the method of interest
r = fo.GetDeviceList(myArray)

%Look at the first member of array
myArray(1)

ans =

FTD2XX_NET.FT_DEVICE_INFO_NODE handle
Package: FTD2XX_NET

Properties:
Flags: 1
Type: [1x1 FTD2XX_NET.FT_DEVICE]
ID: 67330049
LocId: 2097
SerialNumber: [1x1 System.String]
Description: [1x1 System.String]
ftHandle: [1x1 System.IntPtr]

Methods, Events, Superclasses

Gianluca

Great!
I'm new with USB controller and Matlab.
Could you give me some help?
I'm using Matlab R2009b version.

When I do
f = NET.addAssembly
fo = FTD2XX_NET.FTDI

then

methodsview( 'FTD2XX_NET.FTDI');

as you correcly wrote, a list of possible methods are displayed.

Now, I want to use the function
GetDeviceList
I don't understand the meaning of the variable in the help showed up with methodsview function.

I tried
[a,b] = fo.GetDeviceList

but this error message appears:
??? No method 'GetDeviceList' with matching signature found for class
'FTD2XX_NET.FTDI'.

How can I know what is the error?
Have you already faced off this problem?

Thank you very much

Gianluca Radaelli

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: FTD2XX_NET_Write_GetPinStates

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!