The Doctor
30-01-2016, 13:26
Recently I've been experimenting with sending status codes to an Arduino from the RoboRio. I've so far tried toggling serial from the MXP to the arduino, and serial over USB between them. Neither of these have worked yet. I was wondering if any teams had input on how to send single byte status packets?
Current robot code (java):
arduino = new SerialPort(19200,SerialPort.Port.kUSB);
...
byte mode1 = 0; //////// 0b<red><blue><fms><auton><teleop><disabled><enabled><attached>
if (ds.getAlliance() == DriverStation.Alliance.Red) mode1 |= 0b10000000;
if (ds.getAlliance() == DriverStation.Alliance.Blue) mode1 |= 0b01000000;
if (ds.isFMSAttached()) mode1 |= 0b00100000;
if (ds.isAutonomous()) mode1 |= 0b00010000;
if (ds.isOperatorControl()) mode1 |= 0b00001000;
if (ds.isDisabled()) mode1 |= 0b00000100;
if (ds.isEnabled()) mode1 |= 0b00000010;
if (ds.isDSAttached()) mode1 |= 0b00000001;
byte[] mode2 = {mode1};
arduino.write(mode2, 1);
The problem is that the instantiation of the SerialPort object causes the robot code to error and restart. The exact error can't be copied out of the DS, but it's something along the lines of this:
RuntimeException: HAL: -VISA: Resource not found at [SerialPortJNI.serialInitializePort]
Has anyone gotten Rio-to-Arduino comms to work using Serial?
Current robot code (java):
arduino = new SerialPort(19200,SerialPort.Port.kUSB);
...
byte mode1 = 0; //////// 0b<red><blue><fms><auton><teleop><disabled><enabled><attached>
if (ds.getAlliance() == DriverStation.Alliance.Red) mode1 |= 0b10000000;
if (ds.getAlliance() == DriverStation.Alliance.Blue) mode1 |= 0b01000000;
if (ds.isFMSAttached()) mode1 |= 0b00100000;
if (ds.isAutonomous()) mode1 |= 0b00010000;
if (ds.isOperatorControl()) mode1 |= 0b00001000;
if (ds.isDisabled()) mode1 |= 0b00000100;
if (ds.isEnabled()) mode1 |= 0b00000010;
if (ds.isDSAttached()) mode1 |= 0b00000001;
byte[] mode2 = {mode1};
arduino.write(mode2, 1);
The problem is that the instantiation of the SerialPort object causes the robot code to error and restart. The exact error can't be copied out of the DS, but it's something along the lines of this:
RuntimeException: HAL: -VISA: Resource not found at [SerialPortJNI.serialInitializePort]
Has anyone gotten Rio-to-Arduino comms to work using Serial?