Advertisement
Bucher100

Help for brainbox

Apr 17th, 2020
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.57 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports Brainboxes.IO
  3. Imports System.Threading
  4. Imports System.Timers
  5. Imports System.Windows.Threading
  6.  
  7. Class MainWindow
  8.     ' BRAINBOX 1
  9.     Dim WithEvents ed1 As EDDevice
  10.     Dim val1(2) As Integer 'range of Val() variable is 3
  11.     Public ReadOnly worker1 As BackgroundWorker = New BackgroundWorker()
  12.     Dim dimT1 As New DispatcherTimer()
  13.     Dim HasStarted1 As Boolean
  14.     'BRAINBOX 2
  15.     Dim WithEvents ed2 As EDDevice
  16.     Dim val2(2) As Integer 'range of Val() variable is 3
  17.     Public ReadOnly worker2 As BackgroundWorker = New BackgroundWorker()
  18.     Dim dimT2 As New DispatcherTimer()
  19.     Dim HasStarted2 As Boolean
  20.     Public Sub New()
  21.  
  22.         InitializeComponent()
  23.  
  24.         'BRAINBOX 1
  25.         ed1 = EDDevice.Create(My.Settings.BoxIP)
  26.         ed1.Label = "Supervision des pompes de relevages"
  27.  
  28.         worker1.WorkerReportsProgress = True
  29.         AddHandler worker1.DoWork, AddressOf worker_DoWork
  30.         'AddHandler worker.RunWorkerCompleted, AddressOf worker_RunWorkerCompleted
  31.         AddHandler worker1.ProgressChanged, AddressOf worker1_progresschanged
  32.         'worker.RunWorkerAsync(100)
  33.         dimT1.Interval = New TimeSpan(100)
  34.         dimT1.IsEnabled = True
  35.         AddHandler dimT1.Tick, AddressOf TimerTicked1
  36.         dimT1.Start()
  37.  
  38.         'BRAINBOX 2
  39.         ed2 = EDDevice.Create(My.Settings.BoxIP2)
  40.         ed2.Label = "Supervision des pompes de relevages"
  41.  
  42.         worker2.WorkerReportsProgress = True
  43.         AddHandler worker2.DoWork, AddressOf worker_DoWork
  44.         'AddHandler worker.RunWorkerCompleted, AddressOf worker_RunWorkerCompleted
  45.         AddHandler worker2.ProgressChanged, AddressOf worker2_progresschanged
  46.         'worker.RunWorkerAsync(100)
  47.         dimT2.Interval = New TimeSpan(100)
  48.         dimT2.IsEnabled = True
  49.         AddHandler dimT2.Tick, AddressOf TimerTicked2
  50.         dimT2.Start()
  51.  
  52.     End Sub
  53.  
  54.  
  55.     Private Sub TimerTicked1(sender As Object, e As EventArgs)
  56.  
  57.         worker1.ReportProgress(0)
  58.     End Sub
  59.     Private Sub TimerTicked2(sender As Object, e As EventArgs)
  60.  
  61.         worker2.ReportProgress(0)
  62.     End Sub
  63.  
  64.     Private Sub checkState(state As Object)
  65.     End Sub
  66.  
  67.  
  68.     Private Sub worker1_progresschanged(sender As Object, e As ProgressChangedEventArgs)
  69.         'Check if the program has started before setting the Checkbox(rectangle) images
  70.         If Not HasStarted Then
  71.             Exit Sub
  72.         End If
  73.  
  74.         Try
  75.             If val1(0) = 1 Then
  76.  
  77.                 rectangle1.Fill = New ImageBrush With {
  78.                         .ImageSource = New BitmapImage(New Uri(
  79.             System.AppDomain.CurrentDomain.BaseDirectory &
  80.             "img\TemoinEteind.png",
  81.                 UriKind.Absolute))}
  82.                 rectangle2.Fill = New ImageBrush With {
  83.                         .ImageSource = New BitmapImage(New Uri(
  84.                         System.AppDomain.CurrentDomain.BaseDirectory &
  85.                             "img\TemoinVert.png",
  86.                             UriKind.Absolute))}
  87.             ElseIf Val1(0) = 0 Then
  88.  
  89.                 rectangle1.Fill = New ImageBrush With {
  90.                         .ImageSource = New BitmapImage(New Uri(
  91.                             System.AppDomain.CurrentDomain.BaseDirectory &
  92.                             "img\TemoinRouge.png",
  93.                             UriKind.Absolute))}
  94.                 rectangle2.Fill = New ImageBrush With {
  95.                         .ImageSource = New BitmapImage(New Uri(
  96.                             System.AppDomain.CurrentDomain.BaseDirectory &
  97.                             "img\TemoinEteind.png",
  98.                             UriKind.Absolute))}
  99.  
  100.             End If
  101.  
  102.         Catch ex As Exception
  103.             MsgBox(ex.Message)
  104.         End Try
  105.     End Sub
  106.  
  107.  
  108.     Private Sub worker2_progresschanged(sender As Object, e As ProgressChangedEventArgs)
  109.         'Check if the program has started before setting the Checkbox(rectangle) images
  110.         If Not HasStarted2 Then
  111.             Exit Sub
  112.         End If
  113.  
  114.         Try
  115.             If val2(0) = 1 Then
  116.  
  117.                 rectangle1.Fill = New ImageBrush With {
  118.                         .ImageSource = New BitmapImage(New Uri(
  119.             System.AppDomain.CurrentDomain.BaseDirectory &
  120.             "img\TemoinEteind.png",
  121.                 UriKind.Absolute))}
  122.                 rectangle2.Fill = New ImageBrush With {
  123.                         .ImageSource = New BitmapImage(New Uri(
  124.                         System.AppDomain.CurrentDomain.BaseDirectory &
  125.                             "img\TemoinVert.png",
  126.                             UriKind.Absolute))}
  127.             ElseIf Val2(0) = 0 Then
  128.  
  129.                 rectangle1.Fill = New ImageBrush With {
  130.                         .ImageSource = New BitmapImage(New Uri(
  131.                             System.AppDomain.CurrentDomain.BaseDirectory &
  132.                             "img\TemoinRouge.png",
  133.                             UriKind.Absolute))}
  134.                 rectangle2.Fill = New ImageBrush With {
  135.                         .ImageSource = New BitmapImage(New Uri(
  136.                             System.AppDomain.CurrentDomain.BaseDirectory &
  137.                             "img\TemoinEteind.png",
  138.                             UriKind.Absolute))}
  139.  
  140.             End If
  141.  
  142.         Catch ex As Exception
  143.             MsgBox(ex.Message)
  144.         End Try
  145.     End Sub
  146.  
  147.  
  148.     Private Sub worker1_DoWork(sender As Object, e As DoWorkEventArgs)
  149.  
  150.     End Sub
  151.     Private Sub worker2_DoWork(sender As Object, e As DoWorkEventArgs)
  152.  
  153.     End Sub
  154.     Private Sub worker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
  155.  
  156.     End Sub
  157.     Private Sub worker2_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
  158.  
  159.     End Sub
  160.     Private Sub ed1_IOLineFallingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed1.IOLineFallingEdge
  161.  
  162.  
  163.         HasStarted1 = True
  164.         val1(0) = ed1.Inputs(0).Value
  165.  
  166.     End Sub
  167.     Private Sub ed1_IOLineRisingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed1.IOLineRisingEdge
  168.  
  169.  
  170.         HasStarted1 = True
  171.         val1(0) = ed1.Inputs(0).Value
  172.  
  173.     End Sub
  174.     Private Sub ed2_IOLineFallingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed2.IOLineFallingEdge
  175.  
  176.  
  177.         HasStarted2 = True
  178.         val2(0) = ed2.Inputs(0).Value
  179.  
  180.     End Sub
  181.     Private Sub ed2_IOLineRisingEdge(line As IOLine, device As EDDevice, changeType As IOChangeTypes) Handles ed2.IOLineRisingEdge
  182.  
  183.  
  184.         HasStarted2 = True
  185.         val2(0) = ed2.Inputs(0).Value
  186.  
  187.     End Sub
  188.  
  189. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement