04-18-2017 09:08 AM
Hi,
For the stop button, this would be because once you press the button to start the acquisition the case structure never returns to the 'Waiting on Button' case. You could move the stop button outside of the case structure, or inside the 'Camera On' case. This should fix that issue.
With the data not being written to the file, I'm not entirely certain. One thing I did notice is that the reference you are creating with the Constructor Node is the class: uc480.Tools.Video. There is another class under uc480.Video.
Both of these classes have a method named Start() available to them. It's possible that this could be causing the issue in behaviour.
Nic
04-18-2017 10:26 AM
Hi Nic,
The stop button is now working as you suggested! And it seems as though the data is now being written to the file as well. I had a look at what the differences between uc480.Tools.Video and us480.Video were, it appears that with Tools it's possible to manually programme a lot more (in case you were interested, I found this out here: DCx Camera Documentation).
Last issue (hopefully!) is that, when I refresh the explorer window, I can see the file size increasing which to me indicates that the video data is there. However, when I go to play the video I have captured with Windows Media Player (I can still use WMP to play back videos I capture when the programme is not run as a state machine) it warns me that it encountered a problem when trying to play my file. Do you think that because of the way the video is being passed through the programme, the file could be corrupted?
Thanks for all the help!
Emma
04-18-2017 09:20 PM
Hi Emma,
Thanks for the documentation, it should be helpful if you run into any more issues.
Possibly regarding your issue with the video not playing back, I notice that in the stop case you close the reference to the camera in parallel with calling the 'Exit' node. Is it possible that the Exit is not being called because of a race condition occuring with the Close Reference node, and so the video isn't being properly terminated? I couldn't tell from a quick look at the documentation whether or not 'Exit' had any effect on the video file, or just the camera (I actually think probably the latter, in which case it isn't likely to be your problem). You should move the Close Reference to after the Exit node by wiring it to the Invoke Node reference out.
Let us know if this fixes your issue (but I'm not sure it will - sorry).
04-19-2017 02:16 AM
I think cbutcher is right. It's possible the reference for the camera is being closed before the video is closed, so the file is not closed properly, which would cause the corruption you are seeing.
The easiest way to remedy this is to use the error wires to force execution order and have all of the 'Close Reference' vi's come after the close and exit of the video.
Nic
04-19-2017 04:04 AM
Thank you both. I changed it, as per your recommendations, so that the close reference vi came after the Exit() node. Unfortunately this hasn't fixed my problem. I have noticed that I am using the stop button in the 'Camera On' state with a select function to decide if the camera should remain in the 'On' state or go to the 'Stop' state.
Inside the while loop, but outside the case structure I also have an equality that will be equal when the 'Stop' state is running in the case structure, this is wired to the stop of the while loop.
Is it possible that this is becoming True and stopping the while loop, causing the programme to stop, meaning the 'Stop' state will never actually be executed?
Then, because the 'Stop' state is never executed, the video capture does not exit as it should, thus corrupting the file? I have tried wiring the stop of the while loop to a select function but it will only accept a boolean input. I'm unsure where else I could wire it so it will wait until the 'Stop' state has finished before the loop stops.
Maybe there is another way to make the 'while stop' wait until my 'Stop' state has finished.
Emma
04-19-2017 04:23 AM
04-19-2017 05:02 AM
Hi Nic,
Thanks for that. Now I know how to handle the 'Stop' correctly. Unfortunately, I'm still having the same issue. I've tried closing all of the references to video, camera and picture box from the 'Stop' state and included basic error handling. I've run out of ideas as to what could be causing this to fail. I've compared it to the vi that isn't run as a state machine and tried to mimic what I have there in terms of data flow. There's clearly something small that is different between the state machine and the non state machine programmes. I'll keep looking and hopefully it will be resolved without too much of a headache!
Emma
04-19-2017 05:14 AM - edited 04-19-2017 05:25 AM
Hi Emma,
I'm looking through the two side by side (the latest attached Save_AVI_State_machine.vi and Save_Avi-copy.vi) and I haven't found anything just yet but I wanted to comment that in your init case there're a few strange points...
In your allocate method, I'm seeing the width and height wired to other inputs and what I guess is the camera reference id wired lower down. I expect this is because I don't have the library installed (going to find and install it now so I can check more accurately these VIs) but wanted to comment just in case!
Further, you use Height and Width local variables but I'd guess that they take the value of the starting indicator (i.e. the previous run), not the current values (which are probably written later). Again, I'm sure this isn't your main issue with closing, but it's something to be aware of.
Edits:
As you and Nic already discussed, you probably want to wire a True Constant out from the stop case to the stop control for the while loop. However, in the copy you uploaded, the equality check outside of the case structure will be false on the last iteration of the Camera On case, then when you press stop, it should go to true, stopping the loop after the stop case runs. I don't see where it would cause a problem. (But the constant is cleaner, easier to understand and probably simpler for LabVIEW to implement)
Found and downloading the library but might take me a while on this connection!
04-19-2017 08:24 PM
So I had a bit of a go refactoring some of your code - I don't know that it will improve matters, but perhaps you can check that it doesn't make things worse? Assuming that there are no changes, I can try and work out what's being strange. It should behave the same as your code (I only moved the close reference node in the stop case, and placed a stop true constant).
04-20-2017 03:17 AM
Hi cbutcher,
Thank you for taking the time to go through my code so thoroughly and rework it. A couple of points on your attachment:
The code runs with no issues and seems to identify the camera which is positive! When I run it, it waits for the button press and will show me when it's running. I do not, however, have a live display on the screen. The picture box appears to disappear once the start button is clicked. There is also no longer an option to choose a path and filename for the video capture so I can't tell if the camera is actually acquiring data. It's also necessary for me to be able to set the frame rate of the camera before acquisition begins.
I've attached the latest code I've been working from which includes these options.
Emma