LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP Reader

Hi,

I have to implement an exe that reads UDP packets and check if a bit of the payload is 1. The exe have also to print a record of the packet on a file.

I have developed that exe in the file here uploaded but on windows each loop take around 250ms, while the packets sent to me are in the order every 10ms at maximum (it can be less).

How can I improve my exe? A buffer in reading messages and a buffer for printing records can be helpful?

Thank you for the help.

Best Regards,

Zuc

 

Labview 2019

0 Kudos
Message 1 of 20
(253 Views)
  • There is a problematic race condition because reading the text.text property is not guaranteed to happen only after the indicator has been updated. If it executes before the update, you'll get stale data
  • Reading the text.text property of an indicator in hex display is clumsy. You should operate on the binary string directly.
  • We are missing your subVI.
  • You don't need to wire a time into the format date/time. The current time is the default.
  • You only need to wire the net address if you have multiple active adapters. do you?
  • I would disable "convert EOL" for the file writes.
  • I cannot find any chart in your code..
  • ... (just from a quick glance, there is probably more)

Can you isolate the inner code into a simulation ( no UDP, just generating typical strings for the inner code) so we can test it. Do you have documentation on the string structure?

0 Kudos
Message 2 of 20
(229 Views)

Also, "array to spreadsheet string" adds a linefeed, so using that subVI (which does the same but removes the trailing linefeed) and then adding a linefeed afterwards is just more complicated.

 

altenbach_0-1764783510875.png

 

You can just clear error 56, replacing that case structure in the error case.

 

altenbach_0-1764783904054.png

 

 

0 Kudos
Message 3 of 20
(220 Views)

Hi,

I try to answer point by point:

1. I have removed the Text.text property since it was slowing down the loop (here after the updated version of the VI)

2. The subvi only check in the UDP payload if a bit is 1 or 0, but I link that too.

3. I need that time format that is not the default in case I directly connect the get date time as it is, if there is a smarter way open to improve but I need a timestamp like: 2025/12/04 09:44:50,785

4. The EOL is need since I am printing the txt log file row by row I need to pass to the next line at the next loop.

5. Why a chart? I don’t need to print anything.

6. Why the spreadsheet vi? I need to pass from an array to a comma string to print in txt. Maybe I am missing the point but with your suggest you are doing the exact opposite of what I need. From spreadsheet vi I obtain an array as output.

Zuc_lab2_0-1764839467956.png

My point is: given my Vi SimpleUDPReceiver.vi is it possible to reduce the loop rate under 10ms? Doing everything is doing?

Thank you for the help and the advices.

 

Best regards,

Zuc

Download All
0 Kudos
Message 4 of 20
(167 Views)
  1. The text.text property is a lazy way to format a binary string in a special hex format with spaces between groups of four. Typically operating on the raw string directly is significantly more efficient. Did you understand why you had a race condition?
  2. I'll have a look at the subVI
  3. The time formatting is fine, you simply don't need to wire a time into it. It will assume the current time by default.
  4. Array to spreadsheet string will append a linefeed, no need to use that pink function which first removes it and then add it manually.
  5. The structure label of the "no error" case is "Sender sent data. Update the chart value.". This confused me.
  6. The picture you show is "spreadsheet string to array" and you did not wire the inputs correctly. I was talking about "array to spreadsheet string". Compare the icon.

How fast do the packets arrive and how irregular is the time interval? If the loop code is slowing you down, put the UDP receive in a separate loop and push the raw data into a queue, to be read a leaisure in a parallel process.

0 Kudos
Message 5 of 20
(147 Views)

@altenbach wrote:
I'll have a look at the subVI

How fast do the packets arrive and how irregular is the time interval? If the loop code is slowing you down, put the UDP receive in a separate loop and push the raw data into a queue, to be read a leaisure in a parallel process.


OK, your subVi is pure madness. I have no idea what an "Octec" is, but in your world it seems to be 16 bits.

 

All you need is take the raw string, cast it as U16 array and check the desired bit. Compare:

 

altenbach_0-1764855599661.png

 

Message 6 of 20
(138 Views)

Hi Altenbach,

 

1. with the text.text, you mean this part? In that case it was my only way to get a string expressed as "45AD FF24 49D2" where i have the Octets divided by spaces. 

 

Zuc_lab2_0-1764855241001.png

2. Thank you

3. Done thank you

4-6. Done thank you for the advice and sorry for the misunderstanding

5. No problem it was and old case struct, a copy and past error

 

Tha packets have to arrive every 1ms and I have seen that the while loop follow messages every 4ms. It is also true that the sender run in windows so the delays can be also addressed to that. That's way i'm removing every possibility of delay on my side.

 

Thank you for the help!

 

Best Regards,

Zuc

 

Download All
0 Kudos
Message 7 of 20
(127 Views)

Sorry for the mess I have learned Labview by myself without courses

 

What is this function? 

 

Zuc_lab2_0-1764860222169.png

 

Thank you for the help!

0 Kudos
Message 8 of 20
(114 Views)

@Zuc_lab2 wrote:

Sorry for the mess I have learned Labview by myself without courses

 

What is this function? 

 

Zuc_lab2_0-1764860222169.png

 

Thank you for the help!


Logical Shift Function

See: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/logical-shift.html 

0 Kudos
Message 9 of 20
(103 Views)

Not that my code currently only works correctly if the string length is even. Personally, I would convert the string to byte array.

Can you give your definition of "Octec"? Typically one would talk about octets.

0 Kudos
Message 10 of 20
(99 Views)