![]() |
Hilfe bei C++ Übersetzung
Delphi-Quellcode:
sendstring="290200";
retlen=sendstring.GetLength(); StringToCommbyte(sendstring,retlen, commsend); fRes=WriteData(m_hCom, commsend,retlen,FALSE); also aus 290200 wird 290200596a7e
Code:
Kann mir bitte das jemand im Groben übersetzen mit dem CRC16 muss ich mich dann halt kümmern
void CComDlg::StringToCommbyte (CString input, DWORD& length, byte* sendbytescom)
{ input.Remove((char)0x20); length=length/2; byte sendbytes[10000] = {0}; DWORD count=0; BOOL firsttrail; if (input.Mid(0,2)=="7E") { firsttrail=true; } for (DWORD count=0; count<length; count++) { sendbytes[count]=(byte)_strtoui64(input.Mid(count*2,2),NULL,16); } DWORD crc=CalcCRC16(sendbytes,length,firsttrail); sendbytes[length]=(byte)(crc%0x100); sendbytes[++length]=(byte)(crc/0x100); DWORD sc=0; for (DWORD s=0;s<length+1;s++) { switch ((byte)sendbytes[s]) { case 0x7E: if (sc!=0) { sendbytescom[sc]=(byte)0x7D; sendbytescom[++sc]=(byte)0x5E; } else sendbytescom[sc]=sendbytes[s]; break; case 0x7D: sendbytescom[sc]=(byte)0x7D; sendbytescom[++sc]=(byte)0x5D; break; default: sendbytescom[sc]=sendbytes[s]; break; } sc++; } length=sc; } der zuntere Teil "Switch" sollte auch kein problem sein [edit=Phoenix]Delphi- in Code-Tags geändert. Das in den geschweiften klammern sieht sonst so nach Kommentar aus ;-) Mfg, Phoenix[/edit] |
Re: Hilfe bei C# Übersetzung
Bist Du sicher, dass Du eine Übersetzung mit C# haben willst? "::" und DWORD und die Adress-Operatoren deuten doch sehr auf C++ hin. Und gib bitte nochmal genau an, was die Quellsprache und was die Zielsprache sein soll; mit Deinen Anmerkungen hast Du mich verwirrt.
Jürgen |
Re: Hilfe bei C++ Übersetzung
Dann wohl C++ nach Delphi
Delphi-Quellcode:
so in etwa hab ichs bis jetzt
Function StringToCommbyte (Input : String ;length : DWORD; sendbytescom : Byte):Boolean; //oder Sendbytecom ist das result (byte)
var firsttrail : Boolean; count : DWord; sc : DWord; s : DWord; CRC : DWord; //DWORD crc sendbytes : Array [0..9999] of Byte; // byte sendbytes[10000] = {0}; Begin sc := 0; //DWORD sc=0; Stringreplace(Input,#20,'',[rfReplaceAll]);//input.Remove((char)0x20); length :=length div 2; //length=length/2; if Copy(Input,0,2) = #126 then //if (input.Mid(0,2)=="7E") begin firsttrail := True; //firsttrail=true; end; for Count := 0 to length do//for (DWORD count=0; count<length; count++) begin //sendbytes[count]=(byte)_strtoui64(input.Mid(count*2,2),NULL,16); end; // CRC := CalcCRC16(sendbytes,length,firsttrail); // sendbytes[length]=(byte)(crc%0x100); // sendbytes[++length]=(byte)(crc/0x100); for s := 0 to length + 1 do // for (DWORD s=0;s<length+1;s++) begin Case sendbytes[s] of // {Case of} switch ((byte)sendbytes[s]) $7e: Begin //case 0x7e: if SC = 0 Then// if (sc!=0) Begin sendbytescom[sc] := $7D; //sendbytescom[sc]=(byte)0x7D; sendbytescom[inc(sc)] := $5e; //sendbytescom[++sc]=(byte)0x5E; end else sendbytescom[sc] := sendbytes[s]; //sendbytescom[sc]=sendbytes[s]; break; end; $7d: Begin //case 0x7D: sendbytescom[sc] := $7D; //sendbytescom[sc]=(byte)0x7D; sendbytescom[inc(sc)] := $5D; // sendbytescom[++sc]=(byte)0x5D; break; end; else sendbytescom[sc] := sendbytes[s]; //sendbytescom[sc]=sendbytes[s]; break; end; Inc(sc); end; length := sc; end; |
Re: Hilfe bei C++ Übersetzung
wie mache ich das in dieser zeile
Delphi-Quellcode:
was stellt firsttrail dar
CRC := CalcCRC16(sendbytes,length,firsttrail);
|
Re: Hilfe bei C++ Übersetzung
Kann jamand mal die Übersetzung zuende machen bzw. kontrollieren
Delphi-Quellcode:
fehlt mir auch immmer noch
CRC := CalcCRC16(sendbytes,length,firsttrail);
CalcCRC16 taucht nicht im sourcecode als funktion auf müsste also generell bei c++ dabei sein |
Re: Hilfe bei C++ Übersetzung
Das ist definitiv keine C++ Funktion und die muss in den Quellen mit bei sein. CRC16 Algorithmen gibt es viele, die Frage ist eher, von welchen Start-Seed gehen die aus?
|
Re: Hilfe bei C++ Übersetzung
Gehstock: StringReplace ist eine Funktion, keine Prozedur. :zwinker:
|
Re: Hilfe bei C++ Übersetzung
Zitat:
den CRC Algo hab ich gefunden
Delphi-Quellcode:
kann mir das jemand übersetzen
WORD crc_16_l_step(WORD crc, byte data)
{ return crc16_table[(crc ^ data) & 0xff] ^ ((crc >> 8) & 0xFF); } DWORD CComDlg::CalcCRC16(byte* buf_ptr, DWORD len, BOOL value) { WORD eax = CRC_16_SEED; DWORD i=0; if (value==true) i=1; for (i = i; i < len; i++) eax = crc_16_l_step(eax, buf_ptr[i]); eax = eax ^ CRC_16_SEED; return eax; } |
Re: Hilfe bei C++ Übersetzung
Was macht die eckige klammer "[" in c++ ist das auch ein Array
ist diese Übersetzung soweit richtig?
Delphi-Quellcode:
Function crc_16_l_step(crc : word;data : Byte): Word;
Begin Result := crc16_table[(crc xor data) and $ff] xor ((crc shr 8) and $FF); end; Function CalcCRC16(buf_ptr : Array of byte;len : DWORD;value : BOOL): DWORD; var eax : Word; i : DWord; begin eax := $FFFF; i := 0; if (value = true) then i :=1; for i := i to len do eax := crc_16_l_step(eax, buf_ptr[i]); eax := eax xor $FFFF; Result := eax; end; und was sind das für Typen byte* , DWORD& , ^byte und dafür brauch ich Hilfe
Delphi-Quellcode:
sendbytes[count]=(byte)_strtoui64(input.Mid(count*2,2),NULL,16);
|
Re: Hilfe bei C++ Übersetzung
Kann keiner helfen
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz