RobotStudio event

SignalBindingSource Changed Event

Options
How do I tell if my signal in the SignalBindingSource has changed, i.e. how do I create that event handler?
 

Shane

Comments

  • RussD
    Options
    Here is a sample of how to set up SignalBInding programmatically:
     


    Dim sbsOutputs as SignalBIndingSource
    sbsOutputs =
    New SignalBindingSource
    AddHandler
    sbsOutputs.ListChanged, AddressOf sbsOutputs_ListChanged
    For
    i As Integer = 0 To <some collection>Count - 1
         Dim
    so As New SignalObject(<some collection>.Item(i).ToString)
         sbsOutputs.Add(so)

    Next

    'must call ResumeBinding to start ListChanged event notifications

    sbsOutputs.ResumeBinding()

    Private
    Sub sbsOutputs_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs)
         Dim
    strSigName As String = sbsOutputs.Signals(e.NewIndex).Name
         Dim
    singCurrVal As Single = sbsOutputs.Signals(e.NewIndex).Value
         Try
              For
    i As Integer = 0 To Me.<some container>.Controls.Count - 1
              'search through the LEDs for one with the matching signal name text
              If Me.<some container>.Controls(i).Text = strSigName Then
              'if we find it, cast it to type LED and set its value, then break out of the loop
               CType(Me.<some container>.Controls(i), Led).Value = singCurrVal
               Exit For
               End If
          Next
    Catch ex As Exception
          Trace.WriteLine(
    "[sbsOutputs_ListChanged]exception: " & ex.Message)
    End Try
    End
    Sub
    Russell Drown
  • Thanks Russ,
    I can work through the conversion from VB to C#.  However, do you have it in C#?  If not I can do the conversion.

     

    Thanks!

    Shane
  • I have now figured out my problem but I need help to understand it. 
     

    I am using the Event Handler:


    void
    sbsDO_001_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
    {

    }

    This never gets called until I associate a DataGrid to it.  For example, I create a new solution and add a SignalBindingSource to it.  I create the event handler


    this
    .sbsDO_001.ListChanged += new System.ComponentModel.ListChangedEventHandler(sbsDO_001_ListChanged);
    Next I run it and change the signal, nothing happens.  I then add the DataGrid and bind it to the signalbindingsource.  Everything works fine. 

     

    My question is do I have to use the signal binding on a control in order to get the event handler to work?

     

    Also, this does go back to the question about why is the DataGrid the only component that works with the signal binding?  This question is found in the Thread:

     

    RAB basics problemm: FP SDK, SignalBindingSource


    Shane
  • Now I am getting confused, as soon as I make the DataGrid invisible the event handler quits working.  Angry
     

     

    Any ideas?
  • carlosmtz2000
    Options

    Hi Shane,

    The Binding mechanism lets yout synchronize a data base (in our case, the IRC5) with the controls of a user interface. The connection from the user interface to the IRC5 consumes resources and communication time. Due to this, the binding mechanism is automatically suspended if it detects that the control to which is connected is not visible.

    Regarding the problem of the signal binding, I have started to look at this.

    Saludos / Carlos
    Carlos Martinez
    ABB
  • RussD
    Options
    Is your ListChanged handler empty? Try putting something in there like
     

    ABB.Robotics.Diagnostics.Trace.Writeline("signal changed");

     

    and see if it gets called everytime then. In the code sample above, there is no data binding in use, but there is code in the event handler. If you are binding the data source to a control, there is no need handle the ListChanged event, because the designer takes care of this for you.

     

    Signal binding through the designer works with TpsLabels, the problem is that you have to have a dedicated binding source for each signal that you care about, and bind each source to a separate label control. There is no mechanism in the designer to select the individual signal you might care about and bind it to an individual label, when you have multiple signals in a source and bind it to a label, you automatically get the first signal in the collection. That's why it makes more sense to use a single binding source with a bindable control that has an item collection like the DataGrid.

     

    In the sample above I did not want to do this, instead I wanted to use the LED control (which does not support data binding right now), so I implemented my own handler and skipped data binding altogether. In this case its much easier to use the binding source control than it is to manually set up individual signal subscriptions.

     

     
    Russell Drown
  • Thanks guys!
     

    Carlos, that makes sense why when the control is invisible it does not work.Thumbs Up

     

    Russell, for what ever reason (Carlos is looking at it) labels do not work with some of our applications.  However, DataGrids do.  I understand that I would have to write some code to look at different signals in the bindingsource or use one source for each signal. Your code works great!

     

    So my question is, what is the best way to look at a signal that I do not want on the GUI?  Should I not use the binding source and just code it?

     

    Thanks again,

    Shane