18.02.2014 Views

EDU05D.DLL - Smarthome

EDU05D.DLL - Smarthome

EDU05D.DLL - Smarthome

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>EDU05D</strong>.<strong>DLL</strong><br />

Technical Guide<br />

Introduction<br />

General<br />

The EDU05 USB tutor module has 8 digital input/output channels, five analog input channels and two PWM outputs.<br />

There on the board is also 16 character LCD display.<br />

All communication routines are contained in a Dynamic Link Library <strong>EDU05D</strong>.<strong>DLL</strong>.<br />

In this manual we will describe each of these functions provided by the <strong>DLL</strong> in detail. Calling the functions exported by<br />

the <strong>DLL</strong>, you can write custom Windows applications in Visual Basic or any other 32-bit Windows application<br />

development tool that supports calls to a <strong>DLL</strong>.<br />

A complete overview of the procedures and functions that are exported by the <strong>EDU05D</strong>.<strong>DLL</strong> follows.<br />

Note that all the examples in the function description section are written in C++.<br />

EDU05 examples folder includes examples written in Visual Basic 2008 Express, Visual C# 2008 Express and Visual<br />

C++ 2008 Express.<br />

Readers should have an understanding of the basic data types as well as basic knowledge of the Microsoft Windows<br />

operating system.<br />

Microsoft Visual Studio users please note: The <strong>EDU05D</strong>.<strong>DLL</strong> is a standard Windows <strong>DLL</strong>, you cannot reference it.<br />

Calling convention<br />

A calling convention is a scheme for how functions receive parameters from their caller and how they return a result.<br />

Different programming languages use different calling conventions, so it is important to know which calling convention<br />

is used by your programming language and which calling convention is used by the <strong>EDU05D</strong>.<strong>DLL</strong>.<br />

The most common calling convention is the stdcall calling convention, and this is also the one we have used for our<br />

<strong>DLL</strong>.<br />

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<br />

stdcall. However if you are using C to import the functions provided by the <strong>DLL</strong>, you will need to pay special attention<br />

to this.


Overview of the Functions<br />

General functions<br />

int OpenDevice()<br />

void CloseDevice()<br />

int Connected()<br />

void InOutMode(int IOMode)<br />

Opens the communication link to the EDU05 device<br />

Closes the link to the EDU05 device<br />

Checks that the USB connection to the card is valid<br />

Set the digital terminals either inputs or outputs<br />

Analog to Digital converter function<br />

int ReadAnalogChannel(int Channel) Reads the status of one analog input-channel<br />

PWM Output function<br />

void SetPWM(int Channel, int Data) Sets the status the PWM output<br />

Digital Output functions<br />

void OutputAllDigital(int Data)<br />

Sets the digital outputs according to the data<br />

void ClearDigitalChannel(int Channel) Clears the output channel<br />

void ClearAllDigital()<br />

Clears all output channels<br />

void SetDigitalChannel(int Channel) Sets the output channel<br />

void SetAllDigital()<br />

Sets all output channels<br />

Digital Input functions<br />

int ReadAllDigital()<br />

Reads the status of all the input channels<br />

LCD functions<br />

void LCDInit()<br />

Initializes the LCD display module<br />

void LCDClear()<br />

Clears the text on the LCD display<br />

void void LCDWriteString(String^ Data, int Position);<br />

Writes text on the LCD display


Function List<br />

OpenDevice<br />

Syntax<br />

int OpenDevice();<br />

Result<br />

int: If succeeded the return value 1 indicates that EDU05 card was found.<br />

Return value 0 indicates that no EDU05 card found.<br />

Description<br />

Opens the communication link to the EDU05 card. Loads the drivers needed to communicate via the USB port. This<br />

procedure must be performed before any attempts to communicate with the EDU05 card.<br />

Example<br />

int h = OpenDevice();<br />

switch (h)<br />

{<br />

case 0:<br />

Label1->Text = "EDU05 not found";<br />

break;<br />

case 1:<br />

Label1->Text = "EDU05 connected";<br />

IOMode = 1;<br />

InOutMode(IOMode);<br />

RadioButton3->Checked = true;<br />

Timer1->Enabled = true;<br />

break;<br />

}<br />

CloseDevice<br />

Syntax<br />

void CloseDevice();<br />

Description<br />

Unloads the communication routines for EDU05 card and unloads the driver needed to communicate via the USB port.<br />

This is the last action of the application program before termination.<br />

Example<br />

private: System::Void Form1_FormClosed(System::Object^ sender,<br />

System::Windows::Forms::FormClosedEventArgs^ e)<br />

{<br />

CloseDevice();<br />

}<br />

ReadAnalogChannel<br />

Syntax<br />

int ReadAnalogChannel(int Channel);<br />

Parameter<br />

Channel: Value between 1 and 5 which corresponds to the AD channel whose status is to be read.<br />

Result<br />

int: The corresponding Analog to Digital Converter data is read.<br />

Description<br />

The input voltage of the selected 10-bit Analog to Digital converter channel is converted to a value which lies between<br />

0 and 1023.


Example<br />

int Buffer[5];<br />

int i;<br />

