LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing data in a package with Labview


@constructionworker wrote:

 

I think the '''\r'', '\n'' used here may be causing a problem because '\n' is used as the termination character of ''VISA Configure serial port'' in the labview.
How can we do this in labview?

 


Of course the \r\n is the problem. You try to send binary data which can contain this bytes anywhere in the data and then use these bytes also as termination character. Big NO-NO! You overload the meaning of those bytes with two entirely different things. The receiver has no reliable way of detecting what is data and where is your end of message without a lot of complex parsing, conditional logic and use of the Bytes at Serial Port only aggravates the problem.

 

In communication you have three types of messages:

 

1) (textual) messages with a special termination character that is guaranteed to not occur in the message itself

2) binary fixed size messages

3) fixed size header containing information about the length and type of the message that immediately follows

 

Anything else is going to cause you and whoever you burden with dealing with that protocol only a lot of grief and cursing.

 

So choose your poison from these 3 types and properly implement it. Don't mix and match various characteristics. Especially the use of binary data together with a termination character is a very bad choice.

 

Rolf Kalbermatter
My Blog
Message 11 of 20
(1,058 Views)

Thanks for your descriptive answer.You made a good observation.


@rolfk wrote:

Of course the \r\n is the problem. You try to send binary data which can contain this bytes anywhere in the data and then use these bytes also as termination character. Big NO-NO! You overload the meaning of those bytes with two entirely different things. The receiver has no reliable way of detecting what is data and where is your end of message without a lot of complex parsing, conditional logic and use of the Bytes at Serial Port only aggravates the problem.

bool sendPktRFD900(uint8_t *data, uint8_t len)
{
  for (int i = 0; i < len; i++)
  {
    radioPort.write(data[i]);
    radioPort.flush();
  }
  radioPort.println();
  radioPort.flush();
  // set flag
  radioFnctn = TXmode;
  TX = true;
  return true;
}

 I couldn't determine what change I could make in the code.

How can I add a fixed-size header that contains information about the length and type of the message immediately following it, and I think I should use it as the serial configure port termination character?

 

 


 

0 Kudos
Message 12 of 20
(1,003 Views)

For instance something like this

 

#define HEADER_MAGIC_1   0x12  
#define HEADER_MAGIC_2   0x34  
#define HEADER_MAGIC_3   0x56

bool sendPktRFD900(uint8_t *data, uint8_t len)
{
    // Send 4 byte header
    radioPort.write(HEADER_MAGIC_1);
    radioPort.write(HEADER_MAGIC_2);
    radioPort.write(HEADER_MAGIC_3);
    radioPort.write(len);
    // Send actual data
    radioPort.write(buf, len);
    // Flush, but that should not really be necessary
    radioPort.flush();
    // set flag
    radioFnctn = TXmode;
    TX = true;
    return true;
}

 

- You don't need to send each byte separately, the Serial port has a function to send an entire byte array.

- You definitely should not flush the port after every byte, in fact flushing should not really be needed, but if you insists you can call it once at the end of the message.

 

In LabVIEW first disable termination character entirely.

 

Read 4 bytes, check that the first three are 0x12, 0x34, 0x56. If so use the 4th as indication how many bytes to read and do so, rinse and repeat.

Rolf Kalbermatter
My Blog
Message 13 of 20
(990 Views)

 
Thank you very much.
As always, you diagnosed the problem directly 🙂 Your exact answer really helped me a lot.
I have added the code below for those who want it and encounter the same problem. The entire code is as follows. In this way, I achieved my goal. But perhaps some more improvements can be made in the code.

0 Kudos
Message 14 of 20
(961 Views)

The full code is as follows.

0 Kudos
Message 15 of 20
(937 Views)

Your architecture scares me.  Using local variables to pass data to other loops is a major red flag.  Learn to use Queues to pass the data from one loop to the next.  A queue will make sure every data sample is processed as well as not use up CPU since it can sleep while waiting for data to come in.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 16 of 20
(908 Views)

@crossrulz wrote:

Your architecture scares me.


I fully agree. In addition, everything is extremely convoluted with way too many sequence structures and Rube Goldberg constructs, complicated data dependencies, way too many local variables, and way too much duplicate code. I think done correctly, the entire code would shrink to 20% and fit on a postcard.

0 Kudos
Message 17 of 20
(890 Views)

@altenbach wrote:

@crossrulz wrote:

Your architecture scares me.


I fully agree. In addition, everything is extremely convoluted with way too many sequence structures and Rube Goldberg constructs, complicated data dependencies, way too many local variables, and way too much duplicate code. I think done correctly, the entire code would shrink to 20% and fit on a postcard.


With the new zoom feature, ALL code can fit on a post card.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 18 of 20
(884 Views)

@billko wrote:

@altenbach wrote:

@crossrulz wrote:

Your architecture scares me.


I fully agree. In addition, everything is extremely convoluted with way too many sequence structures and Rube Goldberg constructs, complicated data dependencies, way too many local variables, and way too much duplicate code. I think done correctly, the entire code would shrink to 20% and fit on a postcard.


With the new zoom feature, ALL code can fit on a post card.  😉


Not quite, there is a limit to how much you can zoom out (25%).  This code will need 2 post cards when fully zoomed out as is.  If cleaned up, I agree with Christian that the whole code could potentially fit in 1/4 the size (locals take a lot of space, case structures layers could be removed, a lot of comparisons would be easily removed by wiring the numeric straight to the case structure, etc.).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 19 of 20
(876 Views)

@crossrulz wrote:

Your architecture scares me.  Using local variables to pass data to other loops is a major red flag.  Learn to use Queues to pass the data from one loop to the next.  A queue will make sure every data sample is processed as well as not use up CPU since it can sleep while waiting for data to come in.


Thanks for your opinion.
Yes, I think your observation was good. Indeed, CPU usage is high when the program is running. For this, it is absolutely necessary to use Queue.

for Rube goldberg  code;You are right that the code takes up a lot of space. Actually, I wanted to fix this, but I couldn't decide how to do it. My brain is tired to edit this right now.Maybe someone willing to help can help 🙂

0 Kudos
Message 20 of 20
(840 Views)