1656 & 1657 Battery Element Tester Owner’s Manual
STS Instruments Page 73 of 88
8.9.2 Calculating Checksum Visual Basic NET Example
The following two code samples illustrates how to communicate with the Battery Element
Tester using the RS485 protocol.
CalcCheckSum Call
Private Sub btnCalcCheckSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button16.Click
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim checksum1, checksum, i As Integer
Try
txtLengthCmd.Text = txtActualCmd.TextLength
str1 = ChrW(txtRS485Addr.Text) & ChrW(txtComm01.Text) &
ChrW(txtLengthCmd.Text)
str2 = txtActualCmd.Text
str3 = str1 & str2
checksum = 0
checksum1 = 0
For i = 0 To str3.Length - 1
checksum += AscW(str3.Substring(i, 1))
Next
checksum1 = checksum And &HFF
checksum = (&H100 - checksum1) And &HFF
str3 = ChrW(checksum)
txtCheckSum.Text = str3
Catch exp As Exception
MessageBox.Show("Please verify entries are properly entered", "Calulating Checksum",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub