Seeing if a partner controller is connected using RobotC

I am trying to create two versions of my driver control code, on that runs if a partner controller is connected, one that runs if it is not. a search in the forums turned up this as a method of telling


	if( nVexRCReceiveState & 0x01 )
    {
    	player1 = true;
    // first joystick is connected
    }
if( nVexRCReceiveState & 0x02 )
    {
    	player2 = true;
    // second joystick is connected
    }

however that post was from 2012.
the problem I am finding is that both of those IF statements always seem to return true.
am i doing something wrong, or does this method not work with current versions of robotC, does any one know a way of doing this?

Linking to a particular post is almost impossible now, so here is some code from the “ROBOTC programming tips” thread I posted a couple of years ago. The above code is correct, you can only have the partner joystick if the main joystick is also available.

// send some useful information to the debug stream
void
PrintnVexRCReceiveState()
{
    if( (nVexRCReceiveState & (vrXmit1 | vrXmit2)) == (vrXmit1 | vrXmit2) )
        writeDebugStreamLine("Transmitter 1 and 2 connected");
    else
    if( nVexRCReceiveState & vrXmit1 )
        writeDebugStreamLine("Transmitter 1 connected");
    else
    if( nVexRCReceiveState & vrXmit2 )
        writeDebugStreamLine("Transmitter 2 connected");
    
    if( nVexRCReceiveState & vrCompetitionSwitch )
        writeDebugStreamLine("Competition switch is connected");
    else
        writeDebugStreamLine("Competition switch not connected");
    
}

// Monitor nVexRCReceiveState and show changes
task main()
{
    unsigned int rcReceiveState      = 0;
    unsigned int last_rcReceiveState = 1; // cause print on program entry
    
    while(1)
        {
        rcReceiveState = nVexRCReceiveState   
        
        if( rcReceiveState != last_rcReceiveState )
            {
            writeDebugStreamLine("rcReceiveState is %02X", rcReceiveState );
            last_rcReceiveState = rcReceiveState;
            PrintnVexRCReceiveState();
            }
            
        wait1Msec(25);
        }
}

ok you said the code I had above was correct, but it is not working, both if statements always return true, regardless of how many controllers are connected. Then the code you posted was different should I use “vrXmit1” in place of ‘0x01’ and “vrXmit2” in place of "0x02’?

Strange. Here are the definitions, they are the same.

  typedef enum
  {
    vrNoXmiters           = 0,        // No transmitters connected
    vrXmit1               = 0x01,     //                          1 == Transmitter 1 connected
    vrXmit2               = 0x02,     //                          1 == Transmitter 2 connected
    vrBit2                = 0x04,     // Unused
    vrCompetitionSwitch   = 0x08,     // 0 == No Comp Switch      1 == Competition Switch attached.
    vrResetSlave          = 0x10,     // Unused
    vrGameController      = 0x20,     // 0 == Legacy75MHz,        1 == Game Controller
    vrAutonomousMode      = 0x40,     // 0 == Driver Control,     1 == Autonomous Mode
    vrDisabled            = 0x80,     // 0 == Enabled             1 == Disabled.
  } TVexReceiverState;

ok, hmm perhaps I am confused, should “transmitter 2” be the partner controller?

Yes, let me check it out tomorrow to make sure everything is still working.

If the 2nd transmitter is connected, the first must also be connected.

This is the code I used in Toss up when I last did vex.
It assumes that there will not be 0 controllers.

		if (nVexRCReceiveState & vrXmit2)//if 2 controler
		{

		}
		else//if 1 controler
		{

		}

http://puu.sh/minqh.png

https://vexforum.com/index.php/conversation/post/85246

i dont understand why this is the only way to do it :frowning:

Ok, so right click on the post date, thanks, not obvious but at least it can be done.

Code still works correctly in V4.52.

Ok thanks for the Update, we were seeing some other weird behavior from the partner controller as well, so I will look into checking it with a different partner controller