Unable to read from FTDI device using calllibrary function
古いコメントを表示
I am trying to read values from a FTDI device. I am using loadlibrary and calllib functions.
loadlibrary('ftd2xx64.dll','myheader.h','addheader', 'ftd2xx.h');
libfunctionsview ('ftd2xx64')
%% open handle
handle = uint32(0);
ptr_handle = libpointer('voidPtrPtr',handle);
[err] = calllib('ftd2xx64', 'FT_Open', int32(0), ptr_handle);
%% Write temp command
temp_req_id='*meas:tempe\r';
temp_req = [int8(temp_req_id) 0];
size_temp_req = uint32(strlength(temp_req_id));
bytes_written = libpointer('uint32Ptr',0);
err = calllib('ftd2xx64', 'FT_Write',ptr_handle,temp_req,size_temp_req,bytes_written);
bytes_written.Value
%% Get queue status
queue_size = libpointer('uint32Ptr',99);
[err] = calllib('ftd2xx64', 'FT_GetQueueStatus', ptr_handle, queue_size);
queue_size.Value
Photo from program documentation

When I do write command i expect to receive the temperature value from the device using read command. But after write the status of queue buffer remains 0 so I have nothing to read from the queue. But the device acknowledges that number of bytes written was 13.
To check is the value of queue_size is getting updated i tried to initialize the value of queue_size to 99. but the output was 0.
What could be wrong with the code?
I have attached the header an library for reference. any help is kindly appreciated.
1 件のコメント
Tobias Ammann
2023 年 6 月 29 日
編集済み: Tobias Ammann
2023 年 6 月 29 日
Hello Kumar,
glad to hear that you solved your problem. I try to load the ftd2xx64 library in matlab also. However i end up with the following warnings:
Warning: The data type 'error' used by function FT_IoCtl does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_ReadFile does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_WriteFile does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_GetOverlappedResult does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_ClearCommError does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_GetCommState does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_SetCommState does not exist.
> In loadlibrary
Warning: The data type 'error' used by function FT_W32_WaitCommEvent does not exist.
> In loadlibrary
Did you see these warnings also?
[notfound,warnings] = loadlibrary('ftd2xx64', 'ftd2xx.h');
Closer examination of the contents in the 'warnings' variable shows a view thousand warnings of this kind:
Function pointer types are unsupported in structures HRESULT ( __stdcall * QueryInterface ) ( IPrintDialogServices * .
Found on line 306997 of input from line 997 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\commdlg.h
Function pointer types are unsupported in structures HRESULT ( __stdcall * GetCurrentDevMode ) ( IPrintDialogServices * .
Found on line 306997 of input from line 997 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\commdlg.h
Function pointer types are unsupported in structures HRESULT ( __stdcall * GetCurrentPrinterName ) ( IPrintDialogServices * .
Found on line 306997 of input from line 997 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\commdlg.h
Function pointer types are unsupported in structures HRESULT ( __stdcall * GetCurrentPortName ) ( IPrintDialogServices * .
Found on line 306997 of input from line 997 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\commdlg.h
Type 'intWCHAR__unalignedPtr' was not found. Defaulting to type voidPtr.
Found on line 307589 of input from line 316 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\stralign.h
Type 'LARGE_INTEGER' was not found. Defaulting to type error.
Found on line 308611 of input from line 685 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsvc.h
Type 'LARGE_INTEGER' was not found. Defaulting to type error.
Found on line 308611 of input from line 685 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsvc.h
Type 'LPOVERLAPPED' was not found. Defaulting to type error.
Any suggestions?
Regards,
Tobias
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!