LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Network stream stuck at last image and writer timed out

Hello, 

Im building a simple vi  to stream an image from webcam connected to MyRio RT to host pc . Im trying to see what is the max frequency by lowering the wait time and see what stream can handle and  utilization of the myrio unit. But after a minute stream freezes and video is stuck at last image that was taken. I dont get any error and then Writer endpoint indicates that it timed out from indicator. Sometimes instead of this I get message that rio disconected. 

Jenda02_0-1627502228684.png

I cant run those vis again because it shows that last image and only thing that helps is  to restart MyRio and close aplication. I usually get to around 100 ms from 1000 ms. 

Did I do something wrong when I was creating those streams, or are they badly configured? What may cause this? 

These are the VIs. Writer is on MyRio RT and reader on my host pc.   

Jenda02_1-1627501626444.png

 

Thank you, 

J.

 

 

0 Kudos
Message 1 of 29
(1,697 Views)

Hi Jenda,

 

Just being a lizard on the wall (post) want to see what it turns out to be, since I am supposed to implement network stream in one of my application so curious.

 

Until someone gives you a proper response, you could try following steps, it may help😀:

 

1) You can review error logs on your myRIO using NI max (your myRIO might be resetting itself due over use of resources (memory or processor))

2) Change all tunnel modes to Shift register, like the one you have in the writer loop

3) Change time out value for NS Writer VI to "0" in the writer loop, clear the timeout error code as it may occur (just for troubleshooting)

4) Try reducing buffer size on writer side unless it has to be 10K elements

5) Add a wait time in the reader VI also (maybe 20ms)

 

Are you monitoring RT CPU loads (myRIO)? If so, are you seeing high CPU utilization and/or memory consumption. Does your application work fine with a 1000ms wait? Are you sure there is no error occurring in the other subVI that runs on the myRIO?

 

0 Kudos
Message 2 of 29
(1,669 Views)

Thank you for repying. 

 

1)  I looked into RT target errors and theres just that RT target ran into unexpected and needed to restart. 

 

2,3,4,5) I replaced all tunnels, added wait 20ms to reader and without timeout it ran without crashing, but i was able to decrease wait time to 0 ms and it was streaming picture but it didnt look like it was taking/ streaming more of them. It was as choppy as it was at 200ms. 

3) after adding timeout and clearing the error (hopefully the right way, not sure) I got another error -1950678941 

Jenda02_0-1627520159145.png

Where can I best monitor these values? I was looking at cpu load in MAX and Distributed system manager isn´t showing me cpu load or memory in controller status. 

 

J. 

0 Kudos
Message 3 of 29
(1,656 Views)

Just to clarify,


2,3,4,5) I replaced all tunnels, added wait 20ms to reader and without timeout it ran without crashing

So are you saying that you were able to stream?


it was streaming picture but it didnt look like it was taking/ streaming more of them. It was as choppy as it was at 200ms. 

3) after adding timeout and clearing the error (hopefully the right way, not sure) I got another error -1950678941 


You added timeout on the "Connect NS Writer End Point".  I was talking about timeout for writing. This would have caused to start the while loop without even connecting to the end point.

Keep the url as you had (see timeout settings)Xonmyth743_0-1627528023351.png                          On the writing side adjust as neededXonmyth743_1-1627528042976.png

You may not want to start rest of your process without making sure that your end point is connect. Based on how you have your VI set up.

 

 

 

Attached is what I had made for some quick testing, see if you can make use of those VIs. (VI snippets). Those VI have states (not really, but you can go step wise, first connect then send and so on).

 

3) Clear Error.VI was supposed to be placed inside the while loop right after your writing VI. (This was just for testing purposes, but may not be needed.)

 


Where can I best monitor these values? I was looking at cpu load in MAX and Distributed system manager isn´t showing me cpu load or memory in controller status. 


Under RT Utilities pallet, you can use get RT CPU Load VI. You can setup this in a parallel loop with a 1000ms wait time in it. (but for now, you may not really need it). First check out attached VI snippets and the most recent suggestions.

 

Also, If you do not absolutely need buffered data, you can look into using Network Shared Variables  these are easy to use and you will get the most recent data.

 

Download All
0 Kudos
Message 4 of 29
(1,636 Views)

I've done both acquiring videos over Ethernet and using Network Streams in LabVIEW-RT environments, but not both together.  There are "hidden issues" in both situations that can trip the unwary.

  • I was using an older Camera that was an "Ethernet Camera" using TCP/IP as the communication medium (back before there was USB 3).  The Camera, itself, was four floors away, but all of the Camera Buffers (where the images were actually stored) were in the Host PC.  Note that the IMAQ "Buffer" wire really is a reference to a data buffer in the Host PC.  When the Camera takes an Image, it puts it into its "buffer" (which means TCP/IP starts sending it over the Network to the Host PC, where the pixels are stored in memory wherever the Driver puts it).
  • Network Streams form a one-way "transmission line" for data.  When you are all done with the one-way transmission, you close down the Stream.  If you close the Writer before the Reader has read the last entry, you will lose the last entry.  
  • It is not at all clear how you are synchronizing the ending of the Host and Target Loops.  There are two Stop controls.  Let's assume they happen at roughly the same time -- what should you expect to happen?  You are "flushing" the Writer Stream, but you have no delay to ensure that the Reader has had a chance to read the data (and in the case of a large amount of data associated with a video, probably means it has not finished reading), so closing the Stream without a Time Out (I use 1000 msec, myself) you will probably lose the last frame (or two).

