Velleman VM167 User guide

VM167.DLL
Technical Guide
VM167.DLL
Technical guide
Table of Contents
IContents
( I ) Introduction
( II ) Overview of the Functions
Function List
................................................................................................................................... 8( 1 ) OpenDevices
................................................................................................................................... 9( 2 ) CloseDevices
................................................................................................................................... 10( 3 ) ReadAnalogChannel
................................................................................................................................... 11( 4 ) ReadIAllAnalog
................................................................................................................................... 12( 5 ) InOutMode
................................................................................................................................... 13( 6 ) OutputAllDigital
................................................................................................................................... 14( 7 ) ClearDigitalChannel
................................................................................................................................... 15( 8 ) ClearAllDigital
................................................................................................................................... 16( 9 ) SetDigitalChannel
................................................................................................................................... 17( 10 ) SetAllDigital
................................................................................................................................... 18( 11 ) ReadDigitalChannel
................................................................................................................................... 19( 12 ) ReadAllDigital
................................................................................................................................... 20( 13 ) SetPWM
................................................................................................................................... 21( 14 ) OutputAllPWM
................................................................................................................................... 22( 15 ) ResetCounter
................................................................................................................................... 23( 16 ) ReadCounter
................................................................................................................................... 24( 17 ) Connected
................................................................................................................................... 25( 18 ) VersionFirmware
................................................................................................................................... 26( 19 ) VersionDLL
................................................................................................................................... 27( 20 ) ReadBackPWMOut
................................................................................................................................... 28( 21 ) ReadBackInOutMode
3 5
7
( IV ) Function declarations in other programming
languages
................................................................................................................................... 31( 1 ) Visual Basic 6.0
................................................................................................................................... 32( 2 ) Visual Basic 2008 Express
................................................................................................................................... 33( 3 ) Visual C# 2008 Express
................................................................................................................................... 34( 4 ) Delphi
................................................................................................................................... 35( 5 ) Borland C++Builder
© 2010 ... Velleman
30
I
I

Introduction

