One Shot BIt in VB or structured text file

controlconcepts

Lifetime Supporting Member
Join Date
Oct 2008
Location
boston
Posts
300
I have been working with VB a lot lately mostly for Archie's Advanced HMI. Been learning some good stuff but for the life of me I cant Figure out how to make a Oneshot bit other than something like this

If PLCLogTrip = False And OneShot(11) = False Then
OneShot(11) = True
LAtPLC.StartTimer()
End If
If PLCLogTrip And OneShot(11) = True Then
OneShot(11) = False
'countarry = countarry + 1
'LAmysetcnt.Text = "MY Sett Count " & My.Settings.FirstString.Count
LAtPLC.StopTimer()
End If
But i need a global bit to work outside of that if statement else where.

Thanks
Matt
 
The ST standard includes EDGE, EDGEPOS, and EDGENEG keywords that look for the BOOL variable or statement to the right to change states.
MyOS:= EDGEPOS(MyCondition);
You can't used these in a loop though, for that you need to use R_Trig(), F_Trig(), and RF_Trig(), which are function blocks.

As far as VB is concerned, there is usually an attribute/property for every datatype to check if it changed values. Just type the name of a variable and then '.' and see if one of the things is ValueChanged or something similar. It might go like this:

MyOS= MyCondition;
IF(MyOS.ValueChanged){ Do this stuff; }
 
Thanks Captain.. I can't find anything like that in vb.net. What is a good reference for Ladder logic compared to text based Boolean? I think I have found a page before but don't remember where I found it
Thanks Matt..
 
What about something like this:
Code:
    Private OneShot(20) As Boolean
    Private PLCLogTrip As Boolean

    Private Sub Process()
        If Not PLCLogTrip Then
            If Not OneShot(11) Then
                LAtPLC.StartTimer()
            End If
            OneShot(11) = True
        Else
            If OneShot(11) Then
                LAtPLC.StopTimer()
            End If
            OneShot(11) = False
        End If
    End Sub
 
Thanks yet again Archie.. That Looks better than What I came up with. But I am still wondering how or if there is a way to make a OneShot that can be used outside of the Private Sub. Like I found this for a toggle bit.
TgBit(1) = Not (TgBit(1))

Witch is the best way in one line to make a toggle bit that I found thus far. Just need the bit to stay high for one scan thru the form code.
Matt
 
I may not be completely understanding what you are wanting to do. With the variables declared outside of the "Private Sub", they will keep their values and can be used in any of the subroutines within the class. As long as the instance of that class exists, the variable will exist and hold its value. On the other hand, if a variable is declared with a Dim statement within the sub, then their scope (or lifetime) only exists within the sub. After the sub is finished executing, the variable is disposed.

Using the terminology "one scan through the form code" doesn't really apply to VB since the language is event driven and not "scanned". For example, this code:
Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        x = 1
    End Sub
will never execute until the button is clicked.
 
Example code

Thanks Archie for expanding. I get what you mean about event driven and understand that. Sorry I am bad at writing / typing what I mean in my head sometimes! I am much better speaking out my thoughts.. I should have expanded on what I am tring to accomplish. The event I have is a timer. Within that timer I check a bunch of bits for status. For example I have a NetworkStatus Bit, ServerConn Bit and a BtnDisconect Bit that are from other events.

In my timer code I check for state change and then Log the event. The issue I have is if NetworkStatus bit is High and BtnDisconnect is Low I need to still trigger the the same Log event. The same for ServerConn and it's event. If BtnDisconnect is Low The log event for NetworkStatus & ServerConn should log event as stopped. So I was trying to have the BtnDisconnect as a "one shot" for one tick of the timer event and set the Log events.

Here is the code that resides in the timer.
' ***********************************************************
' * Server up time calculation and string save
' ***********************************************************
Dim TestingEnabBit As Boolean
Dim SvrCommTrip As Boolean
Dim LocNetConnTrip As Boolean
Dim PLCLogTrip As Boolean
Dim BTNDiscnVisBitOs As Boolean
Dim ClientConnBitOs As Boolean



'**********************************************************
' Toggle between testing and live running system
If TgBit(1) Then
TestingEnabBit = True
SvrCommTrip = TgBit(2)
LocNetConnTrip = TgBit(3)
PLCLogTrip = TgBit(4)
Else
TestingEnabBit = False
SvrCommTrip = ClientConnBit
LocNetConnTrip = LocalNetConn
PLCLogTrip = PLC_TmrFault
End If
' This is where I am tryig to set a bit once
' to trigger the propper event
If TestingEnabBit = False Then
If btndisconnect.Visible = False And BTNDiscnVisBitOs = False Then
BTNDiscnVisBitOs = True
SvrCommTrip = True
End If
' ---------------------------------
If btndisconnect.Visible = True And BTNDiscnVisBitOs Then
BTNDiscnVisBitOs = False
'SvrCommTrip = False
End If

If ClientConnBit And ClientConnBitOs = False Then
ClientConnBitOs = True
SvrCommTrip = True
End If
' ---------------------------------
If ClientConnBit = False And ClientConnBitOs = True Then
ClientConnBitOs = False
'SvrCommTrip = False
End If
'===================
' Buttons text change for testing
BtnTest2.Text = "Test 2"
BtnTest3.Text = "Test 3"
BtnTest4.Text = "Test 4"
Else
BtnTest2.Text = "Svr Sim"
BtnTest3.Text = "Net C Sim"
BtnTest4.Text = "PLC T Sim"
End If


