Hello, I have to calculate the CRC16 of a MODBUS string. Unfortunately I have no idea how can I do that. I have found a code for Visual Basic, how I can convert it for Basic4Android?
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
And, there is an another solution for the calculation of the CRC16 modbus?
Thanks a lot!!!
			
			
			
				B4X:
			
		
		
		Public Function CRC(buf() As Byte, lbuf As Integer) As Integer
'-------------------------------------------------
' returns the MODBUS CRC of the lbuf first bytes of "buf" buffer (buf is a global array of bytes)
Dim CRC1 As Integer
CRC1 = &HFFFF ' init CRC
For i = 0 To lbuf - 1 Step 1 ' for each byte
CRC1 = CRC1 Xor buf(i)
For j = 0 To 7 Step 1 ' for each bit
k = CRC1 And 1 ' memo bit 0 state
CRC1 = ((CRC1 And &HFFFE) / 2) And H7FFF ' Shift right with 0 at left
If k > 0 Then CRC1 = CRC1 Xor &HA001 ' Bocuse
Next j
Next i
CRC = CRC1
End Function
	And, there is an another solution for the calculation of the CRC16 modbus?
Thanks a lot!!!