String ASCII move as HEX to string table

Hi all,

I am working on converting my string table values into hex format and then pushing them back into a string table for further data conversion. Here is the raw string received from a wireless sensor via serial communication:

, Once I click the format from ascii to hex, I am able to see the correct data needed for parsing:

Does anyone know how to convert a string table into a hex table or a string hex table? I’ve looked through the available commands but couldn’t find anything that works for this purpose. Any suggestions or guidance would be greatly appreciated!

Searching the forums for ‘hex’ gives some good results you might find helpful.

But in short, I would have a loop that simply spins through your table using the unpack command.

1 Like

How did you get the data in the table that way? It will be easier to work with (and to use the Unpack command) if it was in a single string variable.

Are you sure you need to convert it to ASCII Hex prior to your end result? If you can share a bit more on what you need extracted, I/we can then give more specific advice.

2 Likes

The string table width is set to 1. This allowed me to arrange the data in the desired order. I can receive the data as a string, but converting it from the table seems much easier than parsing it from a single continuous string.

For example, here’s how the data would be parsed:

Raw Data:
7E 00 19 90 00 13 A2 00 41 A2 70 EA FF FE C2 7F 00 05 03 FF 01 00 01 00 0D 7A 0A 56 4F

Payload:
7F 00 05 03 FF 01 00 01 00 0D 7A 0A 56

Field Breakdown:

  • 7F – Header
  • 00 – Node ID
  • 05 – Firmware Version
  • 03, FF – Battery Voltage
  • 01 – Transmission Counter
  • 00, 01 – Sensor Type
  • 00 – Reserved
  • 0D, 7A – Humidity = (0D * 256) + 7A = 3450 (DEC) / 100 = 34.50%
  • 0A, 56 – Temperature = (0A * 256) + 56 = 2646 (DEC) / 100 = 26.46°C
1 Like

Keep the payload binary, don’t convert to a hex string.

Using a single string will be easier - treat it as an array of bytes:

Here is the difference:

//As a string
fHumidity = (sPayload[24] * 256 + sPayload[25]) / 100.0;

//As a string table
fHumidity = (GetNthCharacter(stPayload[24], 0) * 256 + GetNthCharacter(stPayload[25], 0)) / 100.0;
2 Likes

Having issue with the unpackstring : Unpack String

UnpackString(From String, Start Index, Width, To Value, Data Type, Endian Type)

Result = UnpackString(sString_tmp, 1, 4, sString, 9, 0);

I constantly get error for invalid length -3

Here is the raw data i receive :


after I change the data type hex from ascii :

Any other way to convert ascii to hex? as the unpack string shows invalid length even with string variables.

Why are you still using a string table?

I would like to have them in table. I am not able the receive the whole data in one string variable. The message are getting chopped of after 26 character. In table I am able to receive all the data at once. Table is more for better visualization, as this is in development stage.

Edit: Added this function to prevent the communication timeout in a second. Which prevented the data from getting chopped off. SendCommunicationHandleCommand(hCom_NCD, “set.to:10”);

Having the data in string variable itself :

Did you figure out why that is happening?

If the data received is 1024 bytes or less, then you can store in a string variable.

That shows 55 bytes.

Yes, I changed the timeout for communication handle. The data is not too big. The actual size of data is 55 bytes.

Have you tried this logic:

fHumidity = (sNCD_Data[24] * 256 + sNCD_Data[25]) / 100.0;

Will that get what you need?

Initially I tried that it didn’t work and got error “string can’t multiplied” . But now it seems to work fine. Not sure how. Will test out all the data points and get back.

You probably were using a string table instead of a string.

That worked well. Was able to pull all the data points from the sensor.
image

Thanks philip.

2 Likes

You’re welcome. Are these SDI-12 protocol sensors? If so, what are you using for signal conversion?

1 Like

Yes. We have ncd transmitter and wireless receiver. The transmitter is connected to epic through usb serial.

1 Like

We are testing NCD sensors here in our compressed air utility room.



The gateway is Ethernet as you can see, so I hooked them up to groov View via the NCD nodes in Node-RED.

On the fence about recommending them.
The node is a bit funky to work with, but the upside is that it returns a JSON object, so its trivial to work with all the values and get them into a groov View data store.



1 Like