You can detect attachment to the FMS by checking the RawControlByte output of the driver station Get Mode vi. It's called in Robot Main and the control byte is discarded. It'd probably be most efficient to have it set to a global variable in Robot Main, rather than calling Get Mode just for the control byte.
The Get Mode vi itself uses the 1st, 4th, and 5th bits in order to determine the current mode, and outputs the appropriate enum value.
The relevant bits of the RawControlByte are as follows:
Code:
Bit | Contents
-----+----------
0 |
1 | Test Mode
2 |
3 | FMS Attached
4 | Telop(0) / Autonomous(1)
5 | Enabled
6 | Emergency Stopped(0) / Okay(1)
7 |
I've tested all of those except for FMS Attached, but I'm extremely confident it'll work properly. Also, WPIlib (C++ at least) has supposed definitions for the other bits... but it also has Test Mode called cRIOChkSum, so I don't think it's really up to date... Nothing actually uses FMS Attached and the other ones anywhere, except for the firmware.