﻿Option Explicit On

Imports System.IO.Ports    'THIS ONE is a reworking trial for SURE board    Version 1a

Public Class Form1
    Dim LiveComPort As New SerialPort
    Dim a As Integer
    Dim v As Integer

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Dim LiveComPort As New IO.Ports.SerialPort
        LiveComPort.PortName = "COM1"       'This is the serial port I am using
        LiveComPort.BaudRate = 9600
        LiveComPort.DataBits = 8
        LiveComPort.Parity = IO.Ports.Parity.None
        LiveComPort.StopBits = IO.Ports.StopBits.One
        LiveComPort.Open()

        Button2.Visible = False

    End Sub
    Sub SendData()

        'send twice

        LiveComPort.Write(Asc("$sure mseg a v Chr(13)"))
        Threading.Thread.Sleep(50)
        LiveComPort.Write(Asc("$sure mseg a v Chr(13)"))

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        v = 8
        For Me.a = 1 To 4
            Call SendData()
        Next a
       
    End Sub

    Sub TurnOff()
        Dim pkg(2) As Byte

        pkg(0) = Asc("$sure ")
        pkg(1) = Asc("off")
        pkg(2) = Asc(Chr(13))

        Dim n As Integer
        For n = 1 To 2              'Send twice
            LiveComPort.Write(pkg, 0, pkg.Length)
            Threading.Thread.Sleep(50)
        Next n

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Call TurnOff()
    End Sub
End Class