So I'd start by adding a Buffer Timeout on the Writer's Destroy Stream function.

 

Bob Schor

0 Kudos
Message 5 of 29
(1,631 Views)

Hello, 

 

So are you saying that you were able to stream?

Yes, just by replacing tunnels, adding wait 20ms to read I could stream to pc. Write and read element timeout was set to 1000 ms and when I lowered it read element on reader endpoint was singaling that it timed out. 

 

It is not at all clear how you are synchronizing the ending of the Host and Target Loops.  There are two Stop controls.  Let's assume they happen at roughly the same time -- what should you expect to happen?  You are "flushing" the Writer Stream, but you have no delay to ensure that the Reader has had a chance to read the data (and in the case of a large amount of data associated with a video, probably means it has not finished reading), so closing the Stream without a Time Out (I use 1000 msec, myself) you will probably lose the last frame (or two).


I forgot about that but i dont really mind loosing a frame or two. What Im after is to have some data about cpu utilization, memory, max frequency that i can stream picture before or if it crashes, what can it handle. 

 

After reading your sugestions I made some changes and I definetly made some mistake because now Im not streaming and have stuck frame from previous session. 

Jenda02_0-1627552241572.png

 

 

Download All
0 Kudos
Message 6 of 29
(1,623 Views)

Hi Jenda02,

 

I am attaching two VIs, I could not open yours since I am using previous version of LabView also I do not have vision module installed. I tried to incorporate my interpretation of Bob_Schor's suggestion in there

 

The Network stream communication works on these VI. Simply put RT Side VI on RT and PC Side VI on PC. Change Data type as required.

 

Make sure you run the RT Side VI first. Then the VI on the PC side, to stop transmission you would have to click "STOP" on RT first. You can change it to work the other way around if needed. Test these VIs (as is) first and then add your image processing VIs.

 

I tested it and it worked for me. Hope this helps.

Download All
0 Kudos
Message 7 of 29
(1,603 Views)

Hi,

first of all thank you for those great examples. They were easy to understand. When I tried sending different types of data it worked great but once I implemented image aquisition from my vi it didn´t go so well. When I first ran the application connection was established and images were streamed but in a way that timed out indicator was switching state constantly while image was switching with empty one and then Myrio disconnected after around 20 s.  When I ran it for a second time there was image stuck in a writer side and nothing on reader but timed out was flickering. I opened Distributed system manager so I could check memory and my usage was quite high. 

Jenda02_1-1627582906147.png

Don´t know if I did something wrong. But maybe its my webcam that it cant keep up. I have generic usb 3.0 1080p camera that is configured in MAX to acquire video in 480p 30fps.  I just noticed that it displays fps at the bottom of MAX, but shouldn´t it say 30 fps acquired  or more of displayed?  I´ve seen displayed be at 5 when using grab in MAX. 

Jenda02_2-1627583299564.png

EDIT: I freed up some memory and it runs better but timed out indicator still flickers while its receiving image. Cpu usage now is around 50% and memory usage continues to rise from 130 MB to  205 MB as shown in the image up. 

Jenda02_0-1627585737495.png

 

And after connecting to MyRio again after it lost connection theres this error. Which after diging trough forum seems to indicate memory leak. 

Jenda02_0-1627586558557.png

 

 

 

0 Kudos
Message 8 of 29
(1,586 Views)

Hi Jenda,

 

I could share all that I knew about NS so my knowledge stops here. As NS works with other data types. I think it has to do something with data acquisition VIs and it's data type. Your CPU usage is at 100% no wonder why your myRIO is resetting.

I have no clue about how image acquisition works. But if I had to take a guess:

1) Either a lot data is building up fast

2) Some loop is running without enough wait (Longer the wait lesser load on CPU)

 

See if the follow makes any difference:

1) Start with 5 second wait time in RT VI and bring it down gradually. See if that lowers your resource consumption.

 

EDIT: What did you do to bring down CPU usage and how did you free up the memory?

0 Kudos
Message 9 of 29
(1,564 Views)

Hi, 

I tried it with 5s wait and each spike to 100% on CPU0 is one frame sent. Memory started to build up fast and last spike to around 50% is when Myrio was disconnected. So my guess is that the first point is right and Rio cant keep up with data build up so it disconnects. 


1) Either a lot data is building up fast

 


Jenda02_0-1627647830204.png

 


EDIT: What did you do to bring down CPU usage and how did you free up the memory?


Last image was right after restart of MyRio and I deleted deployed RTstartup from the unit and it freed up the memory to around 130 MB.  

0 Kudos
Message 10 of 29
(1,530 Views)