Serial read string HEX ,find byte buffer to HEX to DEC as a float02

hello friend i have used this code for extraction Hex
void loop() {
if (SSerial.available()){

Serial.write(SSerial.read());
int inByte = SSerial.read();
// Serial.print(inByte, HEX);

07 07 4E 4D 4B 48 47 45 43 42 40 3F 3E 3B 3B 3A 38 37 35 36 33 32 31 30 2F 2D 2C 2C 2A 29 28 28 26 25 25 25 24 22 22 22 21 21 1F 20 1F 1E 1F 1F 1E 1E 1E 1F 1E 1E 1E 1E 1E 1E 1E 1F 1E 1D 1E 1E 1E 1E 1F 20 20 21 23 24 25 26 27 29 2A 2A 2C 2D 2E 2F 30 32 32 33 34 36 37 38 39 3C 3C 3D 3F 41 42 43 45 47 48 49 4C 4E 4F 50 53 56 57 58 5A 5D 5D 5F 61 63 64 64 67 68 69 6A 6B 6E 6E 6E 71 72 72 73 75 76 77 78 79 7A 7A 7A 7C 7D 7D 7D 7F 7F 7F 80 81 82 81 81 82 82 82 81 82 83 82 82 82 82 82 82 82 83 82 82 82 82 81 81 81 80 7E 7D 7D 7B 79 78 78 77 74 73 73 72 71 6F 6F 6E 6C 6B 6A 68 67 65 65 63 61 60 5F 5D 5B 5A 59 57 55 54 52 50 4E 4C 4B 49 47 45 44 42 40 3E 3E 3C 3A 39 39 37 35 35 34 32 30 30 2F 2D 2C 2B 2B 29 28 28 27 25 25 24 24 23 22 22 21 20 1F 20 20 1E 1E 1F 1E 1E 1E 1F 1E 1D 1E 1E 1E 1E 1D 1E 1E 1D 1E 1E 1E 1E 1E 20 21 21 22 24 25 95 30 30 30 30 02 14 07 05 02 02 02 04 01 9C 00 00 30 30 06 E8 34 32 39 34 39 36 37 32 39 35 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08

String need capturing
3030 3030 0214 07 05 02 02 02 04 019C 00 00 3030

Divided in this sequence
Table

Value 3030 is displayed voltage 12336V
Value 3030 is displayed wattage output 12336W
Value 0214 is displayed voltage panel 66.5V DC
Vaule 07 // code for display allarm 07 not have allarm
Value 05 nd
Value 02 nd
Value 02 nd
Value 02 nd
Value 04 nd
Value 019C is temperature displayed 35celsius
Value 0000 nd
Value 3030 1233W home power load

i need suggestion for manipulate this data
i have test cycle in this post :frowning:
thanks

For hints on how to make a successful post, please read and follow the instructions in the "How to get the best out of the forum" post, linked at the head of every forum category.

Please post a complete sketch, using code tags when you do

'


String inputString = "";
boolean stringComplete = false;  // whether the string is complete
int buffer[350];               //        350 
int count = 0;
int temp3;


//SoftwareSerial SSerial(2,3);
void setup() {
  Serial.begin(9600);
  while(!Serial){}
  Serial.println("IN attesa Cavi non collegati...");
  SSerial.begin(9600);
}


void loop() {
  if (SSerial.available()){
       Serial.write(SSerial.read());

//  int inByte = SSerial.read();
// Serial.print(inByte, HEX);     // A This line my port com monitoring flush data HEX

 if (stringComplete) {            //not sure if this part work i have disabled//Serial.print(inByte, HEX); but serial.print a this time print ascii
    Serial.println(inputString); 
    inputString = "95";         // clear the string:  THIS IS START STRING same value every cycle  ??
    stringComplete = false;     //Reset the flag
    count = 0;    //Reset the array counter


}
} 

//  while (SSerial.available()) {
    // get the new byte:
    byte inChar = SSerial.read();
    // add it to the inputString:
    inputString += inChar;
    buffer[count] = inChar;// this buffer start in hex reading?this is ascii
    count++;
    // if the incoming character is a $, set a flag so the main loop can do something about it:
  //  if (inChar == '      // CODE IS NOT COMPLETE
if(inChar == '$') { stringComplete = true; }                     //this for complete ?   A this this next part programm running and print data to serial com.data is more variable not stable not sure request my buffer
  

 Serial.print("Watt USED: ");
  //watt used code convert 30 30 from hex to decimal and then display 1233W
  temp3 += buffer[2];
  temp3 += buffer[3];
  Serial.println(temp3);  //so you can see the captured string
'

like post number 1

Did you miss the request to use code tags when posting code ?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

I apologize I don't understand how to insert the tags I have inserted quotation mark '' does not work
this is ok ?

You should post code by using code-tags. There are two simple ways to do this.

First way is to click on the code tags icon at the top of the posting window
ArduinoForum

Another wasy is to use an automatic function for doing this in the Arduino-IDE.

Three steps

1)press Ctrl-T for autoformatting your code
2)do a rightclick with the mouse and choose "copy for forum"
3)paste clipboard into write-window of a posting