General
The VM167 interface board has 8 digital input/output channels, five analog input channels and two PWM outputs. The number of inputs/outputs can be expanded by connecting two VM167 cards to the
PC. Both of the cards has its own identification number (card address) by means of the jumper setting. All communication routines are contained in a Dynamic Link Library VM167.DLL.
In this manual we will describe each of these functions provided by the DLL in detail. Calling the functions exported by the DLL, you can write custom Windows applications in Delphi, Visual Basic or any other 32-bit Windows application development tool that supports calls to a DLL.
A complete overview of the procedures and functions that are exported by the VM167.DLL follows. Note that all the examples in the function description section are written in C++. VM167 examples folder includes examples written in Visual Basic 2008 Express, Visual C# 2008 Express, Visual C++ 2008 Express, VB6.0, MS Excel VBA, Delphi 5, Borland C++Builder 6 and Dev­C++.
Readers should have an understanding of the basic data types as well as basic knowledge of the Microsoft Windows operating system.
Microsoft Visual Studio users please note: The VM167.DLL is a standard Windows DLL, you cannot reference it.
Calling convention
A calling convention is a scheme for how functions receive parameters from their caller and how they return a result. Different programming languages use different calling conventions, so it is important to know which calling convention is used by your programming language and which calling convention is used by the VM167 DLL.
The most common calling convention is the stdcall calling convention, and this is also the one we have used for our DLL.
If you are using .NET (VB.NET or C#) you do not need to worry about this since the calling convention in .NET is also stdcall. However if you are using C to import the functions provided by the DLL, you will need to pay special attention to this.
Card Address Setting
J5 Card Address
ON 0
OFF 1
TABLE 1: Jumper J5 Settings
The card address settings must be done before the USB cable is connected to the VM167 card or before turning the PC on. If the USB cable is disconnected and reconnected then all the digital terminals are set as inputs and the PWM outputs are reset to zero.
Velleman Projects
3Page
II

Overview of the Functions

General functions
int OpenDevices() Opens the communication link to the VM167
devices
void CloseDevices() Closes the link to the VM167 devices int Connected() Checks that the USB connection to the cards is
valid
int VersionFirmware(int CardAddress) Reads the firmware version
number
int VersionDLL() Reads the DLL version number void InOutMode(int CardAddress, int HighNibble, int LowNibble)
Set the digital terminals either inputs or outputs
Analog to Digital converter functions
int ReadAnalogChannel(int CardAddress, int Channel)
Reads the status of one analog input-channel
void ReadAllAnalog(int CardAddress, int *Buffer)
Reads the status of all analog input-channels
PWM Output functions
void SetPWM(int CardAddress, int Channel, int Data, int Freq)
Sets the status of one PWM output
void OutputAllPWM(int CardAddress, int Data1, int Data2)
Sets both of the PWM outputs
Digital Output functions
void OutputAllDigital(int CardAddress, int Data)
Sets the digital outputs according to the data
void ClearDigitalChannel(int CardAddress, int Channel)
Clears the output channel
void ClearAllDigital(int CardAddress)
Clears all output channels
void SetDigitalChannel(int CardAddress, int Channel)
Sets the output channel
void SetAllDigital(int CardAddress)
Sets all output channels
Digital Input functions
bool ReadDigitalChannel(int CardAddress, int Channel)
Reads the status of the input channel
int ReadAllDigital(int CardAddress)
Reads the status of all the input channels
Counter functions
void ResetCounter(int CardAddress) Resets the 32 bit pulse counter unsigned int ReadCounter(int CardAddress)
Reads the content of the 32 bit pulse counter
Readback procedures and functions
void ReadBackPWMOut(int CardAddress, int *Buffer)
Reads back the status of the PWM outputs
int ReadBackInOutMode(int CardAddress)
Reads back the current in/out mode of the digital terminals
Velleman Projects
5Page
III

Function List

· OpenDevices
· CloseDevices
· ReadAnalogChannel
· ReadIAllAnalog
· InOutMode
· OutputAllDigital
· ClearDigitalChannel
· ClearAllDigital
· SetDigitalChannel
· SetAllDigital
· ReadDigitalChannel
· ReadAllDigital
· SetPWM
· OutputAllPWM
· ResetCounter
· ReadCounter
· Connected
· VersionFirmware
· VersionDLL
· ReadBackPWMOut
· ReadBackInOutMode
Velleman Projects
7Page
3.1

Open Devices

Syntax
int OpenDevices();
Result
int: If succeeded the return value will indicate the number of VM167 cards found. 1: Card in the Card Address 0 found. 2: Card in the Card Address 1 found. 3: Card in the Card Address 0 and 1 found.
Return value -1 indicates that no VM167 cards found. Return value 0 indicates that there was problems to open the driver. Disconnect and reconnect the USB cable.
Description
Opens the communication link to the VM167 card. Loads the drivers needed to communicate via the USB port. This procedure must be performed before any attempts to communicate with the VM167 cards.
Example
int Cards;
... Cards = OpenDevices();
switch (Cards)
{ case 0: Label1->Text = "Card open error."; break; case 1:
Label1->Text = "Card 0 connected."; RadioButton1->Enabled = true; RadioButton1->Checked = true; CardAddress = 0;
Timer1->Enabled = true; break; case 2: Label1->Text = "Card 1 connected."; RadioButton2->Enabled = true;
RadioButton2->Checked = true; CardAddress = 1; Timer1->Enabled = true; break; case 3:
Label1->Text = "Cards 0 and 1 connected."; RadioButton1->Enabled = true; RadioButton1->Checked = true; RadioButton2->Enabled = true;
RadioButton2->Checked = false; CardAddress = 0; Timer1->Enabled = true; break; case -1:
Label1->Text = "Card not found."; break;
}
Velleman Projects
8Page
3.2

CloseDevices

Syntax
void CloseDevices();
Description
Unloads the communication routines for VM167 cards and unloads the driver needed to communicate via the USB port. This is the last action of the application program before termination.
Example
private: System::Void Form1_FormClosed(System::Object^ sender,
System::Windows::Forms::FormClosedEventArgs^ e)
{
CloseDevices();
}
Velleman Projects
9Page
3.3

ReadAnalogChannel

Syntax
int ReadAnalogChannel(int CardAddress, int Channel);
Parameters
CardAddress: The address of previously opened card. Channel: Value between 1 and 5 which corresponds to the AD channel whose status is to be read.
Result
int: The corresponding Analog to Digital Converter data is read.
Description
The input voltage of the selected 10-bit Analog to Digital converter channel is converted to a value which lies between 0 and 1023.
Example
int a5;
a5 = ReadAnalogChannel(CardAddress, 5); label19->Text = a5.ToString();
Velleman Projects
10Page
Loading...
+ 26 hidden pages