Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.ComponentModel
- Imports Brainboxes.IO
- Imports System.Threading
- Imports System.Timers
- Imports System.Windows.Threading
- Class MainWindow
- ' BRAINBOX 1
- Dim WithEvents ed1 As EDDevice
- Dim val1(2) As Integer 'range of Val() variable is 3
- Public ReadOnly worker1 As BackgroundWorker = New BackgroundWorker()
- Dim dimT1 As New DispatcherTimer()
- Dim HasStarted1 As Boolean
- 'BRAINBOX 2
- Dim WithEvents ed2 As EDDevice
- Dim val2(2) As Integer 'range of Val() variable is 3
- Public ReadOnly worker2 As BackgroundWorker = New BackgroundWorker()
- Dim dimT2 As New DispatcherTimer()
- Dim HasStarted2 As Boolean
- Public Sub New()
- InitializeComponent()
- 'BRAINBOX 1
- ed1 = EDDevice.Create(My.Settings.BoxIP)
- ed1.Label = "Supervision des pompes de relevages"
- worker1.WorkerReportsProgress = True
- AddHandler worker1.DoWork, AddressOf worker_DoWork
- 'AddHandler worker.RunWorkerCompleted, AddressOf worker_RunWorkerCompleted
- AddHandler worker1.ProgressChanged, AddressOf worker1_progresschanged
- 'worker.RunWorkerAsync(100)
- dimT1.Interval = New TimeSpan(100)
- dimT1.IsEnabled = True
- AddHandler dimT1.Tick, AddressOf TimerTicked1
- dimT1.Start()
- 'BRAINBOX 2
- ed2 = EDDevice.Create(My.Settings.BoxIP2)
- ed2.Label = "Supervision des pompes de relevages"
- worker2.WorkerReportsProgress = True
- AddHandler worker2.DoWork, AddressOf worker_DoWork
- 'AddHandler worker.RunWorkerCompleted, AddressOf worker_RunWorkerCompleted
- AddHandler worker2.ProgressChanged, AddressOf worker2_progresschanged
- 'worker.RunWorkerAsync(100)
- dimT2.Interval = New TimeSpan(100)
- dimT2.IsEnabled = True
- AddHandler dimT2.Tick, AddressOf TimerTicked2
- dimT2.Start()
- End Sub
- Private Sub TimerTicked1(sender As Object, e As EventArgs)
- worker1.ReportProgress(0)
- End Sub
- Private Sub TimerTicked2(sender As Object, e As EventArgs)
- worker2.ReportProgress(0)
- End Sub
- Private Sub checkState(state As Object)
- End Sub
- Private Sub worker1_progresschanged(sender As Object, e As ProgressChangedEventArgs)
- 'Check if the program has started before setting the Checkbox(rectangle) images
- If Not HasStarted Then
- Exit Sub
- End If
- Try
- If val1(0) = 1 Then
- rectangle1.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinEteind.png",
- UriKind.Absolute))}
- rectangle2.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinVert.png",
- UriKind.Absolute))}
- ElseIf Val1(0) = 0 Then
- rectangle1.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinRouge.png",
- UriKind.Absolute))}
- rectangle2.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinEteind.png",
- UriKind.Absolute))}
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- Private Sub worker2_progresschanged(sender As Object, e As ProgressChangedEventArgs)
- 'Check if the program has started before setting the Checkbox(rectangle) images
- If Not HasStarted2 Then
- Exit Sub
- End If
- Try
- If val2(0) = 1 Then
- rectangle1.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinEteind.png",
- UriKind.Absolute))}
- rectangle2.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinVert.png",
- UriKind.Absolute))}
- ElseIf Val2(0) = 0 Then
- rectangle1.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinRouge.png",
- UriKind.Absolute))}
- rectangle2.Fill = New ImageBrush With {
- .ImageSource = New BitmapImage(New Uri(
- System.AppDomain.CurrentDomain.BaseDirectory &
- "img\TemoinEteind.png",
- UriKind.Absolute))}
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- Private Sub worker1_DoWork(sender As Object, e As DoWorkEventArgs)
- End Sub
- Private Sub worker2_DoWork(sender As Object, e As DoWorkEventArgs)
- End Sub
- Private Sub worker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
- End Sub
- Private Sub worker2_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
- End Sub
- Private Sub ed1_IOLineFallingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed1.IOLineFallingEdge
- HasStarted1 = True
- val1(0) = ed1.Inputs(0).Value
- End Sub
- Private Sub ed1_IOLineRisingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed1.IOLineRisingEdge
- HasStarted1 = True
- val1(0) = ed1.Inputs(0).Value
- End Sub
- Private Sub ed2_IOLineFallingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed2.IOLineFallingEdge
- HasStarted2 = True
- val2(0) = ed2.Inputs(0).Value
- End Sub
- Private Sub ed2_IOLineRisingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed2.IOLineRisingEdge
- HasStarted2 = True
- val2(0) = ed2.Inputs(0).Value
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement