Link states and progress bar
When we click Connect, the KINGSTAR Subsystem starts to link to hardware. To display the link state, we use a Text Block and Progress Bar.
Text Block: link states
We use a Text Block to display the states of an EtherCAT link. A Text Block is like a label, but it can display only strings, while Label can display a variety of data such as numbers, dates, strings, images, and others. In this sample we only need to display text (string), so we use a Text Block.
To present a link state, we just need to bind the state of an EtherCAT connection with the Text Block. To bind it, in the Text attribute, use {Binding} to bind Subsystem.State. We set FallbackValue to ecatOffline, which is displayed when data binding is unable to return a value.
<TextBlock DockPanel.Dock="Right" Foreground="White" HorizontalAlignment="Right"
Text="{Binding Subsystem.State, FallbackValue=ecatOffline}"/>
An EtherCAT link has four states: Init, Pre-Operational (Pre-Op), Safe-Operational (Safe-Op), and Operational (Op). When the state is Op, the connection has been created. The Text Block reflects these states automatically during linking.
Progress Bar: the linking progress
A progress bar shows a process that requires long time to finish. The use of Progress Bar is similar to Text Block. To present a process, we just need to bind the IsConnecting variable with the Progress Bar. IsConnecting is a flag representing the state of an EtherCAT link. To bind it, in the IsIndeterminate attribute, use {Binding} to bind IsConnecting. When IsConnecting is true, the bar animation starts; when it is false, the animation stops. Since IsConnecting is linked with the Connect button, the bar animation is controlled by the action of the button.
<ProgressBar DockPanel.Dock="Right" Height="25" Width="150" Margin="20,3,5,3"
IsIndeterminate="{Binding IsConnecting}"/>