Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.Text
- Imports System.Threading
- Imports System.Net.NetworkInformation
- Public Class runTestFrma
- 'Counter used to compare step's run time against its wait time
- Dim StepTimerCounter As Integer = 0
- 'current step variables
- Dim StepCommand As String = ""
- Dim StepPrompt As String = ""
- Dim StepArg1 As String = ""
- Dim StepArg2 As String = ""
- Dim StepArg3 As String = ""
- Dim StepArg4 As String = ""
- Dim StepWait As String = ""
- Dim StepOnPass As String = ""
- Dim StepOnFail As String = ""
- Dim currentstep As Integer = 0
- 'Each procedure hands off to another procedure, this variable tracks which we're currently on.
- Dim currentprocedure As String = ""
- Dim threadcontinue As Boolean = False
- Dim port As Int32 = 1111
- Dim client As New TcpClient("192.168.1.127", port)
- Dim stream As NetworkStream = client.GetStream()
- Private Sub RunTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- partIdTxt.Focus()
- partIdTxt.SelectAll()
- If stream.CanRead Then
- GetData.Start()
- Else
- MsgBox("ERROR 1")
- End If
- End Sub
- Private Sub RunTest_Close() Handles MyBase.FormClosed
- mainMenuFrm.Show()
- End Sub
- Private Sub GetData_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetData.Tick
- Connect("192.168.1.127")
- End Sub
- Private Sub Connect(ByVal server As [String])
- Try
- ' Translate the passed message into ASCII and store it as a Byte array.
- Dim data(1) As Byte
- data(0) = 0
- data(1) = 1
- ' Get a client stream for reading and writing.
- ' Stream stream = client.GetStream();
- ' Send the message to the connected TcpServer.
- stream.Write(data, 0, data.Length)
- ' Receive the TcpServer.response.
- ' Buffer to store the response bytes.
- data = New [Byte](115) {}
- ' String to store the response ASCII representation.
- Dim responseData As [String] = [String].Empty
- ' Read the first batch of the TcpServer response bytes.
- Dim bytes As Int32 = stream.Read(data, 0, data.Length)
- 'PARSE DATA HERE
- calLbl.Text = CDec(data(1)).ToString
- doboardvoltages(data)
- Dim bytesa(1) As Byte
- 'Ref 02 Voltage
- bytesa(0) = data(66)
- bytesa(1) = data(67)
- ref02Lbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- '3.3 Voltage
- bytesa(0) = data(68)
- bytesa(1) = data(69)
- v33Lbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- '5 Voltage
- bytesa(0) = data(70)
- bytesa(1) = data(71)
- v5Lbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- '12v Voltage
- bytesa(0) = data(72)
- bytesa(1) = data(73)
- v12Lbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- 'VEH Voltage
- bytesa(0) = data(74)
- bytesa(1) = data(75)
- vehPwrOutLbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- 'Ground Voltage
- bytesa(0) = data(80)
- bytesa(1) = data(81)
- groundLbl.Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- Catch e As ArgumentNullException
- MsgBox("ArgumentNullException: {0}" & e.ToString())
- Catch e As SocketException
- MsgBox("SocketException: {0}" & e.ToString())
- End Try
- End Sub 'Connect
- Private Sub doboardvoltages(ByVal bytes() As Byte)
- For i As Integer = 1 To 32
- Dim bytesa(1) As Byte
- bytesa(0) = bytes(i * 2)
- bytesa(1) = bytes(i * 2 + 1)
- CType(Panel2.Controls("channelactive" & i), Label).Text = GetVoltageFromBytes(bytesa).ToString("0.00")
- If CDec(CType(Panel2.Controls("channelmin" & i), Label).Text) > CDec(CType(Panel2.Controls("channelactive" & i), Label).Text) Then
- CType(Panel2.Controls("channelmin" & i), Label).Text = CType(Panel2.Controls("channelactive" & i), Label).Text
- End If
- If CDec(CType(Panel2.Controls("channelmax" & i), Label).Text) < CDec(CType(Panel2.Controls("channelactive" & i), Label).Text) Then
- CType(Panel2.Controls("channelmax" & i), Label).Text = CType(Panel2.Controls("channelactive" & i), Label).Text
- End If
- Dim setvalue As String = ""
- Select Case bytes(81 + i).ToString()
- Case "0"
- setvalue = "No"
- Case "1"
- setvalue = "G"
- Case "2"
- setvalue = "N"
- Case "6"
- setvalue = "F"
- Case "7"
- setvalue = "P"
- Case "11"
- setvalue = "H"
- End Select
- CType(Panel2.Controls("channelbias" & i), Label).Text = setvalue
- Next
- End Sub
- Private Function GetVoltageFromBytes(ByVal bytes() As Byte) As Double
- Dim voltage As Double = 0.0
- voltage = (((bytes(0) * 256.0) + bytes(1)))
- voltage -= 32768 ' 0x8000 = 32768
- voltage = (voltage * 2.0) * (20.0 / 65535.0)
- Return voltage
- End Function
- 'Loads required procedure by argument into datagrid
- 'THIS FUNCTION APPEARS TO BE WORKING FINE
- Private Sub loadcsvtodatagrid(ByVal filename As String)
- 'we have to stop the timer just so it cannot tick while we're trying to load the file!
- StepTimer.Stop()
- 'Load in CSV File
- StepGrid.Rows.Clear()
- If System.IO.File.Exists("c:\csv\" & filename & ".csv") Then
- Try
- For Each line As String In System.IO.File.ReadAllLines("c:\csv\" & filename & ".csv")
- StepGrid.Rows.Add(line.Split(","))
- Next
- Catch ex As Exception
- MessageBox.Show("Error occured while reading " & filename & " file." & vbNewLine + ex.ToString())
- End Try
- populatearray()
- StepTimer.Start()
- Else
- 'At this point, the program effectively locks down until you close and restart.
- MsgBox("File " & filename & " not found! Close This software and ensure the file is added to your c:\csv\ folder.")
- End If
- End Sub
- 'Loads data from datagrid row into
- 'THIS FUNCTION APPEARS TO BE WORKING FINE
- Private Sub populatearray()
- 'Ensures whole line is selected to populate
- Dim selectRow As DataGridViewRow = StepGrid.CurrentRow
- ' Move the Glyph arrow to the first cell
- StepGrid.CurrentCell = selectRow.Cells(0)
- ' Select the row
- selectRow.Selected = True
- 'populate an csv string with selected row contents
- Dim firstvalue As Boolean = True
- Dim tempstring As String = ""
- For Each cell In StepGrid.SelectedCells
- If Not firstvalue Then
- tempstring &= ","
- End If
- Try
- tempstring &= cell.Value.ToString()
- Catch ex As Exception
- tempstring &= ""
- End Try
- firstvalue = False
- Next
- 'Split string based on commas
- Dim words As String() = tempstring.Split(New Char() {","c})
- 'load row values into current step variables
- StepCommand = words(0)
- StepPrompt = words(1)
- StepArg1 = words(2)
- StepArg2 = words(3)
- StepArg3 = words(4)
- StepArg4 = words(5)
- StepWait = words(6)
- If StepWait = "" Then
- StepWait = "1000"
- End If
- StepOnPass = words(7)
- StepOnFail = words(8)
- 'populatesteplabels()
- End Sub
- 'This function allows for key presses to trigger special events.
- 'THIS FUNCTION WORKS, BUT IS SUBJECT TO ADDITIONAL KEY PRESS HANDLERS
- Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
- Select Case keyData
- Case Keys.F12
- Case Keys.F11
- Case Keys.F2
- 'F10 Will show / hide Datagrid / test block tools
- If datagridPanel.Visible Then
- datagridPanel.Visible = False
- Else
- datagridPanel.Visible = True
- End If
- Case Keys.F1
- 'F10 Will show / hide Datagrid / test block tools
- If Panel2.Visible Then
- Panel2.Visible = False
- Panel3.Visible = False
- Else
- Panel2.Visible = True
- Panel3.Visible = True
- End If
- Case Else
- Return MyBase.ProcessCmdKey(msg, keyData)
- End Select
- Return True
- End Function
- Private Sub ComboBox1_SelectedIndexChanged() Handles ComboBox1.SelectedIndexChanged
- For i As Integer = 1 To 32
- CType(Panel2.Controls("channelbias" & i), Label).BackColor = Color.Transparent
- Next
- If ComboBox1.Text = "All" Then
- 'populate with selected byte value for all
- For i As Integer = 1 To 32
- CType(Panel2.Controls("channelbias" & i), Label).BackColor = Color.Yellow
- Next
- Else
- CType(Panel2.Controls("channelbias" & ComboBox1.Text), Label).BackColor = Color.Yellow
- End If
- End Sub
- Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
- Dim data(34) As Byte
- data(0) = 1
- data(1) = 1
- 'populate with current values
- For i As Integer = 0 To 31
- data(2 + i) = getbiasfromletter(CType(Panel2.Controls("channelbias" & i + 1), Label).Text)
- Next
- 'get byte value of bias selection
- Dim setvalue As Byte
- Select Case ComboBox2.Text
- Case "No"
- setvalue = CByte(0)
- Case "G"
- setvalue = CByte(1)
- Case "N"
- setvalue = CByte(2)
- Case "F"
- setvalue = CByte(6)
- Case "P"
- setvalue = CByte(7)
- Case "H"
- setvalue = CByte(11)
- End Select
- If ComboBox1.Text = "All" Then
- 'populate with selected byte value for all
- For i As Integer = 0 To 31
- data(2 + i) = setvalue
- Next
- Else
- data(1 + CInt(ComboBox1.Text)) = setvalue
- End If
- stream.Write(data, 0, data.Length)
- 'resetminmax()
- End Sub
- Private Function getbiasfromletter(ByVal txt As String) As Byte
- Dim setvalue As Byte
- Select Case txt
- Case "No"
- setvalue = CByte(0)
- Case "G"
- setvalue = CByte(1)
- Case "N"
- setvalue = CByte(2)
- Case "F"
- setvalue = CByte(6)
- Case "P"
- setvalue = CByte(7)
- Case "H"
- setvalue = CByte(11)
- End Select
- Return setvalue
- End Function
- End Class
Add Comment
Please, Sign In to add comment