View Full Version : Detecting if the code runs from the PC or the RoboRIO
I have some code that I want to run only when working from the PC (connected with an Ethernet cable) for debugging purposes.
Is there a way for the code to detect if the code runs from the PC or from the RoboRIO itself?
That way I won't need to disable this code block whenever I download it to the robot.
Thank you!
Jonathan L.
29-07-2015, 13:04
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/
The Conditional Disable Structure...
I haven't ever done it, but I imagine it can be done using some kind of property node. (to LabVIEW documentation!) I would highly recommend removing any code only running in debugging mode from the final robot project to avoid any chance of the robot thinking it is in debug mode and to keep the robot from having to constantly check whether or not it is in debug mode.
Just my $0.02
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/
The Conditional Disable Structure...
That looks great! I will try it on the robot the next time I'll have a chance :)
I haven't ever done it, but I imagine it can be done using some kind of property node. (to LabVIEW documentation!) I would highly recommend removing any code only running in debugging mode from the final robot project to avoid any chance of the robot thinking it is in debug mode and to keep the robot from having to constantly check whether or not it is in debug mode.
Just my $0.02
That's a good point, but I think that the structure that was suggested by Jonathan makes sure that whatever that is in the block doesn't even get compiled so there are no constant checking. (I hope :P)
wt200999
29-07-2015, 15:12
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/
The Conditional Disable Structure...
Unfortunately I do not think the conditional disable structure will work the way that you want without some extra effort.
The only time RUN_TIME_ENGINE is FALSE will be if you are running the code on your host machine. This works if you are using the simulator vs the actual robot, but once you run it on the robot as you describe it will be TRUE. Target_Type and OS will give you the same issue.
You can create a conditional that is project wide, and manually change it when you build, but that is tedious and more importantly is error prone.
You may be able to play around with the build specification, maybe with the pre/post build actions combined with the project wide build specification, but this is not something I have never tried.
You may be better of with the suggestion from Ari423 unless you have a good reason to prevent the code block from compiling in the first place.
Greg McKaskle
29-07-2015, 15:30
If you are asking about simulated versus running on the roboRIO, the Conditional Disable Structure is what you are looking for. An example of how to use it is shown in this VI vi.lib\Rock Robotics\SystemInterfaces\NetworkCommunication\Net Comm_UnloadCPPStartupProgram.vi
If you want to know if a debugging host is connected, I believe you want to use a Property Node to read the App.UserInterfaceAvailable property. Read the help and I think you will see that it does what you want. If not, please explain more of what you are looking for.
Greg McKaskle
The only time RUN_TIME_ENGINE is FALSE will be if you are running the code on your host machine. This works if you are using the simulator vs the actual robot, but once you run it on the robot as you describe it will be TRUE. Target_Type and OS will give you the same issue.
I just had an idea. When you get the file path of Robot Main in Robot Main, if it is built and running in the robot project the second to last string in the file path will be projectName.exe, whereas if you were running it in debug mode (manually running Robot Main) the second to last string in the file path will be the folder the project is in. You should be able to get the file path, strip it twice, and search the second stripped string for ".exe". If you are running a build the index will be greater than 0 (it exists somewhere in the string). If it is running in debug mode, the index will be -1 (search string isn't in source string). You can then save this bool as a global, carry it into teleop and/or periodic, or do whatever you want with it. Let me know if this works.
EDIT: I think this is what you are looking for without using any complicated property nodes. There may be other ways to do the same thing using property nodes or otherwise, and you should feel free to use whichever you feel is easier. My original suggestion about removing this code from the final project still stands.
If you want to know if a debugging host is connected, I believe you want to use a Property Node to read the App.UserInterfaceAvailable property. Read the help and I think you will see that it does what you want. If not, please explain more of what you are looking for.
Greg McKaskle
This is what I'm looking for, I'll try it.
I just had an idea. When you get the file path of Robot Main in Robot Main, if it is built and running in the robot project the second to last string in the file path will be projectName.exe, whereas if you were running it in debug mode (manually running Robot Main) the second to last string in the file path will be the folder the project is in. You should be able to get the file path, strip it twice, and search the second stripped string for ".exe". If you are running a build the index will be greater than 0 (it exists somewhere in the string). If it is running in debug mode, the index will be -1 (search string isn't in source string). You can then save this bool as a global, carry it into teleop and/or periodic, or do whatever you want with it. Let me know if this works.
EDIT: I think this is what you are looking for without using any complicated property nodes. There may be other ways to do the same thing using property nodes or otherwise, and you should feel free to use whichever you feel is easier. My original suggestion about removing this code from the final project still stands.
I want to try your method but I don't have enough experience with LabVIEW strings. Can you post here the code that does what you have explained?
I want to try your method but I don't have enough experience with LabVIEW strings. Can you post here the code that does what you have explained?
Sorry it has taken me so long to get back to you, I haven't had access to a computer with LabVIEW on it.
Here is the sample code (you can drag and drop it into a vi and it will automatically render as LabVIEW code):
19245
It should return true if it is running in debug mode and false if it is running as part of a build. Let me know how it works out.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.