VM167.
VM167.
Contents I Table of Contents ( I ) Introduction 3 ( II ) Overview of the Functions 5 ( III ) Function List 7 ( 1 ) OpenDevices ................................................................................................................................... 8 ( 2 ) CloseDevices ................................................................................................................................... 9 ( 3 ) ReadAnalogChannel ..................................................................
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.
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
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 Page 7
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.
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.
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.
3.4 ReadIAllAnalog Syntax void ReadAllAnalog( int CardAddress, int *Buffer); Parameter CardAddress: The address of previously opened card. Buffer: Pointer to an array of five 32 bit integers where the data will be read. Description The status of all five Analog to Digital Converters are read to an array of long integers.
3.5 InOutMode Syntax void InOutMode(int CardAddress, int HighNibble, int LowNibble); Parameters CardAddress: The address of previously opened card. LowNibble: 0: the digital I/O terminals 1 to 4 are outputs LowNibble: 1: the digital I/O terminals 1 to 4 are inputs. HighNibble: 0: the digital I/O terminals 5 to 8 are outputs HighNibble: 1: the digital I/O terminals 5 to 8 are inputs. Description Set the digital terminals either inputs or outputs.
3.6 OutputAllDigital Syntax void OutputAllDigital(int CardAddress, int Data); Parameters CardAddress: The address of previously opened card. Data: Value between 0 and 255 that is sent to the digital output port (8 channels). Description The channels of the digital output port are updated with the status of the corresponding bits in the data parameter.
3.7 ClearDigitalChannel Syntax void ClearDigitalChannel( int CardAddress, int Channel); Parameters CardAddress: The address of previously opened card. Channel: Value between 1 and 8 which corresponds to the output channel that is to be cleared. Description The selected channel is cleared.
3.8 ClearAllDigital Syntax void ClearAllDigital(int CardAddress); Parameter CardAddress: The address of previously opened card. Result All digital outputs are cleared.
3.9 SetDigitalChannel Syntax void SetDigitalChannel( int CardAddress, int Channel); Parameters CardAddress: The address of previously opened card. Channel: Value between 1 and 8 which corresponds to the output channel that is to be set. Description The selected digital output channel is set.
3.10 SetAllDigital Syntax void SetAllDigital(int CardAddress); Parameter CardAddress: The address of previously opened card. Description All the digital output channels are set.
3.11 ReadDigitalChannel Syntax bool ReadDigitalChannel(int CardAddress, int Channel); Parameters CardAddress: The address of previously opened card. Channel: Value between 1 and 8 which corresponds to the input channel whose status is to be read. Result bool: TRUE means that the corresponding digital input of the card is HIGH. FALSE means that the input is LOW. Description The status of the selected Input channel is read.
3.12 ReadAllDigital Syntax int ReadAllDigital(int CardAddress); Parameter CardAddress: The address of previously opened card. Result int: The 8 LSB correspond to the status of the digital input channels. '1' means that the corresponding input of the card is HIGH, '0' means that the input is LOW. Description The function returns the status of the digital inputs of the card.
3.13 SetPWM Syntax void SetPWM(int CardAddress, int Channel, int Data, int Freq); Parameters CardAddress: The address of previously opened card. Channel: The PWM output channel 1 or 2. Data: Value between 0 and 255 which is to be sent to the PWM output of the card. The duty cycle of the PWM output corresponds to the data value: 0 = 0%, 255 = 100% duty cycle. Freq: The PWM frequency: 1: 2929.68 Hz 2: 11718.
3.14 OutputAllPWM Syntax void OutputAllPWM(int CardAddress, int Data1, int Data2); Parameters CardAddress: The address of previously opened card. Data1: Value between 0 and 255 which is to be sent to the PWM 1 output of the card .
3.15 ResetCounter Syntax void ResetCounter(int CardAddress); Parameter CardAddress: The address of previously opened card. Description The 32 bit pulse counter is reset.
3.16 ReadCounter Syntax unsigned int ReadCounter(int CardAddress); Parameter CardAddress: The address of previously opened card. Result unsigned int: The content of the 32 bit pulse counter. Description The function returns the status of the 32 bit pulse counter. The counter counts the pulses fed to the digital terminal number 1. Both input and output pulses are counted. The counter increments on the rising edge. Example TextBox1->Text = (ReadCounter(CardAddress)).
3.17 Connected Syntax int Connected(); Result int: The return value indicate the number of VM167 cards connected. 0: No cards connected 1: Card at the Card Address 0 found. 2: Card at the Card Address 1 found. 3: Cards at the Card Address 0 and 1 found. Description Checks that USB connection to the cards is valid. Example int Cards; ... Button1_Click(..) { Cards = OpenDevices(); // open ... } ...
3.18 VersionFirmware Syntax int VersionFirmware(int CardAddress); Parameters CardAddress: The address of previously opened card. Result int: A 32 bit integer where the firmware version (4 digits) is represented. Each byte is one digit. Description The firmware version info of the card is read. Example int ver; ver = VersionFirmware(CardAddress); label17->Text = "Firmware v"+(ver >> 24).ToString()+ "." +((ver >> 16) & 0xFF).ToString() +"." +((ver >> 8) & 0xFF).ToString()+ "." +(ver & 0xFF).
3.19 VersionDLL Syntax int VersionDLL(); Result int: A 32 bit integer where the DLL version (4 digits) is represented. Each byte is one digit. Description The DLL version info is read. Example int ver; ver = VersionDLL(); label18->Text = "DLL v" +(ver >> 24).ToString()+ "." +((ver >> 16) & 0xFF).ToString()+ "." +((ver >> 8) & 0xFF).ToString()+ "."+(ver & 0xFF).
3.20 ReadBackPWMOut Syntax void ReadBackPWMOut(int CardAddress, int *Buffer); Parameter CardAddress: The address of previously opened card. Buffer: Pointer to array of two 32 bit integers where the data will be read. Description The values of the PWM outputs are read back to an array of two 32 bit integers. Example int PWM[2]; ReadBackPWMOut(CardAddress, PWM); TrackBar1->Value = PWM[0]; TrackBar2->Value = PWM[1]; Label15->Text = TrackBar1->Value.ToString(); Label16->Text = TrackBar2->Value.
3.21 ReadBackInOutMode Syntax int ReadBackInOutMode( int CardAddress); Parameter CardAddress: The address of previously opened card. Result int: Value between 0 and 3 representing the input/output mode of the digital terminals. 0: All the digital I/O terminals are outputs 1: The digital I/O terminals 1 to 4 are inputs and terminals 5 to 8 are outputs. 2: The digital I/O terminals 1 to 4 are outputs and terminals 5 to 8 are inputs.
IV
Function declarations in other programming languages · · · · · Visual Basic 6.
4.1 Visual Basic 6.0 Private Declare Function OpenDevices Lib "vm167.dll" () As Long Private Declare Sub CloseDevices Lib "vm167.dll" () Private Declare Sub InOutMode Lib "vm167.dll" (ByVal CardAddress As Long, ByVal HighNibble As Long, ByVal LowNibble As Long) Private Declare Function ReadAnalogChannel Lib "vm167.dll" (ByVal CardAddress As Long, ByVal Channel As Long) As Long Private Declare Sub ReadAllAnalog Lib "vm167.
4.2 Visual Basic 2008 Express Private Declare Function OpenDevices Lib "vm167.dll" () As Integer Private Declare Sub CloseDevices Lib "vm167.dll" () Private Declare Sub InOutMode Lib "vm167.dll" (ByVal CardAddress As Integer, ByVal HighNibble As Integer, ByVal LowNibble As Integer) Private Declare Function ReadAnalogChannel Lib "vm167.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer) As Integer Private Declare Sub ReadAllAnalog Lib "vm167.
4.3 Visual C# 2008 Express [DllImport("vm167.dll")] public static extern int OpenDevices(); [DllImport("vm167.dll")] public static extern void CloseDevices(); [DllImport("vm167.dll")] public static extern int ReadAnalogChannel( int CardAddress, int Channel); [DllImport("vm167.dll")] public static extern void ReadAllAnalog(int CardAddress, int[] Buffer); [DllImport("vm167.dll")] public static extern void SetPWM(int CardAddress, int Channel, int Data, int Freq); [DllImport("vm167.
4.4 Delphi function OpenDevices: integer; stdcall; external 'VM167.dll'; procedure CloseDevices; stdcall; external 'VM167.dll'; function ReadAnalogChannel(CardAddress: integer; Channel: integer):integer; stdcall; external 'VM167.dll'; procedure ReadAllAnalog(CardAddress: integer; Buffer: Pointer); stdcall; external 'VM167.dll'; function ReadAllDigital(CardAddress: integer): integer; stdcall; external 'VM167.
4.