for (i=0; i


InOutMode(0);<br />

ClearAllDigital(CardAddress);<br />

SetDigitalChannel<br />

Syntax<br />

void SetDigitalChannel(int Channel);<br />

Parameter<br />

Channel: Value between 1 and 8 which corresponds to the output channel that is to be set.<br />

Description<br />

The selected digital output channel is set.<br />

Example<br />

if (CheckBox3->Checked)<br />

SetDigitalChannel(3);<br />

else<br />

ClearDigitalChannel(3);<br />

SetAllDigital<br />

Syntax<br />

void SetAllDigital();<br />

Description<br />

All the digital output channels are set.<br />

Example<br />

InOutMode(0);<br />

SetAllDigital(CardAddress);<br />

SetPWM<br />

Syntax<br />

void SetPWM(int Channel, int Data);<br />

Parameters<br />

Channel: The PWM output channel 1 or 2.<br />

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<br />

corresponds to the data value: 0 = 0%, 255 = 100% duty cycle.<br />

Example<br />

SetPWM(1, 128); // The duty cycle of the PWM output #1 is set to 50%<br />

Connected<br />

Syntax<br />

bool Connected();<br />

Result<br />

bool: true if the card is connected, false if not connected.<br />

Description<br />

Checks that USB connection to the cards is valid.<br />

Example<br />

if (Connected())<br />

Label1->Text = "EDU05 connected";<br />

else


Label1->Text = "EDU05 not connected";<br />

LCDInit<br />

Syntax<br />

void LCDInit();<br />

Description<br />

Initializes the LCD display module.<br />

Example<br />

InOutMode(0);<br />

LCDInit();<br />

LCDClear<br />

Syntax<br />

void LCDClear();<br />

Description<br />

Clears the LCD display.<br />

Example<br />

InOutMode(0);<br />

LCDClear();<br />

LCDWriteString<br />

Syntax<br />

void LCDWriteString(String^ Data, int Position);<br />

Parameters<br />

Data: Pointer to the text string.<br />

Position: Text position (0...15) on the LCD display.<br />

Example<br />

InOutMode(0);<br />

LCDWriteString(textBox1->Text,Convert::ToInt32(textBox2->Text));


Function declarations in other programming languages<br />

Visual Basic 2008 Express<br />

Private Declare Function OpenDevice Lib "edu05d.dll" () As Integer<br />

Private Declare Sub CloseDevice Lib "edu05d.dll" ()<br />

Private Declare Function Connected Lib "edu05d.dll" () As Boolean<br />

Private Declare Function ReadAnalogChannel Lib "edu05d.dll" (ByVal Channel As Integer) As Integer<br />

Private Declare Function ReadAllDigital Lib "edu05d.dll" () As Integer<br />

Private Declare Sub SetPWM Lib "edu05d.dll" (ByVal Channel As Integer, ByVal Data As Integer)<br />

Private Declare Sub InOutMode Lib "edu05d.dll" (ByVal IOMode As Integer)<br />

Private Declare Sub OutputAllDigital Lib "edu05d.dll" (ByVal Data As Integer)<br />

Private Declare Sub ClearAllDigital Lib "edu05d.dll" ()<br />

Private Declare Sub SetAllDigital Lib "edu05d.dll" ()<br />

Private Declare Sub ClearDigitalChannel Lib "edu05d.dll" (ByVal Channel As Integer)<br />

Private Declare Sub SetDigitalChannel Lib "edu05d.dll" (ByVal Channel As Integer)<br />

Private Declare Sub LCDInit Lib "edu05d.dll" ()<br />

Private Declare Sub LCDClear Lib "edu05d.dll" ()<br />

Private Declare Sub LCDWriteString Lib "edu05d.dll" (ByVal Data As String, ByVal Position As Integer)<br />

Visual C# 2008 Express<br />

[DllImport("edu05d.dll")]<br />

public static extern int OpenDevice();<br />

[DllImport("edu05d.dll")]<br />

public static extern void CloseDevice();<br />

[DllImport("edu05d.dll")]<br />

public static extern bool Connected();<br />

[DllImport("edu05d.dll")]<br />

public static extern int ReadAnalogChannel(int Channel);<br />

[DllImport("edu05d.dll")]<br />

public static extern int ReadAllDigital();<br />

[DllImport("edu05d.dll")]<br />

public static extern void SetPWM(int Channel, int Data);<br />

[DllImport("edu05d.dll")]<br />

public static extern void InOutMode(int IOMode);<br />

[DllImport("edu05d.dll")]<br />

public static extern void OutputAllDigital(int Data);<br />

[DllImport("edu05d.dll")]<br />

public static extern void ClearAllDigital();<br />

[DllImport("edu05d.dll")]<br />

public static extern void SetAllDigital();<br />

[DllImport("edu05d.dll")]<br />

public static extern void ClearDigitalChannel(int Channel);<br />

[DllImport("edu05d.dll")]<br />

public static extern void SetDigitalChannel(int Channel);<br />

[DllImport("edu05d.dll")]<br />

public static extern void LCDInit();<br />

[DllImport("edu05d.dll")]<br />

public static extern void LCDClear();<br />

[DllImport("edu05d.dll")]<br />

public static extern void LCDWriteString(string Data, int Position);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!