usb-ttl-in8-out8 | deditec manual · description of the delib integration in visual-c/c++ the delib...
TRANSCRIPT
INDEX
Index | 2Seite
1. Introduction 6
1.1. General remarks 6
1.2. Customer satisfaction 6
1.3. Customer response 6
2. Hardware description 8
2.1. Technical data 8
2.2. Pin assignment 9
3. Firmware update 11
3.1. DEDITEC Flasher 11
4. Software 15
4.1. Using our products 15
154.1.1. Access via graphical applications 154.1.2. Access via the DELIB driver library 154.1.3. Access via protocol 164.1.4. Access via provided test programs
4.2. DELIB driver library 17
174.2.1. Overview 174.2.1.1. Program under diverse operating systems
184.2.1.2. Program with diverse programming languages
184.2.1.3. Program independent of the interface
184.2.1.4. SDK-Kit for Programmer
194.2.2. Supported operating systems 194.2.3. Supported programming languages 204.2.4. Installation DELIB driver library 224.2.5. DELIB Configuration Utility
4.3. Integration of the DELIB 23
234.3.1. Integration of the delib.h in Visual-C/C++ 264.3.2. Integration of the delib.cs in Visual-C#
INDEX
Index | 3Seite
274.3.3. Integration of the delib.cs in Visual-C# unter Windows 64bit 314.3.4. Integration of the delib.pas in Delphi 324.3.5. Integration of the delib.bas in Visual Basic 334.3.6. Integration of the delib.vb in VB.NET 344.3.7. Integration of the delib.bas in MS-Office (VBA) 364.3.8. Integration of the delib.dll in LabVIEW 364.3.8.1. Integration of the delib.dll in LabVIEW
454.3.8.2. Usage of the VIs in LabVIEW
4.4. Test programs 47
474.4.1. Digital Input-Output Demo 5. DELIB API reference 49
5.1. Management functions 49
495.1.1. DapiOpenModule 505.1.2. DapiCloseModule 515.1.3. DapiGetDELIBVersion 525.1.4. DapiSpecialCMDGetModuleConfig 545.1.5. DapiOpenModuleEx
5.2. Error handling 55
555.2.1. DapiGetLastError 565.2.2. DapiGetLastErrorText
5.3. Reading Digital inputs 57
575.3.1. DapiDIGet1 585.3.2. DapiDIGet8 595.3.3. DapiDIGet16 605.3.4. DapiDIGet32 615.3.5. DapiDIGet64 625.3.6. DapiDIGetFF32 635.3.7. DapiDIGetCounter 645.3.8. DapiSpecialCounterLatchAll 655.3.9. DapiSpecialCounterLatchAllWithReset 665.3.10. Dapi_Special_DI_FF_Filter_Value_Get 675.3.11. Dapi_Special_DI_FF_Filter_Value_Set
5.4. Setting Digital outputs 68
685.4.1. DapiDOSet1_WithTimer
INDEX
Index | 4Seite
695.4.2. DapiDOSet1 705.4.3. DapiDOSet8 715.4.4. DapiDOSet16 725.4.5. DapiDOSet32 735.4.6. DapiDOSet64 745.4.7. DapiDOReadback32 755.4.8. DapiDOReadback64
5.5. Example program 76
6. Appendix 79
6.1. Revisions 79
6.2. Copyrights and trademarks 80
Introduction |Seite 6
1. Introduction
1.1. General remarks
First of all, we would like to congratulate you to the purchase of a high qualityDEDITEC product.
Our products are being developed by our engineers according to qualityrequirements of high standard. Already during design and development we takecare that our products have -besides quality- a long availability and an optimalflexibility.
Modular design
The modular design of our products reduces the time and the cost of development.Therefor we can offer you high quality products at a competitive price.
Availability
Because of the modular design of our products, we have to redesign only a moduleinstead of the whole product, in case a specific component is no longer available.
1.2. Customer satisfaction
Our philosophy: a content customer will come again. Therefor customersatisfaction is in first place for us.
If by any chance, you are not content with the performance of our product, pleasecontact us by phone or mail immediately.
We take care of the problem.
1.3. Customer response
Our best products are co-developments together with our customers. Therefor weare thankful for comments and suggestions.
Hardware description |Seite 8
2. Hardware description
The USB - I/O Interface conduces to a simplification of the well complex data of theUSB-Bussystem. Commands such as "8-bit data write" and "8-bit data read" willbe transmitted to the 16 in-/outputs by the provided driver library.
2.1. Technical data
Input current: ~53 mA
USB 2.0 / 1.1
8*TTL-Input
8*TTL-Output
Simple response under Windows
Hardware description |Seite 9
2.2. Pin assignment
Pin Pin
1 VCC 2 LED
3 GND 4 GND
5 IN6 6 IN 7
7 IN 4 8 IN 5
9 IN 2 10 IN 3
11 IN 0 12 IN 1
13 OUT 0 14 OUT1
15 OUT 2 16 OUT3
17 OUT4 18 OUT5
19 OUT6 20 OUT7
21 AD3 22 AD2
23 AD1 24 AD0
25 GND 26 VREF
Firmware update |Seite 11
3. Firmware update
3.1. DEDITEC Flasher
You can find the latest firmware version for your DEDITEC product always at thedownload section of our homepage.
( -> http://www.deditec.de/en/module/downloads/firmware-updates.html )
Approach after download
Unzip the ZIP archive
Start the program deditec-flasher.exe
The following application will be opened:
You can find a detailed description of the available commands on the followingpage.
Firmware update |Seite 12
1. Select the Interface of the module of the RO-Series
Command (Key) Interface
U USB-Interface
S Serial Interface (RS-232 / RS-485)
C CAN-Interface
E Ethernet-Interface
V USB2-Interface
Note:
1) The current selected interface will be displayed in the last line (Selected Device= USB)
2) Press key Q to flash "non-RO-Series-products" (USB-Mini-Sticks, USB-Logi-500, ..)
3) In order to flash products of the RO-CAN-Series, you have to connect themodule with your PC via the CAN/SER adapter.
2. Additional options
Command (Key) Description
D Flasher runs in DEBUG mode
Therefore, additional information will be displays
P Reads the current firmware of connected DEDITECproducts
3. Select the module which you want to flash (RO-Series only)
Command (Key) Description
M Flash the RO-Interface module
A Flash all AD16, AD16-DA4, DA4 or AD16_ISO submodules
B Flash all DA2_ISO sub modules
G Flash all STEPPER2 sub modules
H Flash all O8-R8 or M16 sub modules
I Flash all PT100 sub modules
J Flash all CNT8 or CNT/IGR sub modules
Z Scan the module for available sub modules
Software |Seite 15
4. Software
4.1. Using our products
4.1.1. Access via graphical applications
We provide driverinterfaces e.g. for LabVIEW and ProfiLab. The DELIB driverlibrary is the basis, which can be directly activated by ProfiLAB.
For LabVIEW, we provide a simple driver connection with examples!
4.1.2. Access via the DELIB driver library
In the appendix, you can find the complete function reference for the integration ofour API-functions in your software. In addition we provide examples for thefollowing programming languages:
C
C++
C#
Delphi
VisualBasic
VB.NET
MS-Office
4.1.3. Access via protocol
The protocol for the activation of our products is open source. So you are able touse our products on systems without Windows or Linux.
Software |Seite 16
4.1.4. Access via provided test programs
We provide simple handling test programs for the most important functions of ourproducts. These will be installed automatically by the installation of the DELIBdriver library.
So you can test directly e.g. relays or you can check the voltage of an A/Dconverter.
Software |Seite 17
4.2. DELIB driver library
4.2.1. Overview
The following figure explains the structure of the DELIB driver library
The DELIB driver library allows an uniform response of DEDITEC hardware withparticular consideration of the following viewpoints:
Independent of operating system
Independent of programming language
Independent of the product
4.2.1.1. Program under diverse operating systems
The DELIB driver library allows an uniform response of our products on diverseoperating systems.
We has made sure, that all of our products can be responded by a few commands.Whatever which operating system you use. - Therefore the DELIB cares!
Software |Seite 18
4.2.1.2. Program with diverse programming languages
We provide uniform commands to create own applications. This will be solved bythe DELIB driver library.
You choose the programming language!
It can be simply developed applications under C++, C, Visual Basic, Delphi orLabVIEW®.
4.2.1.3. Program independent of the interface
Write your application independent of the interface !
Program an application for an USB product of us. - Also, it will work with anethernet or RS-232 product of us !
4.2.1.4. SDK-Kit for Programmer
Integrate the DELIB in your application. On demand you receive an installationscript for free, which allows you, to integrate the DELIB installation in yourapplication.
Software |Seite 19
4.2.2. Supported operating systems
Our products support the following operating systems:
Windows 7
Windows Vista
Windows XP
Windows 2000
Linux
4.2.3. Supported programming languages
Our products are responsive via the following programming languages:
C
C++
C#
Delphi
VisualBasic
VB.NET
MS-Office
Software |Seite 20
4.2.4. Installation DELIB driver library
Start screen of the DELIB installer
Insert the DEDITEC driver CD into the drive and start „delib_install.exe“. TheDELIB driver library is also available on http://www.deditec.en/delib
Click on „Install“.
Software |Seite 21
The drivers will be installed.
The DELIB driver library is now installed. Press „Close“ to finish the installation.
You can configure your module with the „DELIB Configuration Utility“ (see nextchapter). This is only necessary, if more than one module is present.
Software |Seite 22
4.2.5. DELIB Configuration Utility
Start the “DELIB Configuration Utility” as follows:
Start Programs DEDITEC DELIB DELIB Configuration Utility.
The „DELIB Configuration Utility“ is a program to configure and subdivideidentical USB-modules in the system. This is only necessary if more than onemodule is present.
Software |Seite 23
4.3. Integration of the DELIB
4.3.1. Integration of the delib.h in Visual-C/C++
Description of the DELIB integration in Visual-C/C++
The DELIB Installation defines environment variables to facilitate links to theDELIB-include and DELIB-lib directory.
DELIB_LIB = C:\Programs\DEDITEC\DELIB\lib
DELIB_INCLUDE = C:\Programs\DEDITEC\DELIB\include
Start Visual-C/C++ and open via menu "Projekt -> Einstellungen"
Software |Seite 24
DELIB.H entry in the Visual-C/C++ Project configurations
Under the tab "C/C++" choose the "Kategorie" Präprozessor and enter on"Zusätzliche Include Verzeichnisse" "$(DELIB_INCLUDE)".
Software |Seite 25
DELIB.LIB entry in the Visual-C/C++ Project configurations
Under the tab "Linker" extend the existing line in "Zusätzliche IncludeVerzeichnisse" with the ending "$(DELIB_LIB)\delib.lib"
Software |Seite 26
4.3.2. Integration of the delib.cs in Visual-C#
Description of the DELIB integration in Visual-C#
You can find the needed files for Visual-C# in the directory C:\Programme\DEDITEC\DELIB\Include\delib.cs. Start Visual-C# and open viamenu "Projekt -> Vorhandes Element hinzufügen" in the directory C:\Programme\DEDITEC\DELIB\Include\ the file "delib.cs" to import.
Add the following reference in your program:using DeLib;
Software |Seite 27
4.3.3. Integration of the delib.cs in Visual-C# unter Windows 64bit
Program sample for the DELIB driver library under Windows 64 Bit
In the following sections there is a description how to compile the project as "x86"
Show all settings
Open the options via menue "Extras -> Optionen"
Check “Alle Einstellungen anzeigen"
Software |Seite 28
Check under "Projekte und Projektmappen" "Erweiterte Buildkonfigurationenanzeigen".
Software |Seite 29
The Configuration Manager
Open the configuration manager via "Any CPU -> Konfigurations-Manager...".
In the configuration manager select under der column "Plattform" "Any CPU ->Neu...".
Under "Neue Plattform" select "x86".
Software |Seite 30
Start debugging
You can start the debugging as normal via the "Start-Button". Note that the toolbarcombobox for Platform Configuration now lists both "x86" and "AnyCPU" and has"x86" selected
Software |Seite 31
4.3.4. Integration of the delib.pas in Delphi
Description of the "delib.pas" integration in Delphi
You can find the needed files for Delphi in the directory C:\Programme\DEDITEC\DELIB\include\delib.pas.
Start Delphi and open via menu "Projekt -> dem Projekt hinzufügen" the file "delib.pas" to import.
Software |Seite 32
4.3.5. Integration of the delib.bas in Visual Basic
Description of the "delib.bas" integration in Visual Basic
You can find the needed files for VB in the directory C:\Programme\DEDITEC\DELIB\include\delib.bas.
Start Visual Basic and open via menu "Projekt -> Datei hinzufügen..." the file"delibi.bas" to import.
Software |Seite 33
4.3.6. Integration of the delib.vb in VB.NET
Description of the DELIB integration in VB.NET
You can find the needed files for VB.NET in the directory C:\Programme\DEDITEC\DELIB\Include\delib.vb. Start VB.NET and open via menu"Projekt -> Vorhandes Element hinzufügen" in the directory C:\Programme\DEDITEC\DELIB\Include\ the file "delib.vb" to import.
Software |Seite 34
4.3.7. Integration of the delib.bas in MS-Office (VBA)
Description of the "delib.bas" integration in Visual Basic for Applications
You can find the needed files for VBA in the directory C:\Programme\DEDITEC\DELIB\include\delib.bas.
Start Microsoft Excel and open via menu "Extras -> Makro -> Visual Basic Editor".
Software |Seite 35
Creation of UserForm
Create a new UserForm via menu "Einfügen -> UserForm". In the top left-handcorner of the project manager right click on "UserForm -> Datei importieren". Openin the directory C:\Programme\DEDITEC\DELIB\include the file "delib.bas" toimport.
Software |Seite 36
4.3.8. Integration of the delib.dll in LabVIEW
4.3.8.1. Integration of the delib.dll in LabVIEW
The LabVIEW-Sampleprogram "Deditec_Modul_Control.vi" is not a EXE-File andyou need to execute this file the LabVIEW development environment.
Description of the delib.dll integration in LabVIEW Version 11
- You can find the needed files for LabVIEW in the directorys
"C:\Windows\System32\delib.dll" and "C:\Programme\DEDITEC\DELIB\include\ delib.h"
- Start LabVIEW and open the menu "Tools -> Import -> DLL ..."
Software |Seite 38
- In the next window, choose the path to the delib.h and delib.dll and press continue
Software |Seite 39
- Press continue again
- The Header-File will now be analized. Afterwards press continue.
Software |Seite 40
- Follow the instructions and configurate the name and the saving location for theVIs.
Software |Seite 41
- In the new window choose "Easy error correction" in the drop-down menu andpress continue.
Software |Seite 42
- VIs which are working with 64-bit values must be edited. The display must bechanged from "unsigned long" to "unsigned quad".
- The following VIs must be edited:
-> DapiCNT48CounterGet48 (function return)
-> DapiDIGet64 (function return)
-> DapiDOSet64 (data)
-> DapiDOReadBack64 (function return)
Software |Seite 43
- In addition for some VIs you need to change the elementype to "numeric".
- The following VIs must be edited:
-> DapiWriteLongLong (value)
-> DapiReadLongLong (function return)
- Afterwards press continue.
Software |Seite 44
- You recive a summary of the executed steps.
- Press continue
- The VIs will now be created and are ready to use.
Software |Seite 45
4.3.8.2. Usage of the VIs in LabVIEW
Some functions of the DELIB-library are expecting a string as a parameter value.
This example shows how to use such functions in LabVIEW.
We will use the A/D converter function which is used to set the voltage range as anexample.
The definition of this function is:void DapiADSetMode(ULONG handle, ULONG ch, ULONG mode);
The voltage ranges for this function are already defined in the DELIB-library.
Example code in C/C++:DapiADSetMode(handle, 0, ADDA_MODE_UNIPOL_5V);
This code can also be written like this:DapiADSetMode(handle, 0, 1);
In the delib.h file can you read the hexadecimal values to determine the modes.The hex values must be convertet to decimal.
After the installation of the DELIB-library, the delib.h file is located in the followingdirectory: C:\Programs\Deditec\DELIB\Include\delib.h
Software |Seite 46
The function could look like this in LabVIEW:
The channel and mode are passed as unsigned long
Software |Seite 47
4.4. Test programs
4.4.1. Digital Input-Output Demo
Start “Digital Input-Output Demo” as follows:
Start Programme DEDITEC DELIB Digital Input-Output Demo.
The screenshot shows a test of the RO-USB-O64-R64. The configuration of themodule (64 inputs and 64 outputs) is shown on the upper left side.
DELIB API reference |Seite 49
5. DELIB API reference
5.1. Management functions
5.1.1. DapiOpenModule
Description
This function opens a particular module.
Definition
ULONG DapiOpenModule(ULONG moduleID, ULONG nr);
Parameters
moduleID=Specifies the module, which is to be opened (see delib.h)
nr=Indicates No of module which is to be opened.
nr=0 -> 1. module
nr=1 -> 2. module
Return value
handle=handle to the corresponding module
handle=0 -> Module was not found
Remarks
The handle returned by this function is needed to identify the module for all otherfunctions.
Example program
// USB-Modul öffnenhandle = DapiOpenModule(RO_USB1, 0);printf("handle = %x\n", handle);if (handle==0){// USB Modul wurde nicht gefundenprintf("Modul konnte nicht geöffnet werden\n");return;}
DELIB API reference |Seite 50
5.1.2. DapiCloseModule
Description
This command closes an opened module.
Definition
ULONG DapiCloseModule(ULONG handle);
Parameters
handle=This is the handle of an opened module
Return value
none
Example program
// Close the moduleDapiCloseModule(handle);
DELIB API reference |Seite 51
5.1.3. DapiGetDELIBVersion
Description
This function returns the installed DELIB version.
Definition
ULONG DapiGetDELIBVersion(ULONG mode, ULONG par);
Parameters
mode=Mode, with which the version is readout (must be 0).
par=This parameter is not defined (must be 0).
Return value
version=Version number of the installed DELIB version [hex].
Example program
version = DapiGetDELIBVersion(0, 0);//Bei installierter Version 1.32 ist version = 132(hex)
DELIB API reference |Seite 52
5.1.4. DapiSpecialCMDGetModuleConfig
Description
This command returns the hardware equipment (number of in-/output channels) ofthe module.
Definition
ULONG DapiSpecialCommand(ULONG handle,DAPI_SPECIAL_CMD_GET_MODULE_CONFIG, par, 0, 0);
Parameters
handle=This is the handle of an open module.
Get number of digital input channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DI
Get number of digital output channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DO
Get number of digital in-/output channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DX
Get number of analog input channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_AD
Get number of analog output channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DA
Get number of stepper channels
par=DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_STEPPER
DELIB API reference |Seite 53
Return value
Get number of digital input channels
return=Number of digital input channels
Get number of digital output channels
return=Number of digital output channels
Get number of digital in-/output channels
return=Number of digital in-/output channels
Get number of analog input channels
return=Number of analog input channels
Get number of analog output channels
return=Number of analog output channels
Get number of stepper channels
return=Number of stepper channels
Example program
ret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DI, 0, 0);//Gibt die Anzahl der digitalen Eingangskanäle zurückret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DO, 0, 0);//Gibt die Anzahl der digitalen Ausgangskanäle zurückret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DX, 0, 0);//Gibt die Anzahl der digitalen Ein-/Ausgangskanäle zurückret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_AD, 0, 0);//Gibt die Anzahl der analogen Eingangskanäle zurückret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_DA, 0, 0);//Gibt die Anzahl der analogen Ausgangskanäle zurückret=DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_GET_MODULE_CONFIG,DAPI_SPECIAL_GET_MODULE_CONFIG_PAR_STEPPER, 0, 0);//Gibt die Anzahl der Stepperkanäle zurück
DELIB API reference |Seite 54
5.1.5. DapiOpenModuleEx
Description
This function opens a specific RO-ETH-module.The particularity of this commandis, that parameters like IP-address and portnumber can be specified.
Definition
ULONG DapiOpenModuleEx(ULONG moduleID, ULONG nr, unsigned char*exbuffer);
Parameters
moduleID=Specifies the module, which is to be opened (see delib.h)
nr=Indicates No of module which is to be opened.
nr=0 -> 1. module
nr=1 -> 2. module
exbuffer=buffer for IP-adresse and port
Return value
handle=handle to the corresponding module
handle=0 -> Module was not found
Remarks
The handle returned by this function is needed to identify the module for all otherfunctions.
Currently, this command is only supported by our RO-ETH-Series.
Example program
// Open ETH-Module with parameter
DAPI_OPENMODULEEX_STRUCT open_buffer;
strcpy((char*) open_buffer.address, "192.168.1.10");open_buffer.portno = 0;
handle = DapiOpenModuleEx(RO_ETH, 0, (unsigned char*) &open_buffer);printf("Module handle = %x\n", handle);
DELIB API reference |Seite 55
5.2. Error handling
5.2.1. DapiGetLastError
Description
This function returns the last registered error.
Definition
ULONG DapiGetLastError();
Parameters
None
Return value
Error code
0=no error. (see delib.h)
Example program
ULONG error;error=DapiGetLastError();if(error==0) return FALSE;printf("ERROR = %d", error);
DELIB API reference |Seite 56
5.2.2. DapiGetLastErrorText
Description
This function reads the text of the last registered error.
Definition
extern ULONG __stdcall DapiGetLastErrorText(unsigned char * msg, unsigned longmsg_length);
Parameters
msg = text buffer
msg_length = length of the buffer
Example program
BOOL IsError (){ if (DapiGetLastError () != DAPI_ERR_NONE)
{ unsigned char msg[500];
DapiGetLastErrorText((unsigned char*) msg, sizeof(msg)); printf ("Error Code = %x * Message = %s\n", 0, msg); return TRUE;}
return FALSE;}
DELIB API reference |Seite 57
5.3. Reading Digital inputs
5.3.1. DapiDIGet1
Description
This command reads a single digit input.
Definition
ULONG DapiDIGet1(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the number of input that is to be read (0 ..).
Return value
State of the input (0 / 1).
DELIB API reference |Seite 58
5.3.2. DapiDIGet8
Description
This command reads 8 digital inputs simultaneously.
Definition
ULONG DapiDIGet8(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the number of the input, from which it begins to read from (0, 8, 16,24, 32, ..)
Return value
State of the read inputs.
DELIB API reference |Seite 59
5.3.3. DapiDIGet16
Description
This command reads 16 digital inputs simultaneously.
Definition
ULONG DapiDIGet16(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the number of the input, from which it begins to read from (0, 16, 32,..)
Return value
State of the read inputs.
DELIB API reference |Seite 60
5.3.4. DapiDIGet32
Description
This command reads 32 digital inputs simultaneously.
Definition
ULONG DapiDIGet32(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the number of the input, from which it begins to read from (0, 32, 64,..)
Return value
State of the read inputs.
Example program
unsigned long data;// ----------------------------------------------------// Einen Wert von den Eingängen lesen (Eingang 1-31)data = (unsigned long) DapiDIGet32(handle, 0);// Chan Start = 0printf("Eingang 0-31 : 0x%x\n", data);printf("Taste für weiter\n");getch();// ----------------------------------------------------// Einen Wert von den Eingängen lesen (Eingang 32-64)data = (unsigned long) DapiDIGet32(handle, 32);// Chan Start = 32printf("Eingang 32-64 : 0x%x\n", data);printf("Taste für weiter\n");getch();
DELIB API reference |Seite 61
5.3.5. DapiDIGet64
Description
This command reads 64 digital inputs simultaneously.
Definition
ULONGLONG DapiDIGet64(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the number of the input,from which it begins to read from (0, 64, ..)
Return value
State of the read inputs.
DELIB API reference |Seite 62
5.3.6. DapiDIGetFF32
Description
This command reads the flip-flops from the inputs and resets them. (Input statechange).
Definition
ULONG DapiDIGetFF32(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module .
ch=Specifies the number of the input, from which it begins to read from (0, 32, ..)
Return value
State of 32 input change states
DELIB API reference |Seite 63
5.3.7. DapiDIGetCounter
Description
This command reads the counter of a digital input
Definition
ULONG DapiDIGetCounter(ULONG handle, ULONG ch, ULONG mode);
Parameters
handle=This is the handle of an opened module.
ch=Specifies the digital input,from which the counter will be read.
mode=0 (Normal counter function)
mode=DAPI_CNT_MODE_READ_WITH_RESET (Reading and resetting thecounter)
mode=DAPI_CNT_MODE_READ_LATCHED (Reading the latched counter)
Return value
Value of the counter.
Example program
value = DapiDIGetCounter(handle, 0 ,0);// Reading counter of DI Chan 0
value = DapiDIGetCounter(handle, 1 ,0);// Reading counter of DI Chan 1
value = DapiDIGetCounter(handle, 8 ,0);// Reading counter of DI Chan 8
value = DapiDIGetCounter(handle, 0 ,DAPI_CNT_MODE_READ_WITH_RESET);// Reading AND resetting counter of DI Chan 0
value = DapiDIGetCounter(handle, 1, DAPI_CNT_MODE_READ_LATCHED);// Reading the latched counter of DI Chan 1
DELIB API reference |Seite 64
5.3.8. DapiSpecialCounterLatchAll
Description
This command saves the counters of all digital inputs simultaneously into atemporary storage (latch).
So, after that, the counter of the latch can be read successively.
Here, the speciality is, that it is possible to "freeze" simultaneously the counter andthe frozen counter (latch) can be read one by one.
Definition
void DapiSpecialCommand(ULONG handle, DAPI_SPECIAL_CMD_COUNTER,DAPI_SPECIAL_COUNTER_LATCH_ALL, 0, 0);
Parameters
None
Example program
DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_COUNTER,DAPI_SPECIAL_COUNTER_LATCH_ALL, 0, 0);
DELIB API reference |Seite 65
5.3.9. DapiSpecialCounterLatchAllWithReset
Description
This command saves the counters of all digital inputs simultaneously into atemporary storage (latch).
In addition, the counters of the digital inputs will be reset.
Definition
void DapiSpecialCommand(ULONG handle, DAPI_SPECIAL_CMD_COUNTER,DAPI_SPECIAL_COUNTER_LATCH_ALL_WITH_RESET, 0, 0);
Parameters
None
Example program
DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_COUNTER,DAPI_SPECIAL_COUNTER_LATCH_ALL_WITH_RESET, 0, 0);
DELIB API reference |Seite 66
5.3.10. Dapi_Special_DI_FF_Filter_Value_Get
Description
This command returns the filter [ms], in which time interval the digital inputs aresampled.
Definition
ULONG DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_DI,DAPI_SPECIAL_DI_FF_FILTER_VALUE_GET, 0, 0);
Parameters
handle=This is the handle of an opened module.
Return value
Time [ms]
Example program
value = DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_DI,DAPI_SPECIAL_DI_FF_FILTER_VALUE_GET, 0, 0);//Gibt das Zeitintervall zum Abtasten der digitalen Eingangskanäle zurück.
DELIB API reference |Seite 67
5.3.11. Dapi_Special_DI_FF_Filter_Value_Set
Description
This command sets a filter [ms], in which time interval the digital inputs aresampled.
Definition
void DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_DI,DAPI_SPECIAL_DI_FF_FILTER_VALUE_SET, ULONG time_ms, 0);
Parameters
handle=This is the handle of an opened module.
time_ms=time interval [ms], in which digital inputs are sampled.
Return value
None
Remarks
This command only supports pulse durations between 5ms and 255ms.
If no time is set, the default value (100ms) will be used.
Example program
DapiSpecialCommand(handle, DAPI_SPECIAL_CMD_DI,DAPI_SPECIAL_DI_FF_FILTER_VALUE_SET, 5, 0);// Setzt das Zeitintervall auf 5msDapiSpecialCommand(handle, DAPI_SPECIAL_CMD_DI,DAPI_SPECIAL_DI_FF_FILTER_VALUE_SET, 150, 0);// Setzt das Zeitintervall auf 150ms
DELIB API reference |Seite 68
5.4. Setting Digital outputs
5.4.1. DapiDOSet1_WithTimer
Description
This function sets a digital output (ch) to a value (data - 0 or 1) for a specified timein msec.
Definition
void DapiDOSet1_WithTimer(ULONG handle, ULONG ch, ULONG data, ULONGtime_ms);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output, from which it begins to write to (0, 32, 64, ..)
data=Specifies the data values, to write to the outputs
time_ms=Specifies the time, in which an output is set [ms]
Return value
None
Remarks
This function is only supported by our RO-O8-R8 module.
This function will lose its validity, if it is overwritten with other values.
If you want to deactivate this function, you will have to overwrite it with time_ms=0.
Example program
DapiDOSet1_WithTimer(handle, 2, 1, 1000);//Setting channel 2 for 1000msec to 1
DELIB API reference |Seite 69
5.4.2. DapiDOSet1
Description
This is the command to set a single output.
Definition
void DapiDOSet1(ULONG handle, ULONG ch, ULONG data);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output to be set to (0 ..)
data=Specifies the data value that is to be written (0 / 1)
Return value
None
DELIB API reference |Seite 70
5.4.3. DapiDOSet8
Description
This command sets 8 digital outputs simultaneously.
Definition
void DapiDOSet8(ULONG handle, ULONG ch, ULONG data);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output, from which it begins to write to (0, 8, 16, 24,32, ..)
data=Specifies the data values, to write to the outputs
Return value
None
DELIB API reference |Seite 71
5.4.4. DapiDOSet16
Description
This command sets 16 digital outputs simultaneously.
Definition
void DapiDOSet16(ULONG handle, ULONG ch, ULONG data);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output, from which it begins to write to (0, 16, 32, ..)
data=Specifies the data values, to write to the outputs
Return value
None
DELIB API reference |Seite 72
5.4.5. DapiDOSet32
Description
This command sets 32 digital outputs simultaneously.
Definition
void DapiDOSet32(ULONG handle, ULONG ch, ULONG data);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output, from which it begins to write to (0, 32, 64, ..)
data=Specifies the data values, to write to the outputs
Return value
None
Example program
// Einen Wert auf die Ausgänge schreibendata = 0x0000ff00; // Ausgänge 9-16 werden auf 1 gesetztDapiDOSet32(handle, 0, data); // Chan Start = 0printf("Schreibe auf Ausgänge Daten=0x%x\n", data);printf("Taste für weiter\n");getch();// ----------------------------------------------------// Einen Wert auf die Ausgänge schreibendata = 0x80000000; // Ausgang 32 wird auf 1 gesetztDapiDOSet32(handle, 0, data); // Chan Start = 0printf("Schreibe auf Ausgänge Daten=0x%x\n", data);printf("Taste für weiter\n");getch();// ----------------------------------------------------// Einen Wert auf die Ausgänge schreibendata = 0x80000000; // Ausgang 64 wird auf 1 gesetztDapiDOSet32(handle, 32, data); // Chan Start = 32printf("Schreibe auf Ausgänge Daten=0x%x\n", data);printf("Taste für weiter\n");getch();
DELIB API reference |Seite 73
5.4.6. DapiDOSet64
Description
This command is to set 64 digital outputs.
Definition
void DapiDOSet64(ULONG handle, ULONG ch, ULONG data);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the output, from which it begins to write to (0, 64, ..)
data=Specifies the data values, to write to the outputs
Return value
None
DELIB API reference |Seite 74
5.4.7. DapiDOReadback32
Description
This command reads back the 32 digital outputs.
Definition
ULONG DapiDOReadback32(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the input, from which it begins to read from (0, 32, ..)
Return value
Status of 32 outputs.
DELIB API reference |Seite 75
5.4.8. DapiDOReadback64
Description
This command reads back the 64 digital outputs.
Definition
ULONGLONG DapiDOReadback64(ULONG handle, ULONG ch);
Parameters
handle=This is the handle of an opened module
ch=Specifies the number of the input, from which it begins to read from (0, 64, ..)
Return value
Status of 64 outputs.
DELIB API reference |Seite 76
5.5. Example program
// ****************************************************************************// ****************************************************************************// ****************************************************************************// ****************************************************************************// ****************************************************************************//// (c) DEDITEC GmbH, 2009//// web: http://www.deditec.de//// mail: [email protected]//////// dtapi_prog_beispiel_input_output.cpp////// ****************************************************************************// ****************************************************************************// ****************************************************************************// ****************************************************************************// ****************************************************************************////// Folgende Bibliotheken beim Linken mit einbinden: delib.lib// Dies bitte in den Projekteinstellungen (Projekt/Einstellungen/Linker(Objekt-Bibliothek-Module) .. letzter Eintrag konfigurieren#include <windows.h>#include <stdio.h>#include "conio.h"#include "delib.h"// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------
void main(void){unsigned long handle;unsigned long data;unsigned long anz;unsigned long i;unsigned long chan;// ----------------------------------------------------// USB-Modul öffnenhandle = DapiOpenModule(USB_Interface8,0);printf("USB_Interface8 handle = %x\n", handle);if (handle==0){// USB Modul wurde nicht gefundenprintf("Modul konnte nicht geöffnet werden\n");printf("TASTE für weiter\n");getch();
DELIB API reference |Seite 77
return;}// Zum Testen - ein Ping senden// ----------------------------------------------------printf("PING\n");anz=10;for(i=0;i!=anz;++i){data=DapiPing(handle, i);if(i==data){// OKprintf(".");}else{// No answerprintf("E");}}printf("\n");
// ----------------------------------------------------// Einen Wert auf die Ausgänge schreibendata = 255;DapiWriteByte(handle, 0, data);printf("Schreibe auf Adresse=0 daten=0x%x\n", data);// ----------------------------------------------------// Einen Wert auf die Ausgänge schreibendata = 255;DapiWriteByte(handle, 1, data);printf("Schreibe auf Adresse=0 daten=0x%x\n", data);// ----------------------------------------------------// Einen Wert auf die Ausgänge schreibendata = 255;DapiWriteByte(handle, 2, data);printf("Schreibe auf Adresse=2 daten=0x%x\n", data);// ----------------------------------------------------// Einen Wert von den Eingängen lesendata = (unsigned long) DapiReadByte(handle, 0);printf("Gelesene Daten = 0x%x\n", data);// ----------------------------------------------------// Einen A/D Wert lesenchan=11; // read chan. 11data = DapiReadWord(handle, 0xff010000 + chan*2);printf("Adress=%x, ret=%x volt=%f\n", chan, data, ((float) data) / 1024*5);//Bei 5 Volt Ref// ----------------------------------------------------// Modul wieder schliessenDapiCloseModule(handle);printf("TASTE für weiter\n");getch();return ;}
Appendix |Seite 79
6. Appendix
6.1. Revisions
Rev 1.00 First issue
Rev 2.00 Design change
Rev 2.01 Supplement to technical data
Rev 2.02 Added chapters "Firmware update" and "Integration of theDELIB"
Rev 2.03 Index added
Appendix |Seite 80
6.2. Copyrights and trademarks
Linux is registered trade-mark of Linus Torvalds.
Windows CE is registered trade-mark of Microsoft Corporation.
USB is registered trade-mark of USB Implementers Forum Inc.
LabVIEW is registered trade-mark of National Instruments.
Intel is registered trade-mark of Intel Corporation
AMD is registered trade-mark of Advanced Micro Devices, Inc.