please help configuring serial studio for my raw biary file #253
Replies: 2 comments
-
|
Hi! I think this problem can be solved with the following steps. I highly recommend reading the dataflow section in the wiki to make everything easier to understand and follow. Step 1: Configure Serial Studio for “Project Mode” Ensure Serial Studio is set up to parse data using “Project Mode.” You can read about the different operation modes here.
Step 2: Create a New Project and Configure Data Conversion
Step 3: Set Frame Start/End Delimiters
Step 4: Write a Frame Parser Function The frame parser function converts an input string from the serial port into an array for populating Serial Studio dashboard widgets. function parse(frame) {
// Split the hex string into an array of byte values
let bytes = [];
for (let i = 0; i < frame.length; i += 2) {
let byte = parseInt(frame.substring(i, i + 2), 16);
bytes.push(byte);
}
return bytes;
}The code above will simply convert any binary input data into an array with the numerical values for each byte. For your usage case, it might be a bit more complicated since the different data types in your structure will require different number of bytes (e.g. Step 5: Encoding Data on the Microcontroller You can totally skip this step if you already implemented it, just adding how I might do it: void encodeAndSendData(subscale_t *data) {
uint8_t buffer[256];
uint8_t *ptr = buffer;
// Pack fields into the buffer
// Optional: add a frame starting sequence
memcpy(ptr, &data->acid, sizeof(data->acid));
ptr += sizeof(data->acid);
memcpy(ptr, &data->lognum, sizeof(data->lognum));
ptr += sizeof(data->lognum);
memcpy(ptr, &data->rug3isfresh, sizeof(data->rug3isfresh));
ptr += sizeof(data->rug3isfresh);
memcpy(ptr, &data->isauto, sizeof(data->isauto));
ptr += sizeof(data->isauto);
memcpy(ptr, &data->week, sizeof(data->week));
ptr += sizeof(data->week);
memcpy(ptr, &data->timeofweek, sizeof(data->timeofweek));
ptr += sizeof(data->timeofweek);
// Repeat for other fields...
// Optional: add a frame end sequence (e.g. \n).
// Send the buffer through the serial port...
}Step 6: Revised Frame Parser for Serial Studio Here’s an (untested) JavaScript parser function that decodes the packed data sent from the microcontroller. As you might notice, we retain the first part of the initial hexadecimal parsing function to build an array of bytes...the rest of the function focuses on extracting data from the byte array and "reconstructing" the data types in your C-structure. function parse(frame) {
let bytes = [];
for (let i = 0; i < frame.length; i += 2) {
let byte = parseInt(frame.substring(i, i + 2), 16);
bytes.push(byte);
}
let index = 0;
let acid = (bytes[index++] << 8) | bytes[index++];
let lognum = (bytes[index++] << 8) | bytes[index++];
let rug3isfresh = bytes[index++];
let isauto = bytes[index++];
let week = (bytes[index++] << 24) | (bytes[index++] << 16) | (bytes[index++] << 8) | bytes[index++];
let timeofweek = bytesToDouble(bytes, index); index += 8;
let insstatus = (bytes[index++] << 24) | (bytes[index++] << 16) | (bytes[index++] << 8) | bytes[index++];
let hdwstatus = (bytes[index++] << 24) | (bytes[index++] << 16) | (bytes[index++] << 8) | bytes[index++];
// Decode other fields similarly...
return [
acid,
lognum,
rug3isfresh,
isauto,
week,
timeofweek,
insstatus,
hdwstatus,
// Add the rest of the parsed data fields
];
}
function bytesToDouble(bytes, offset) {
let buffer = new ArrayBuffer(8);
let view = new Uint8Array(buffer);
for (let i = 0; i < 8; i++) {
view[i] = bytes[offset + i];
}
return new Float64Array(buffer)[0];
}Note: You can use Also, I highly recommend setting the Console display mode to Hexadecimal. This avoids potential crashes that can occur when Serial Studio tries to display binary data as readable characters in the console widget:
Step 7: Register Groups and Widgets Finally, create groups and widgets that correspond to the data parsed. Ensure that the array indices in your datasets match the indices in the parser function. Please let me know if this helps you! |
Beta Was this translation helpful? Give feedback.
-
|
thank you so much, this is the script i ended up writing: `function parse(frame) { } // ------------------------------------------------------------------------- function parseU8(bytes, offset) { function parseU32LE(bytes, offset) { function parseDoubleLE(bytes, offset) { function parseFloatLE(bytes, offset) { |
Beta Was this translation helpful? Give feedback.




Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I am trying to set up serial studio to process and visualize raw binary data that is transmitted via a radio connected to the usb serial port of my laptop. I am having issues with setting up the project editor/parse function to correctly read the incoming raw binary data and would appreciate any advice i could get on how to do it. attached below is the structure for the raw binary data that is transmitted :
Beta Was this translation helpful? Give feedback.
All reactions