is ok ?

Yes, Post #4 looks corrected.

Code does not appear to be complete.

Looks like you are testing for SSerial.available(), then reading multiple characters from the serial buffer, without knowing how many are actually available.

@cento, does this help?
Output:

 Hex:  0x31 0x32 0x33 0x33 0x36
 Dec:   49  50  51  51  54
 float: 12.336

Code:


char buf [80];
char s [80];
char fStr [10];

void
process (
    char *buf )
{
    unsigned len = strlen (buf);

    Serial.print (" Hex: ");
    for (unsigned n = 0; n < len; n++)  {
        sprintf (s, " 0x%02x", buf[n]);
        Serial.print (s);
    }
    Serial.println ();
    
    Serial.print (" Dec: ");
    for (unsigned n = 0; n < len; n++)  {
        sprintf (s, " %3d", buf[n]);
        Serial.print (s);
    }
    Serial.println ();
    
    int   x = atoi (buf);
    float f = x / 1000.0;
    dtostrf (f, 6, 3, fStr);

    Serial.print (" float: ");
    Serial.println (fStr);
}

void
loop (void)
{
    if (Serial.available ())  {
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';         // terminal w/ NULL

        process (buf);
    }
}

void
setup (void)
{
    Serial.begin (9600);
}

Thank you for code conversion.

My code a this time display value.
But i not hare sure if my code flow is correct
Vaule is not same to display..
Working progress...

what are you trying to do?

this output suggests reading voltages and power (Watts).
do you need a way to identify that the input is a Voltage or Power? separate the sub-fields, and translate the ASCII values into decimal values?

With this code i send only one byte
This code reply

If send more byte around 10.my code reply with more result

This code not capture one complete string
This code capture one buffer and send result.

If have data in in ascci
With this line
// Serial.print(inByte, HEX);
i have printed hex value. But have printed total string.

In the string i need find the value 95
For start cycle buffering
And capture the next hex.

In the old post have the position hex interessed.

so this code it trying to send 1 byte?

I need send to you one video for understand this?

In the video i send the dump for display
And inverter reply.

I need manipulation data recevied by inverter.
Thank s
The comunication possible is master slave.
The display send the code
And the inverter reply to display.

Thank s

please use google translate to provide a clearer explanation of what you want to do?

what is the format to the data being dumped?

it looks like some of it is sinusoidal

1 Like

This is format data dumped is in hex.
In this string up the post..
I need find value 95 and capture this next string
30 30 30 30 02 14 07 05 02 02 02 04 01 9C 00 00 30 30

Ok? Thank s

all data is binary (hex) but what does it represent

example:

Yeah i have edit post 16