Hi hyco-ga,
I have uploaded an example c++ program that will read from and
write to the first analog channel on the board. You can download the
file from:
http://rapidshare.de/files/3863702/example.cpp.html
The instructions to get it compiling and running properly follow:
- STEP 1: Getting the compiler
The example program that I have provided is a simple console
program, which has been tested with the Borland C++ 5.5 compiler.
Borland provides this compiler as a free download on their website.
You can download it from:
- Borland C++ Builder Downloads
(http://www.borland.com/downloads/download_cbuilder.html)
Also, since we will be working on a GUI next, you will need
to download the Borland C++ Builder 6.0 Enterprise Trial, available
from the same webpage. However, this can wait, since our example
program just requires the BC++ 5.5 compiler for now.
- STEP 2: Installing and configuring the Borland C++ 5.5 compiler
Just run the downloaded exe and the compiler will install
itself. By default it installs in the 'C:\Borland\BCC55\' folder.
Once the installation is complete, we will need to add the
BIN subfolder in the installation directory to the system PATH, so
that we can run the compiler just by specifying its name at the
command-line, with out worrying about the installation path.
To add the compiler BIN folder to the system path:
- Right click on the My Computer icon and select 'Properties'
- In the Window that pops up, click on the 'Advanced' tab
- On the 'Advanced' tab, click on the 'Environment Variables' button
- In the dialog that pops up, go down the 'System Variables'
list till you see the 'Path' variable
- Select the 'Path' variable and click on the 'Edit' button
- In the window that pops up, goto the 'Variable Value'
field, and add the path to the BIN directory at the beginning of the
text there, followed by a semicolon. So if the field was earlier:
Variable Value: %SystemRoot%\system32;%SystemRoot
it should become
Variable Value:
C:\Borland\BCC55\BIN;%SystemRoot%\system32;%SystemRoot
where 'C:\Borland\BCC55\BIN' is the path to the BC++ 5.5
compiler BIN folder.
- Now click on Ok and dismiss all the dialogs.
- STEP 3: The compiler options
To keep things simple, copy the example C++ program I have
provided, the K8055D.h and the K8055D.dll files into one folder. I
copied all the files into a 'C:\Example\' folder. You may use any
folder you want. Just change the command line options appropriately.
Now when we compile this program, we have to provide the
compiler with the following information:
- The list of folders it should search to find the required
header (.h) files. In this case, we want it to look in it's standard
headers files folder, which will be the 'Include' subfolder in the
installation directory (by default 'C:\Borland\BCC55\Include\')
We also want it to look in the folder which contains the
'K8055D.h' header file. For me, this value is 'C:\Example\'. You will
have to put the appropriate folder name for yourself.
The above information is provided to the compiler using the
-I option. The multiple folder names are separated by a semicolon.
- We also need to provide the compiler with the path to the
standard library (.lib) folder. We provide this information using the
'-L' option. This folder will be 'C:\Borland\BCC55\LIB\' by default.
- Now, since we are using a custom library file for the dll
(K8055D.lib), we will need to provide the full path to it at the
command line also. In the example, this path is given as
'C:\Example\K8055D.lib'. You will need to modify this path to reflect
your settings.
- Finally, we need to provide the compiler with the name of
the C++ file that needs to be compiled (example.cpp in this case).
- STEP 4: Compiling the program
- To compile the program, we must first start the command
prompt. Go to 'Start Menu'> Run, type 'cmd' in the Run Dialog box and
press 'Enter'. The command prompt should pop up.
- Now switch to the folder in which the example.cpp file and
the dll reside.
cd C:\Example
- Once you are in this folder, compile the cpp file with the
following command line:
bcc32 -IC:\Example\;C:\Borland\BCC55\Include\
-LC:\Borland\BCC55\Lib C:\Example\k8055d.lib example.cpp
- If all the settings have been provided correctly, the
program should compile without any error or warning messages.
- STEP 4: Running the program
Once the program compiles successfully, an exe file with the
same name (example.exe in this case) will be created in the current
folder. Make sure that the K8055D.dll file lies in the same folder as
the exe.
Once you run the example program, it will try to open card 0
on the board. If it is successful, it clears the first Analog Channel,
asks the user for an input and writes it to the channel, and then
reads it back.
Be sure to set the card address to 0 by setting the SK5 and
SK6 jumpers to on before connecting the USB cable or turning on the
PC. See the manual for detailed instructions.
=============================================
The example program demonstrates simple reading and writing
functionality as you requested. Its functionality can be extended
further using the other methods documented in the API.
While I have tested that the program compiles and executes correctly,
I cannot verify the functionality since i do not have access to the
actual board.
Please try out the example code, and if you encounter any errors,
post the detailed error messages here and we will work through them.
Once you have confirmed that the given code meets your needs, we can
start work on the GUI. You will need to download and install Borland
C++ Builder 6.0 Enterprise trial for this, if you do not have access
to the full version.
==============================================
Hope this helps.
If you need any clarifications, just ask!
Regards,
Theta-ga
:) |
Clarification of Answer by
theta-ga
on
19 Aug 2005 11:53 PDT
Hi hyco-ga,
As per the specs you listed above, I have created the required GUI
interface. You can download a zip file containing the project from:
- RapidShare.De: ControllerGUI.zip
(http://rapidshare.de/files/4154219/ControllerGUI.zip.html)
To keep things simple, I have included the .lib, .h and the .dll
files for the USB board API in the same folder as the project files.
The exe will require the dll to be in the same folder to run properly.
The code contains three main units(.h/.cpp):
1. ControllerGUI: This contains the code to setup a Windows
application. This file is created and maintained by the Borland C++
IDE, and you will not need to modify it yourself.
2. frmMain: This contains all the code for the actual form that we
use. It contains all the code for reading in the user input from the
form to the relevant data structure. It also contains the code
required to display the outputs to the user. You will need to modify
this if you want to change the GUI or the event handling code.
3. Controller: This class contains all the code that reads and
writes data to and from the USB board. It also contains a method
called Process() which is supposed to contain the code to process the
data as per your requirements, and then store the user outputs in the
relevant data structure. This is the method where you will need to add
the code for the processing you need to do.
Control Flow:
- You start the app by running the .exe
- You select the card to open by checking and unchecking the
relevant jumpers, as specified in the manual. By default, the selected
card address is 0.
- Click on the 'Open' button to open the link to the USB Board. Once
the link is opened, this button becomes the 'Close' button. If you
click on it again, it will close the link to the USB board.
- Once you open the connection with the board, the GUI for providing
user inputs and displaying user outputs is displayed.
- By default, all input variables are set to 0. You can modify them
as per your needs, and then press the 'Set' button to store them in
the relevant data structure for use in further calculations.
- I have made the polling interval for the board configurable. By
default, it is set to 1000 milliseconds. You can set it to any
required value by entering it in the textbox at the bottom right of
the screen.
- Press the 'Start Polling' button to start polling data from the
board. The app will read in the data, preform the required processing
(as per the code you add), and display the output data on the screen.
It will continue doing so until you click the 'Stop Polling' button.
Again, since I do not have access to the actual hardware, i was only
able to perform limited testing on the code. Please try it out, and if
you find any issues, we can work through them together.
The code is reasonably well documented, and you will be mainly adding
code to the Controller class to perform the processing you require.
Look at the Process() method of that class. Also you will need to
provide the code for calculating the TempC output variable. Right now
I just set it to 0.
Just try out the code, and if you need any clarifications, I'll be right here!
Hope this helps.
Regards,
Theta-ga
:)
|