Results 1 to 14 of 14

Thread: RESOLVED: Problem with a parallel port module in VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Resolved 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

    http://www.velleman.be/images/products/0/k8000.jpg

    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
    Attached Files Attached Files
    Last edited by UKDJF; Apr 1st, 2005 at 11:21 AM. Reason: Resolved

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Problem with a parallel port module in VB6

    What is this card supposed to be controlling?

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Problem with a parallel port module in VB6

    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.

    Sounds like a lot of fun.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    Quote Originally Posted by moeur
    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.



    Thanks

    Tom
    Last edited by UKDJF; Mar 28th, 2005 at 01:41 PM.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Problem with a parallel port module in VB6

    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:
    1. Private Sub Form_Load()
    2.     card_nr = 0
    3.     Start_K8000
    4.     SelectI2CprinterPort 1
    5.     ConfigIOchipAsInput 0 'Channels 1-8 are for input
    6.     ConfigIOchipAsOutput 1 'channels 9-16 are for output
    7.     Timer1.Interval = 100 'check ports every 100ms
    8. End Sub
    In the timer routine we'll monitor the ports
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Dim i As Integer
    3.     For i = 0 To 7
    4.         GlobalIOState(i) = ReadIOchannel(i + 1 + card_nr * 16)
    5.         'do some action here based on state of I/O
    6.     Next
    7. End Sub

    See if you get this working

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    OK, everything else seems to work except for this bit:
    VB Code:
    1. GlobalIOstate(i)
    It's giving me a compile error: sub or function not defined

    The instructions also said the module I attached must be added, i think it's for using the parallel port to communicate with the board (maybe wrong)
    Attached Files Attached Files
    Last edited by UKDJF; Mar 28th, 2005 at 02:48 PM.

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Problem with a parallel port module in VB6

    OK, everything else seems to work except for this bit:
    VB Code:
    1. 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:
    1. Option Explicit
    2. 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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    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?

    Thanks for your help Moeur

    Tom

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Problem with a parallel port module in VB6

    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:
    1. Private Sub Timer1_Timer()
    2.     Dim i As Integer
    3. 'Check state of input lines and respond as required
    4. 'The following are the input lines
    5. '   0. Handbrake/parking brake on
    6. '   1. Door(s) open
    7. '   2. Boot open
    8. '   3. Low Battery warning
    9. '   4. Low water
    10. '   5. Hood open
    11. '   6. Car radio turned on
    12.    
    13.     For i = 0 To 7
    14.         GlobalIOState(i) = ReadIOchannel(i + 1 + card_nr * 16)
    15.         Select Case i
    16.         Case Is = 0
    17.             If GlobalIOState(i) = True Then
    18.                 'Parking Brake is On
    19.             Else
    20.                 'Parking Brake is off
    21.             End If
    22.         Case Is = 1
    23.             If GlobalIOState(i) = True Then
    24.                 'Door is Open
    25.             Else
    26.                 'Door is Closed
    27.             End If
    28.         Case Is = 2
    29.             If GlobalIOState(i) = True Then
    30.                 'Trunk is Open
    31.             Else
    32.                 'Trunk is Closed
    33.             End If
    34.        
    35.         'etc, etc, ...
    36.         End Select
    37.     Next i
    38. End Sub

    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.
    VB Code:
    1. 'Toggle state of interior lights
    2. Private Sub Command1_Click()
    3.  Static LightsON As Boolean
    4.  LightsON = Not LightsON
    5.  If LightsON Then
    6.     SetIOchannel 5
    7.  Else
    8.     ClearIOchannel 5
    9.  End If
    10. End Sub

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    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.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    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.

  13. #13
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Problem with a parallel port module in VB6

    If you get a chance, post the exact code you are developing.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    Re: Problem with a parallel port module in VB6

    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:
    1. Private Sub Timer1_Timer()
    2. If ReadIOchannel(1) = 1 Then Input1 = True Else Input1 = False 'Read channel1 and set Bool Var accordingly
    3. If ReadIOchannel(2) = 2 Then Input2 = True Else Input2 = False 'Read channel2 and set Bool Var accordingly
    4. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width