RESOLVED: Problem with a parallel port module in VB6
I've been working on this for a little while now and started building a PC for my car (since i'm into modding pc'c and cars i thought why not do both), now i've hit a big stumbling block I'm looking at buying this module
Which can handle 16 12V inputs or 12V outputs (freely selectable + analogue's) and apparetly it can be controlled from visual basic, before i buy it i'd like to get an understanding of exactly how it works, all i've managed to find is the document i've attached which explains how to use it in VB (apparently). I was hoping as im still virtually a complete newb someone would be able to explain to me what some of this means.
What i'd like to achieve as an end result is to have the card configured to give 10 inputs and 6 outputs, if an input comes on say input 1 for example then i'd like to set a global bool var called input1 to true, likewise setting a var called output1 for example turns output 1 on the card on. I'm kinda hoping someone can point me in the right direction because after reading that myself i was virtually lost after the 1st line
Thanks for taking the time to read it and any assistance offered is greatly appreciated
Last edited by UKDJF; Apr 1st, 2005 at 11:21 AM.
Reason: Resolved
First of all you have to figure out how you are going to configure the device.
From your description it looks like you only need the digital I/O channels.
Do you want to monitor and switch 12V devices in the car?
Make sure the digital I/O channels can handle 12V, digital is usually 5V
Also, make sure the device can handle the current you plan to put through it.
Next, make a list of tasks you want to perform with the device. Tasks such as
1. Monitor the digital I/O ports 10 times a second
2. Turn on/off an I/O port.
I wouldn't bother writing any code until you get the device and it is installed on your computer.
Thanks for the responses guys, the card's outputs are optoisolated relay outs and can switch anything upto 230V, I will be using 2 analogue inputs (may use the other analog outs as digital out's by driving them to max range/0), one analogue input is gonna be hooked up to a pressure sensor near the inlet manifold to measure boost level and the other is gonna be via a 0-10V convertor circuit that will be connected to a temp sensor on the turbo itself (monitoring for bearings/oil starvation etc.). One of the digital outs i'm planning to have working depending on the pressure measured on the boost pressure analogue input to trigger water mist injection. I was planning on having 1-10 as inputs and 11-16 as outputs.
Plus i'm planning on the program doing some other things like integrating media player and some sat nav software too but i havnt worked out how to hook up a small membrane keypad to the PS2 socket yet
I wouldn't bother writing any code until you get the device and it is installed on your computer.
Sounds like a lot of fun.
Advice taken, Board is on order, just have to wait a few days for it to arrive then i gotta assemble it (should give me a nice headache ) . In the meantime i've worked out a list of things I want the program to do and was wondering if you guys could see anything obvious i've overlooked, here's a list of the inputs:
Digital In's
1. Handbrake/parking brake on
2. Door(s) open
3. Boot open
4. Low Battery warning
5. Low water
6. Hood open
7. Car radio turned on
Digital Outs
1. Trigger dependant on level from boost analogue input (for aquamist system)
2. Switch on amplifiers
3. Alarm Sounder (beeper)
4. Illumination circuit for car boot
5. Illunination circuit car interior
6. System shutdown (looped through a small relay work power button on PC)
From that i've decided the first 7 IO are to be configured as inputs and the next 6 as outputs, with the remainder set as inputs (the analogues can be used as outputs later if required - so im told)
Analogue In's
1. Boost pressure (pressure sensor) by inlet manifold.
2. Water temp (maybe)
3. Oil pressure (maybe)
So from that I worked out a list of things i want it to do as follows:
1. Monitor if the input from boot/bonnet switch is recieved while parking brake is off and display a warning message saying what's open
2. Monitor Boost sensor and put the value 0-255 into a public var for later use on a gauge
3. Monitor the input from that sensor also and compare it to a set value to trigger output 1
4. Be able to toggle the interior/boot illumination outputs on/off from a button
5. Display a warning message if the measured value from boost sensor exceeds a set level
6. Trigger shutdown relay(output) for a period of 1 second (or just over) to shut the PC down when the button is clicked.
7. Shut off media player if input from car radio is lost (digital input)
8. Prompt asking if amps are to be on/off when car radio is turned on and set output accordingly.
Basically, I'm thinking it's gonna be easier to have a load of public bool vars for the inputs and outputs called like Input1 (goes true when In1 is on) and Output1 (which turns output1 on when var is true), and have the Analogue in's values put into public Integer vars, that way i can easily perform the maths on them. I used to be heavily involved in industrial logic programming so doing logical operations with bool vars is the easiest method for me to work with. Can you guys see any easy way of doing that? as there example program has got me totally confused. I found another sample program which i've attached and I'm still totally clueless as to how exactly I can talk to inputs and outputs individually. If someone can shed some light on this for me i'd be greatly appreciative as this has (so far) been a
fascinating little project for me.
OK, let's get started.
First you have to configure the board
I'll assume that SW1 is set to Off-Off
In your new project copy all the declerations form the sample project and put a timer on the form
Let's Configure 8 digital ports (chip 0: 1-8) for input and eight (chip 1: 9-16) for output.
VB Code:
Private Sub Form_Load()
card_nr = 0
Start_K8000
SelectI2CprinterPort 1
ConfigIOchipAsInput 0 'Channels 1-8 are for input
ConfigIOchipAsOutput 1 'channels 9-16 are for output
OK, everything else seems to work except for this bit:
VB Code:
GlobalIOstate(i)
This is the array of global boolean variables that you wanted. You can declare it in the decleration section of your module
VB Code:
Option Explicit
Dim GlobalIOstate(0 to 7) as Boolean
One other suggestion: the sample program is a good one to use to test that you have set the board up properly. Once your board is set-up, applied test voltages and loads then then see if the sample program behaves as expected.
That seems to work (still waiting for the board to arrive).
My fault for being such a newb lol
OK, how would i separate that global array up into separate variables,
I'm assuming (never really dealt with arrays) that is holds a combination of the 8 variables. Would that code be the same for setting the outputs too?
One thing I would suggest is getting a book for Beginners on Visual Basic. It can do a lot better job of showing you the basics than I could through this discussion. Eventually I'll be expecting you to get the hang of it and take over.
The examples I'll show will not be the best way to do things, but will be the simplest to understand.
Probably the best place to react to the input ports is in the timer event. Assume you've connected the inputs in the order you listed them.
VB Code:
Private Sub Timer1_Timer()
Dim i As Integer
'Check state of input lines and respond as required
As far as the output goes, you don't need a timer, just respond to events. For example, lests say that you want to turn on the interior lights (port 5) using a button on your form.
Add a button to your form and the following code.
Thanks for that Moeur, I'm sure i can adapt it to do exactly what i want. I've got a book but it's way too confusing for my liking but im gradually picking bits and pieces up as i go along.
I've finally got the board through and am part-way through assembly, hopefully i'll have it working later today (printer cable pending).
Thanks for all your help, I'll post back when i've completed some tests on it and see if it works as expected.
Well, the board works with their example program but doesnt work with that example you gave me. I added at form_load() to start the K8000 and terminate it on form_terminate(). It doesnt seem to be getting comms with the module, i added that parallel port module thing that I included in an earlier post but that did nothing, declared everything but to no avail. I'll keep digging away at it till i can get comms with the board hopefully then i can see if it all works.
Still couldnt get it to communicate from my program so i stripped back the sample source code they supplied to a blank form and used that as a starting point, i cant see any differences (copied the declarations into another project and that didnt work) so i just saved a copy of the stripped back project and can use that as a basis for building my projects onto.
Sorted the input's to boolean vars thing with a little playing around and this was what worked
VB Code:
Private Sub Timer1_Timer()
If ReadIOchannel(1) = 1 Then Input1 = True Else Input1 = False 'Read channel1 and set Bool Var accordingly
If ReadIOchannel(2) = 2 Then Input2 = True Else Input2 = False 'Read channel2 and set Bool Var accordingly
End Sub
Just repeated that code for all the inputs
The outputs worked just as you expected, adding your code for those worked great.
Thanks for all your help Moeur, it's greatly appreciated
PS. I'm sure to be starting another thread when i get to do the analogue side of things so I'll makr this one as resolved. Thanks again