Results 1 to 4 of 4

Thread: Need assistance adding a timed lockout to application (Working but with issues)

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    32

    Need assistance adding a timed lockout to application (Working but with issues)

    I would love a 2nd set of eyes because what I need to accomplish has to be easy I am just over thinking this thing.

    First some Background: I have a program that uses Phidgets RFID readers and a weight sensor, All of this and the current state of the program works perfectly.

    When the RFID reader reads a tag it makes sure the min. weight is also present and then launches a macro in another program. If the Tag goes out of range and/or the weight on the scale goes below the min. it stops, rinses and repeats when a tag is scanned again.

    FYI this whole apparatus is for Behavioral Pigeon research in a college Psychology Dept. We use an industry standard program for our research but is has no customization or autonomy. That is where my app comes in, simply put it listens for the RFID and weight and if given the go it passes the info to the Psych program via simple macros the psych program will accept. The whole thing is ties to a contraption that allows the pigeons to choose when they want to run experiments for us in return for yummy birdseed rewards..... Anyway

    Now for the Issue:

    We now want to add a contingency to lockout greedy pigeons who has began guarding the platform so only they can access the system for food (The RFID tag is on each pigeons ankle so the system recognizes them by ID/Name)

    So I added a timer that we can customize with a text box IE: 30000ms, then tied it to a checkbox so we can turn the condition on and off. That works fine. What I need is when the pigeon leaves and the system resets everything it starts the timer, If that same RFID tag is scanned again within that timer it ignores it and simply logs the scan but does not run the macro. If a different RFID scans it just runs as normal.

    Here is the current Sub that handles RFID Tags and works as normal:

    Code:
     'Tag event handler...we'll display the tag code in the field on the GUI
        Public Sub PhidgetRfidTag(ByVal sender As Object, ByVal e As TagEventArgs) Handles PhidgetRfid.Tag
    
            MinimumStartThreshhold = CInt(FormOpt.TxtBxMinStart.Text)
            gramData = CInt(ActiveWeight.Text)
    
            LabelTagLive.Text = e.Tag
    
            If e.Tag IsNot Nothing Then
                ValidTag = True
            Else
                ValidTag = False
            End If
    
            If gramData > MinimumStartThreshhold Then
                ValidWeight = True
            Else
                ValidWeight = False
            End If
    
            If ValidTag And ValidWeight = True Then
                UpdateTextBoxNormal()  '-Updates the DataGrid with Subject and RFID info.
                MacroExecute()            '-Runs the Macro to Launch Med-PC IV
            Else
            End If
    
        End Sub
    Pretty Basic, no shock it works fine

    So when I add the conditions for watching if a tag string is locked out I used the following changes with odd results...

    I made a simple sub to compare the incoming string to the last:
    Code:
        Public Sub LockoutCompare()
            Dim TagScanned = LabelTagCurrent.Text
            Dim TagLast = LabelTagLast.Text
    
            If String.Equals(TagScanned, TagLast) = True Then
                Lockout = True
            Else
                Lockout = False
    
            End If
    
        End Sub
    I have gotten mixed info on how to use the String.Equals function should I represent the boolean answers as True/False or 0/1? or does it matter?

    Then I added the extra conditions to the closing of sessions by simply starting the timer if the box is checked:

    Code:
     If FormOpt.CheckBoxDelay.Checked Then
                TimerLockout.Start()
                Lockout = True
            End If
    On the Timer Tick:

    Code:
    Private Sub TimerLockout_Tick(sender As Object, e As EventArgs) Handles TimerLockout.Tick
            TimerLockout.Stop() 
            Lockout = False '-Stops the timer if Previous RFID does not return then sets lockout to False
        End Sub
    And finally the changes made to the On tag Event:
    Code:
        'Tag event handler...we'll display the tag code in the field on the GUI
        Public Sub PhidgetRfidTag(ByVal sender As Object, ByVal e As TagEventArgs) Handles PhidgetRfid.Tag
    
            MinimumStartThreshhold = CInt(FormOpt.TxtBxMinStart.Text)
            gramData = CInt(ActiveWeight.Text)
    
            LabelTagLive.Text = e.Tag
    
            If e.Tag IsNot Nothing And FormOpt.CheckBoxDelay.Checked = False Then
                ValidTag = True
            Else
                ValidTag = False
            End If
    
            If gramData > MinimumStartThreshhold Then
                ValidWeight = True
            Else
                ValidWeight = False
            End If
    
            If FormOpt.CheckBoxDelay.Checked = True Then
                LockoutCompare()
                If Lockout = True And TimerLockout.Enabled = True Then
                    UpdateTextBoxLockout()  '-Update DataGrid to reflect Lockout
                    TimerLockout.Start()    '-Restart the Timer
                Else
    
                End If
            End If
    
            If ValidTag And ValidWeight = True Then
                UpdateTextBoxNormal()
                MacroExecute()
            Else
            End If
    
        End Sub
    In a nutshell what I have works halfway... If I enable the checkbox it basically locks out everything haha. The answer has got to be plain enough to allow you all to shame me ...

    Anyone got something?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,023

    Re: Need assistance adding a timed lockout to application (Working but with issues)

    Pigeons are suckers! I'd be wanting minimum wage, at least.

    First off: This is pretty cool, in general.

    Second: You shouldn't be using CInt to convert user input into an integer. Use Integer.TryParse instead. CInt will throw an exception if somebody forgets to enter something or enters something that isn't a string. Alternatively use a NumericUpDown control rather than a textbox, in which case CInt will be totally fine. Those are minor points, though.

    Third: As to the main point, the key would be to put a breakpoint on the call to LockoutCompare and step through that method. I'm not keen on using labels to hold strings when a string variable would do, but the .Text property of a label is a string, so it should work fine. You don't need to use that String.Equals, since the = and <> operators work just fine for strings, which means that method could be reduced to:

    Code:
    Public Sub LockoutCompare()
       LockOut = (LabelTagLast.Text = LabelTagCurrent.Text)
    End Sub
    That single line does the same thing that your method does, so you could clearly remove the method entirely and put that right into the event handler. That might make it easier to see a problem. For example, you make use of LabelTagCurrent and LabelTagLast, but in the event handler you only appear to set LabelTagLive, which you don't appear to compare to, but which clearly should hold the same thing as LabelTagCurrent....whatever that is. Does it? Also, where do you set LabelTagLast?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    32

    Re: Need assistance adding a timed lockout to application (Working but with issues)

    Awesome, I will make some changes....I don't consider myself a Novice but I can be dangerous HA! I have used the = and <> in other conditions in my app...I should have seen that /BONK.

    More info as it Develops
    <3 VBForums folks

  4. #4

    Re: Need assistance adding a timed lockout to application (Working but with issues)

    Quote Originally Posted by gwilkinson View Post
    Awesome, I will make some changes....I don't consider myself a Novice but I can be dangerous HA! I have used the = and <> in other conditions in my app...I should have seen that /BONK.

    More info as it Develops
    <3 VBForums folks
    If I get the time when I get home, I'll sift through this miniature program. It grabbed my attention and I'm merely replying now to make sure I get updates via email.

    Hope things work out for you (if you get this solved before I get home).

Tags for this Thread

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