If SvrCommTrip And OneShot(10) = False Then
OneShot(10) = True
''''''SvrCommTrip = False
LAtSvrComm.StartTimer()

Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtSvrComm.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
End If
' ------------
If SvrCommTrip = False And OneShot(10) = True Then
OneShot(10) = False
''''''SvrCommTrip = False
LAtSvrComm.StopTimer()
LBSvrConn.Items.Clear()

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtSvrComm.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
Dim TList As Array
TList = LAtSvrComm.TimeList.ToArray
''''' work on
'My.Settings.SvrConnStg = LAtSvrComm.TimeList
'Me.Text = LAtSvrComm.TimeList.ToString

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
If Not My.Settings.SvrConnStg Is Nothing Then
My.Settings.SvrConnStg.Clear()
End If
For Idex = 0 To 19
If Not String.IsNullOrEmpty(LAtSvrComm.TimeArray(Idex)) Then
LBSvrConn.Items.Add(LAtSvrComm.TimeArray(Idex))
My.Settings.SvrConnStg.Add(LAtSvrComm.TimeArray(Idex))
End If
Next
My.Settings.Save()
End If


'***************************************************
' Local Network Comm loging
If LocNetConnTrip = False And OneShot(11) = False Then
OneShot(11) = True
LAtLocNet.StartTimer()
Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtLocNet.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
End If
' ------------------------------------------------
If LocNetConnTrip And OneShot(11) = True Then
OneShot(11) = False
Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtLocNet.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
End If
LAtLocNet.StopTimer()
LBPLCCom.Items.Clear()



'***************************************************
' PLC Comm loging
If PLCLogTrip = False And OneShot(12) = False Then 'And RcvTmr.Enabled Then
OneShot(12) = True
LAtPLC.StartTimer()
Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtPLC.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
End If
' ------------------------------------------------
If PLCLogTrip And OneShot(12) = True Then
OneShot(12) = False
If SelectedDGV = 3 Then
Dim TListBindSource As New BindingSource
TListBindSource.DataSource = LAtPLC.TimeList
DGVList.DataSource = TListBindSource
DGVList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DGVList.AutoResizeColumns()
End If
LAtPLC.StopTimer()
LBPLCCom.Items.Clear()
If Not My.Settings.PLCCommStg Is Nothing Then
My.Settings.PLCCommStg.Clear()
End If
For Idex = 0 To 19
If Not String.IsNullOrEmpty(LAtPLC.TimeArray(Idex)) Then
LBPLCCom.Items.Add(LAtPLC.TimeArray(Idex))
My.Settings.PLCCommStg.Add(LAtPLC.TimeArray(Idex))
End If
Next
My.Settings.Save()
End If

It think I have a theory now as i look at this.. Maybe to have the OneShot(X) bits to set to true or false at the end of the timer or at the start.

Thanks Matt..
 
I think I am starting to understand what you want. I did a little refactoring and renaming to help me understand. Does this look like I am on the right track:
Code:
    Private DisconnectButtonVisibleBitOneShot As Boolean
    Private ClientConnBitOneShot As Boolean

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        ' ************************************************** *********
        ' * Server up time calculation and string save
        ' ************************************************** *********
        Dim TestingEnabBit As Boolean = TgBit(1)
        Dim SvrCommTrip As Boolean = ClientConnBit
        Dim LocNetConnTrip As Boolean = LocalNetConn
        Dim PLCLogTrip As Boolean = PLC_TmrFault
 


        '******************************************
        ' Set for Testing?
        '******************************************
        If TestingEnabBit Then
            SvrCommTrip = TgBit(2)
            LocNetConnTrip = TgBit(3)
            PLCLogTrip = TgBit(4)

            btnTest2.Text = "Svr Sim"
            btnTest3.Text = "Net C Sim"
            btnTest4.Text = "PLC T Sim"
        Else
            '**************************************************************************************
            ' This is closer to a ladder logic implementation
            ' Two parallel branches each with an ONS and the SvrCommTrip as the OTE
            SvrCommTrip = (Not btnDisconnect.Visible And Not DisconnectButtonVisibleBitOneShot) _
                         Or (ClientConnBit And Not ClientConnBitOneShot)

            '* Set the one shots to the conditions prior to them
            DisconnectButtonVisibleBitOneShot = Not btnDisconnect.Visible
            ClientConnBitOneShot = ClientConnBit
            '**************************************************************************************

            '===================
            ' Buttons text change for testing
            btnTest2.Text = "Test 2"
            btnTest3.Text = "Test 3"
            btnTest4.Text = "Test 4"
        End If
 

Similar Topics

Hi, Does anyone have any idea how to write an OSR (one shot rising) as we have in RSLogix with jst normal XIC/XIO instructions? Just to know. Thx.
Replies
4
Views
3,814
Hello all. This is a very lonnnnnnng shot but worth a try. I have an OMS Group Impact100 metering machine. At this customer it blows foam into 3d...
Replies
0
Views
182
Howdy Everyone, So I have been retrofitting a cell to run different fixtures and updating it with new drives and a few other things. It runs...
Replies
15
Views
1,495
Hi all, I am working on a ladder program in AS and I was to trigger a reading on my IO link sensor every .5 s, and use that value to run a...
Replies
1
Views
535
Back
Top Bottom