Expand|Select|Wrap|Line Numbers
- Public Class GlobalMembers
- Public com1 As MSCOMM
- ' Global Union Variables:
- Public Shared crc_value As word_byte ' system crc value
- Public Shared adc_value As word_byte ' adc value read from table
- Public Shared location_value As word_byte ' address of table to send ADC value
- Public Shared pmsg As Byte() = New Byte(24) {} ' crc buffer
- Public Shared tsize As UInteger
- ' Global Structure Definitions
- Public Class byte_low_hi
- Public low_byte As Byte
- Public high_byte As Byte
- End Class
- ' Global Union Definitions
- 'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
- 'ORIGINAL LINE: union word_byte
- Public Structure word_byte
- Public word16 As UInteger
- Public byte8 As byte_low_hi
- End Structure
- 'Code Constants
- #Const BMS = True ' this represents the binary message start byte, value 0x2A
- #Const PASSWD = True ' this represents the factory pass code, value 11548d
- #Const POLY = True ' the polynomial used in the CRC algorithm
- Friend NotInheritable Class DefineConstants
- Public Const BMS As Char = "*"c
- Public Const PASSWD As Integer = &H2D1C
- Public Const POLY As Integer = &H8005
- End Class
- Public Sub table_upload_req()
- Dim Len As Byte = &H8
- Dim Cmd As Byte = &H9
- adc_value.word16 = &H0 ' read ADC value and put into storage var
- location_value.word16 = &H0
- crc_value.word16 = 0
- Dim msg_size As Byte = Len - 2
- pmsg(0) = AscW(Len)
- pmsg(1) = AscW(Cmd)
- Dim i As Integer = 0
- Do While i < tsize
- ' single table upload request packet
- location_value.word16 += 1
- adc_value.word16 = ADC_AVE(i)
- pmsg(2) = CChar(adc_value.word16.high_byte)
- pmsg(3) = CChar(adc_value.word16.low_byte)
- pmsg(4) = CChar(location_value.word16.high_byte)
- pmsg(5) = CChar(location_value.word16.low_byte)
- crc_value.word16 = Make_Bitwise_CRC16(UInteger, msg_size)
- com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3) + pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) + CChar(crc_value.word16.low_byte)
- tsize += 1
- Loop
- End Sub
- Public Function Make_Bitwise_CRC16(ByVal msg_size As UInteger) As Integer
- Dim i As UInteger
- Dim j As UInteger
- Dim msg As UInteger
- For i = 0 To msg_size - 1
- msg = (pmsg(i) << 8)
- For j = 0 To 7
- If ((msg Xor crc_value.word16) >> 15) > 0 Then
- crc_value.word16 = (crc_value.word16 << 1) Xor DefineConstants.POLY
- Else
- crc_value.word16 <<= 1
- End If
- msg <<= 1
- Next j
- Next i
- Return (crc_value.word16 Xor 0)
- End Function
- End Class