Professional Documents
Culture Documents
2005-10-17
Number of pages:
15
DACAPL.DLL, a CAPL DLL to use IOcab with CANalyzer --Revision history Version 1.0.0 dated 2004-06-28 1.0.1 dated 2004-08-04
II
Editor Hb Hb
Table of contents 1 General.........................................................................................................................4 2 Installation ...................................................................................................................4 3 Usage in CAPL ............................................................................................................4 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 Variables of the CAPL program.............................................................................................5 CAPL on preStart ...................................................................................................................6 CAPL on Start ........................................................................................................................7 Setting the Analog Outputs ....................................................................................................8 Setting the Digital Outputs .....................................................................................................8 Reading the Inputs..................................................................................................................9 Using PWM Out and Capture In ..........................................................................................11 Helper Functions ..................................................................................................................11
4 DLL Functions ...........................................................................................................12 4.1 unsigned long CAPLEXPORT far CAPLPASCAL daLoadLibrary(char libraryName[])...12 4.2 int CAPLEXPORT far CAPLPASCAL daGetDeviceCount(unsigned long libHandle)......12 4.3 int CAPLEXPORT far CAPLPASCAL daGetDeviceInfo(unsigned long libHandle, int dev, char deviceName[], int n).....................................................................................................12 4.4 int CAPLEXPORT far CAPLPASCAL daOpenDevice(unsigned long libHandle, int dev)12 4.5 int CAPLEXPORT far CAPLPASCAL daCloseDevice(unsigned long libHandle, int dev)13 4.6 int CAPLEXPORT far CAPLPASCAL daPrepStartDevice(unsigned long libHandle, int dev).......................................................................................................................................13 4.7 int CAPLEXPORT far CAPLPASCAL daStartDevice(unsigned long libHandle, int dev, int reset) .....................................................................................................................................13 4.8 int CAPLEXPORT far CAPLPASCAL daStopDevice(unsigned long libHandle, int dev) .13 4.9 long CAPLEXPORT far CAPLPASCAL daGetAIValueEx2(unsigned long libHandle, long device, int channel, double value[],unsigned long time[]) ...................................................13 4.10 int CAPLEXPORT far CAPLPASCAL daGetDIValueEx2(unsigned long libHandle, long device, int channel,char value[], unsigned long time[]) .......................................................13 4.11 int CAPLEXPORT far CAPLPASCAL daSetAOValue(unsigned long libHandle, long device, int channel, double value) ........................................................................................14 4.12 int CAPLEXPORT far CAPLPASCAL daSetDOValue(unsigned long libHandle, long device, int channel, long value)............................................................................................14 4.13 int CAPLEXPORT far CAPLPASCAL daSetModeDigital(long device, int channel, unsigned long mode) ............................................................................................................14 4.14 int CAPLEXPORT far CAPLPASCAL daSetModeAnalog(long device, int channel,
dacapl_dll.doc
III
unsigned long mode, unsigned long voltRange) ..................................................................14 4.15 int CAPLEXPORT far CAPLPASCAL daSetModeTrigger(long device, unsigned long mode, unsigned long period, unsigned long source, unsigned long level) ...........................14 4.16 int CAPLEXPORT far CAPLPASCAL daSetModePWM(long device, unsigned long mode, unsigned long freq)....................................................................................................15
dacapl_dll.doc
General
The CAPL-DLL dacapl.dll will enable using an IOcab in CANalyzer. The digital and analog outputs can be set, and the digital and analog inputs can be read in a CAPL program.
Installation
1. Copy the file dacapl.dll in the exec32-directory of your CANalyzer-installation. 2. The DLL must be inserted in the list of used CAPL-DLLs. Open the options-dialog (CANalyzer menu Configuration - Options), select Application Settings CAPL DLL and add dacapl.dll to the list. 3. Make sure that the file da_iocab.dll is in the same directory and has the version 1.1.0.3 or higher.
Usage in CAPL
The usage of the dll will be explained with code examples from a CAPL-program.
dacapl_dll.doc
//timer used to poll the input-ports //timer to set the analog output-ports //timer to set the digital output-ports
//the buffers to get/set the analog/digital I/O's float prevAVal[1], curAVal[1]; char prevDVal[8], curDVal[9]; //port modes: 0 =off, 1= in, 2=out, 65 = PWM in (only valid for the 4th digital input) dword modeAnalog = 2; dword modeDigital = 1; //analog input voltage range dword voltSel = 0; //pwm-settings dword pwmMode =2; dword pwmFreq =1250; //trigger settings dword trigMode = dword trigPeriod = dword trigSource = dword trigLevel = } selection: 0 ( high voltage) or 1 (low voltage)
//see port modes //scanner frequency, valid = 1250, 2500, 5000, 10000
1; 1; 4; 0;
//1=polling with pll. period, 2=trigger on rising edge, 3=trigger on falling edge, 4= trigger on rising/falling edge //polling period in ms //trigger source (only valid for trigger mode 2-4): 0-3 = digital in 0-3, 4=analog in 4 //trigger level in mV (only valid for source =4)
dacapl_dll.doc
dacapl_dll.doc
write("da_iocab device #%d open result = 0x%x",usedDevice, result); if(0==result) { result = daPrepStartDevice(hIOcab,usedDevice); write("da_iocab device #%d prep. start result = 0x%x",usedDevice, result); } if(0!=result) { write("da_iocab device #%d could not be opened!",usedDevice); } } else { write("da_iocab device #%d is not found!",usedDevice); } } }
dacapl_dll.doc
dacapl_dll.doc
dacapl_dll.doc
DACAPL.DLL, a CAPL DLL to use IOcab with CANalyzer --tsec[0]+(float)(tsec[1])/1000000); memcpy(prevDVal, curDVal,8); } } //timestamp in seconds
10
dacapl_dll.doc
11
with pwmMode = 2 (output, see also chapter CAPL on preStart). The frequency and duty cycle can be set with:
float frequency = 100; //frequency in Hz float duty = 0.5; //duty cycle int result; result = daSetAOValue(hIOcab,usedDevice, 4, frequency); result = daSetAOValue(hIOcab,usedDevice, 5, duty);
If DPWM shall be used to capture a signal, then the DPWM must be configured as input:
daSetModePWM(usedDevice,pwmMode,pwmFreq);
with pwmMode = 1 (use the DPWM pin as input), or with pwmMode = 65 (use the DIO4 as input). The frequency and duty cycle can be read with:
dword tsec[2]; long result; result = daGetAIValueEx2(hIOcab,usedDevice,4,curAVal, tsec); result = daGetAIValueEx2(hIOcab,usedDevice,5,curAVal, tsec); //get the frequency //get the duty cycle
dacapl_dll.doc
DACAPL.DLL, a CAPL DLL to use IOcab with CANalyzer --} return 1; } memcpy(char m[], char n[], int s) { for(;s>0;--s) { m[s-1]=n[s-1]; } }
12
DLL Functions
4.1 unsigned long CAPLEXPORT far CAPLPASCAL daLoadLibrary(char libraryName[]) Loads the library 'libraryName'. Returns the handle or 0 in case of an error. 4.2 int CAPLEXPORT far CAPLPASCAL daGetDeviceCount(unsigned long libHandle) Returns the device count of the attached devices, which are supported from the loaded DLL. 4.3 int CAPLEXPORT far CAPLPASCAL daGetDeviceInfo(unsigned long libHandle, int dev, char deviceName[], int n) Copies the device info-string in deviceName. Returns 0 if ok, else !=0. Use this function to find out if the device is operable, and the device name. 4.4 int CAPLEXPORT far CAPLPASCAL daOpenDevice(unsigned long libHandle, int dev) Opens the device. Returns 0 if ok, else !=0. This function must be called before the device can be used.
dacapl_dll.doc
13
4.5 int CAPLEXPORT far CAPLPASCAL daCloseDevice(unsigned long libHandle, int dev) Closes the device. Returns 0 if ok, else !=0. 4.6 int CAPLEXPORT far CAPLPASCAL daPrepStartDevice(unsigned long libHandle, int dev) daPrepStartDevice must be called one time in CAPL-PrepStart. The device initializes the measurement. Returns 0 if ok, else !=0. 4.7 int CAPLEXPORT far CAPLPASCAL daStartDevice(unsigned long libHandle, int dev, int reset) daPrepStartDevice must be called one time in CAPL-Start. Returns 0 if ok, else !=0. 4.8 int CAPLEXPORT far CAPLPASCAL daStopDevice(unsigned long libHandle, int dev) daPrepStartDevice must be called one time in CAPL-StopMeasurement. Returns 0 if ok, else !=0. 4.9 long CAPLEXPORT far CAPLPASCAL daGetAIValueEx2(unsigned long libHandle, long device, int channel, double value[],unsigned long time[]) Reads one analog port and stores the value in 'value[]'
The timestamp of the value (that means the time when the port is read) is stored in time[0] (the seconds) and time[1] (the microseconds). The timestamp is set to 0 if the driver does not support this function. Returns 0 if ok, else !=0. 4.10 int CAPLEXPORT far CAPLPASCAL daGetDIValueEx2(unsigned long libHandle, long device, int channel,char value[], unsigned long time[]) Reads one digital port and stores the value in 'value[]'. The timestamp of the value ( that means the time when the port is read) is stored in time[0] (the seconds) and time[1] (the microseconds).
dacapl_dll.doc
DACAPL.DLL, a CAPL DLL to use IOcab with CANalyzer --The timestamp is set to 0 if the driver does not support this function. Returns 0 if ok, else !=0.
14
4.11 int CAPLEXPORT far CAPLPASCAL daSetAOValue(unsigned long libHandle, long device, int channel, double value) Sets one analog port. Returns 0 if ok, else !=0. 4.12 int CAPLEXPORT far CAPLPASCAL daSetDOValue(unsigned long libHandle, long device, int channel, long value) Sets one digital port Returns 0 if ok, else !=0. 4.13 int CAPLEXPORT far CAPLPASCAL daSetModeDigital(long device, int channel, unsigned long mode) Sets the configuration for one device. The data will be stored in an ini-file which is located in the exec32-directory. Must be called before calling OpenDevice Returns 0 if ok, else !=0. 4.14 int CAPLEXPORT far CAPLPASCAL daSetModeAnalog(long device, int channel, unsigned long mode, unsigned long voltRange) Sets the configuration for one device. The data will be stored in an ini-file which is located in the exec32-directory. Must be called before calling OpenDevice Returns 0 if ok, else !=0. 4.15 int CAPLEXPORT far CAPLPASCAL daSetModeTrigger(long device, unsigned long mode, unsigned long period, unsigned long source, unsigned long level) Sets the configuration for one device. The data will be stored in an ini-file which is located in the exec32-directory. Must be called before calling OpenDevice Returns 0 if ok, else !=0.
dacapl_dll.doc
15
4.16 int CAPLEXPORT far CAPLPASCAL daSetModePWM(long device, unsigned long mode, unsigned long freq) Sets the configuration for one device. The data will be stored in an ini-file which is located in the exec32-directory. Must be called before calling OpenDevice Returns 0 if ok, else !=0.
dacapl_dll.doc