1656 & 1657 Battery Element Tester Owner’s Manual
STS Instruments Page 74 of 88
WriteQuery Routine
Private Sub btnWriteQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnWriteQuery.Click
Dim transfer_data(100) As Byte
Dim str1 As String
Dim str2 As String
Try
If txtCheckSum.Text = "" Then
MessageBox.Show("Please select 'Calculating Checksum' button to calculate checksum", "Missing
Checksum Code", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf btnConnect1656.Enabled = True Then
MessageBox.Show("Please establish connection to STS1656", "Connection Error",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
str1 = ChrW(txtRS485Addr.Text) & ChrW(txtComm01.Text) & ChrW(txtLengthCmd.Text) &
txtActualCmd.Text & txtCheckSum.Text
For i = 0 To str1.Length - 1
transfer_data(i) = AscW(str1.Substring(i, 1))
Next
SerialPort1.Write(transfer_data, 0, str1.Length)
If str1.IndexOf("?") > 0 Then
str2 = SerialPort1.ReadLine
RichTextBox1.Text += str2 & vbCrLf
End If
End If
Catch exp As Exception
MessageBox.Show("Please verify command syntax is entered correctly", "Syntax Error",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub