Hallo Leute, Habe ein Problem mit einer Übersetzung von C# nach VB.Net. Den ganzen Code habe ich mit einem Online Translator übersetzt. Nur bei einem Teil gibt es ein Problem. Originaler Code:
1 | private void GetCRC(byte[] message, ref byte[] CRC) |
2 | {
|
3 | //Function expects a modbus message of any length as well as a 2 byte CRC array in which to
|
4 | //return the CRC values:
|
5 | |
6 | ushort CRCFull = 0xFFFF; |
7 | byte CRCHigh = 0xFF, CRCLow = 0xFF; |
8 | char CRCLSB; |
9 | |
10 | for (int i = 0; i < (message.Length) - 2; i++) |
11 | {
|
12 | CRCFull = (ushort)(CRCFull ^ message[i]); |
13 | |
14 | for (int j = 0; j < 8; j++) |
15 | {
|
16 | CRCLSB = (char)(CRCFull & 0x0001); |
17 | CRCFull = (ushort)((CRCFull >> 1) & 0x7FFF); |
18 | |
19 | if (CRCLSB == 1) |
20 | CRCFull = (ushort)(CRCFull ^ 0xA001); |
21 | }
|
22 | }
|
23 | CRC[1] = CRCHigh = (byte)((CRCFull >> 8) & 0xFF); |
24 | CRC[0] = CRCLow = (byte)(CRCFull & 0xFF); |
25 | }
|
VB Code:
1 | |
2 | Private Sub GetCRC(ByVal message As Byte(), ByRef CRC As Byte()) |
3 | 'Function expects a modbus message of any length as well as a 2 byte CRC array in which to |
4 | 'return the CRC values: |
5 | |
6 | Dim CRCFull As UShort = &HFFFF |
7 | Dim CRCHigh As Byte = &HFF, CRCLow As Byte = &HFF |
8 | Dim CRCLSB As Char |
9 | |
10 | For i As Integer = 0 To (message.Length) - 3 |
11 | CRCFull = CUShort(CRCFull Xor message(i)) |
12 | |
13 | For j As Integer = 0 To 7 |
14 | CRCLSB = ChrW(CRCFull And &H1) |
15 | CRCFull = CUShort((CRCFull >> 1) And &H7FFF) |
16 | |
17 | If CRCLSB = 1 Then |
18 | CRCFull = CUShort(CRCFull Xor &HA001) |
19 | End If |
20 | Next
|
21 | Next
|
22 | CRC(1) = InlineAssignHelper(CRCHigh, CByte((CRCFull >> 8) And &HFF)) |
23 | CRC(0) = InlineAssignHelper(CRCLow, CByte(CRCFull And &HFF)) |
24 | End Sub |
Das Problem liegt bei:
1 | |
2 | If CRCLSB = 1 Then |
3 | CRCFull = CUShort(CRCFull Xor &HA001) |
4 | End If |
Der Compiler sagt: Fehler 1 Der =-Operator ist für die Typen "Char" und "Integer" nicht definiert. Kann mir da wer weiter helfen ??