β06-23-2021 11:38 AM
I already saw some topics about this matter but this I could not convert the characters that I have to a hex number.
I have the following code, which has in the beginning an EEprom variable that has a string of 96 bits, and which and the gets split into 3 different Values of 32 Bit and then each one of these 32 bit values contains four characters.
I want to put these 4 characters
(shown in this Fmc funktion: Fmt(Result_Block0,"%s<%s%s%s%s",c_Char1,c_Char2,c_Char3,c_Char4); into a string that contains each hexvalue of these chars. But I could not find a way to do that.
I guess it might be not hard, I am just a beginner and still learning basic stuff everyday π
I will be very thankful is someone can help me find a solution!
Thanks a lot in advance.
//Ausgabe in BinΓ€r
char EEPROM[100] ={0};
Fmt(EEPROM,"%s<%s%s%s%s%s%s%s",b_sgtin_Header,b_Filter_ergebnis,b_Partition_ergebnis,b_Company_Prefix_ergebnis,vorangestellte_0,b_Item_Reference_ergebnis,b_Serial_Result);
SetCtrlAttribute(sPanels.P_Hauptmenue, P_MAIN_EEPROM, ATTR_CTRL_VAL, EEPROM);
char Byte_Block [10]= {0};
char B0 [40] = {0};
char B1 [40] = {0};
char B2 [40] = {0};
char c_Char1 [2] = {0};
char c_Char2 [2] = {0};
char c_Char3 [2] = {0};
char c_Char4 [2] = {0};
char Result_Block0 [5] = {0};
char Result_Block1 [5] = {0};
char Result_Block2 [5] = {0};
char cRead_Block_0 [10] = {0};
char cRead_Block_1 [10] = {0};
char cRead_Block_2 [10] = {0};
//Unterteilung der 96 Bits vom Data Matrix Inhalt in 3 Teilen. (Je 32 Bits)
CopyBytes(B0, 0,EEPROM,0,32);
CopyBytes(B1, 0,EEPROM,33,32);
CopyBytes(B2, 0,EEPROM,64,32);
//Unterteilung jede der 32 Bits in 4 * 8 Bits bzw. 4 Bytes und Umwandlung in ein ASCII Character
//GTIN erste 32 Bits in Block 0
Daten_EEPROM_Byte_VERTEILER(B0);
DATEN_alle_Char_uerbergabe_Funktion (Byte_Block,c_Char1, c_Char2, c_Char3, c_Char4);
Fmt(Result_Block0,"%s<%s%s%s%s",c_Char1,c_Char2,c_Char3,c_Char4);
Fmt(cCommand,"%s<%s%s%s%s",WRITE_BLOCK,"0_",Result_Block0,ENDE);
//unsigned char str[100],strH[200];
int i,j;
unsigned char x_ResultBlock0[10];
memset(x_ResultBlock0,0,sizeof(x_ResultBlock0));
/*converting str character into Hex and adding into strH*/
for(i=0,j=0;i<strlen(Result_Block0);i++,j+=2)
{
sprintf((char*)x_ResultBlock0+j,"%02X",x_ResultBlock0[i]);
}
x_ResultBlock0[j]='\0'; /*adding NULL in the end*/
SetCtrlAttribute(sPanels.P_Hauptmenue, P_MAIN_DM_SCAN_2, ATTR_CTRL_VAL, ("%x\n",x_ResultBlock0));
// Write and Read Data in and from Block 0
iResult = Befehl_Senden(cCommand,cAnswer);
Fmt(cCommand,"%s<%s%s%s",READ_BLOCK,"0",ENDE);
iResult = Befehl_Senden(cCommand,cAnswer);
CopyBytes(cRead_Block_0,0,cAnswer,23,8);
SetCtrlAttribute(sPanels.P_Hauptmenue, P_MAIN_DM_SCAN_7, ATTR_CTRL_VAL, cRead_Block_0);
β06-24-2021 04:05 AM - edited β06-24-2021 04:14 AM
Hi, there is a bit of confusion in your post between bits and bytes!
You always speak of bits, but you are using bytes-oriented functions so it's difficult to understand the situation; just as an example, in the line
CopyBytes (B0, 0, EEPROM, 0, 32);
you say you want to split 96 a 96-bits block in chunks or 32 bits, but you are copying 32 bytes=256 bits!
You should either rethink your code or explain better the situation, possibly adding an example of what EEPROM may contain and what you are aiming to obtain.