Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Parallel Port Interface Real Time Counter Trouble.


Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2008, 10:26 AM
chr chr is offline
Newcomer
 
Join Date: Jan 2008
Posts: 1
Default Parallel Port Interface Real Time Counter Trouble.


Greetings to all, I am having small issues with a Visual Basic 6 code I am working on to widen my knowledge. I'm new to the programming scene, hopefully someone here will be able to help.

I'll be lighting up LED lights via Parallel Port. My code is written in Vb6. I'm using the inpout32.dll to send my signals to the pins. I am using a breadboard to establish the circuit. Basically what I am having trouble is to code a counter that can count how many times the LED light is blinking. I have little knowledge about Timers, everything I read about it isn't really helping me. I'll paste my code down here and try and explain it as well as I can in English.

MAIN PROBLEM : Coding a counter that can detect how many times the LED light blinks in real time. I know how to make the light stop blinking after X amount of seconds, that's simple to do. I am just lost on how to be able to make the counter detect how many times it's actually blinking in real time.

Private Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal sgnGo As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal sgnGo As Integer, ByVal Value As Integer)


'Variable to send the signals to the pins

Dim sgnGo As String 'Variable to send the single
Dim onOff as Long 'Variable to make the LED blink on/off

'The HEX code for the LPT1 port defined in form_load

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Timer2.Enabled = False
Timer2.Interval = 2000
sgnGo = &H378
End Sub

'Out is to simply send the signal to the pin using inpout32.dll

Private Sub pn1_Click()
Timer1.Enabled = True
Timer2.Enabled = False
Out sgnGo, 1
End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = True
Timer2.Enabled = False
onOff = onOff Xor 1 'Light blinks on/off every 1 second
Out sgnGo, onOff
End Sub

Private Sub pn2_Click()
Timer2.Enabled = True
Timer1.Enabled = False
Out sgnGo, 2
End Sub

Private Sub Timer2_Timer()
Timer2.Enabled = True
Timer1.Enabled = False
onOff = onOff Xor 2 'Light blinks on/off every 2 seconds
Out sgnGo, onOff
End Sub

'Procedure to turn off LED lights
Private Sub sgnArret_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Out sgnGo, 0
End Sub
Reply With Quote
  #2  
Old 01-22-2008, 07:05 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,890
Default

I'm not sure what the question is.
Do you just want to display a total running count for both in one value, or a running count for each, or what?

If a running count, then there are several approaches you can take.
Since you toggle the light every time the timer fires, you could just increment a value in the timer and display that number divided by 2.

Led1_Counter = Led1_Counter + 1
Label_Cnt_1.Caption = Led1_Counter \ 2

You could just check the bit being set in the timer and increment the counter,

If onOff And 1 then Led1_Counter = Led1_Counter + 1
Label_Cnt_1.Caption = Led1_Counter

If onOff And 2 Then Led2_Counter = Led2_Counter + 1
Label_Cnt_2.Caption = Led2_Counter

I'm not sure it that is what you are after.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->