Adlink PCI 9221 encoder driver for real time simulink

1 visualizzazione (ultimi 30 giorni)
Hello. I have a ADLINK PCI 9221 board and A/B/Z encoder. In simulink i can only use input an output blocks for modelling but not for encoder mode. Encoder i can initialize in Workspace by writing this code:
clc clear all; close all; addpath('../PCIDASK'); %check x64 or x86 if strcmp(computer('arch'),'win64') DLL = 'PCI-Dask64.dll'; HEADER = 'Dask64_forMatlab.h'; LIB = 'dasklib'; else DLL = 'PCI-Dask.dll'; HEADER = 'Dask_forMatlab.h'; LIB = 'dasklib'; end %check DLL and HEADER if ~exist(DLL,'file') ~exist(HEADER,'file') fprintf('DLL or HEADER is not found here\n'); return; end %check lib loading if ~libisloaded(LIB) [notfound,warnings] = loadlibrary(DLL,HEADER,'alias',LIB); if ~libisloaded(LIB) fprintf('Load lib failed\n'); return; end end %% card_type = PCIDASK.PCI_9221;%PCI_9221 card_num = uint16(0); GCtr = uint16(0); % PCI-9221: 0 to 1 Mode = bitor(PCIDASK.x4_AB_Phase_Encoder, hex2dec('000')); % CW_CCW_Encoder 0x0c '00c'; x1_AB_Phase_Encoder 0x0d '00d'; x2_AB_Phase_Encoder 0x0e '00e'; x4_AB_Phase_Encoder 0x0f '00f'; Phase_Z 0x10 '010' (Use bitor for Phase_Z) SrcCtrl = uint16(0); % Not used in encoder PolCtrl = uint16(0); % Not used in encoder LReg1_Val = uint32(0); % Not used in encoder LReg2_Val = uint32(0); % Not used in encoder RD_Value = uint32(0); %% %=== Typical Main procedure === card = calllib(LIB,'Register_Card',card_type,card_num); if card < 0 error = card; unloadlibrary(LIB); fprintf('Register_Card failed with error code %d\n', error); return; end %Clear Encoder% error = calllib(LIB,'GPTC_Clear', card, GCtr); if error < 0 calllib(LIB,'GPTC_Clear', card, GCtr); calllib (LIB,'Release_Card', card); unloadlibrary(LIB); fprintf('GPTC_Clear failed with error code %d\n', error); return; end %Setup Encoder% error = calllib(LIB,'GPTC_Setup',card, GCtr, Mode, SrcCtrl, PolCtrl, LReg1_Val, LReg2_Val); if error < 0 calllib(LIB,'GPTC_Clear', card, GCtr); calllib(LIB,'Release_Card',card); unloadlibrary(LIB); fprintf('GPTC_Setup failed with error code %d\n', error); return; end %Enable Encoder% error = calllib(LIB,'GPTC_Control', card, GCtr, PCIDASK.IntENABLE, 1); if error < 0 calllib(LIB,'GPTC_Clear', card, GCtr); calllib(LIB,'Release_Card', card); unloadlibrary(LIB); fprintf('GPTC_Control failed with error code %d\n', error); return; end %Set Timer% tic; timer_0 = toc; fprintf('Start Encoder, press anykey on figure to stop\n');
% Here is like kbhit() in C code , press anykey to exit loop fighit = figure('keypressfcn',@(obj,ev) set(obj,'userdata',1));
while isempty(get(fighit,'userdata')) %Enable Encoder% [error, RD_Value] = calllib(LIB,'GPTC_Read', card, GCtr, RD_Value); if error < 0 calllib(LIB,'GPTC_Control', card, GCtr, PCIDASK.IntENABLE, 0); calllib(LIB,'GPTC_Clear', card, GCtr); calllib(LIB,'Release_Card', card); unloadlibrary(LIB); fprintf('GPTC_Read failed with error code %d\n', error); return; end
timer_1 = toc; fprintf('GPTC_Read: %d, press anykey on figure to stop [%.2f seconds]\n', RD_Value, double(timer_1-timer_0)); %volts = zeros(1,1000,'double'); %plot(volts);
pause(0.200); end fprintf('Stop Encoder\n');
error = calllib(LIB,'GPTC_Control', card, GCtr, PCIDASK.IntENABLE, 0); if error < 0 calllib(LIB,'GPTC_Clear', card, GCtr); calllib(LIB,'Release_Card', card); unloadlibrary(LIB); fprintf('GPTC_Control failed with error code %d\n', error); return; end
error = calllib(LIB,'GPTC_Clear', card, GCtr); if error < 0 calllib(LIB,'GPTC_Clear', card, GCtr); calllib(LIB,'Release_Card', card); unloadlibrary(LIB); fprintf('GPTC_Clear failed with error code %d\n', error); return; end
calllib(LIB,'Release_Card', card); unloadlibrary(LIB); %clear all; close all;
But as you can see this code use (functions GPTC_READ and other main functions) .dll file. And I don't understand - how can i correctly write a code in slrtdrivertool for real time measurement in my machine. Is it support external DLLs?

Risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by