View Single Post
  #4   Spotlight this post!  
Unread 17-01-2016, 15:03
AndyB871 AndyB871 is offline
Registered User
FRC #0871
 
Join Date: Jan 2012
Location: East Islip
Posts: 37
AndyB871 has a spectacular aura aboutAndyB871 has a spectacular aura aboutAndyB871 has a spectacular aura about
Re: Java SerialPort kUsb

Well, a code snippet is easy (which is why i didn't post one in the first place)
There isn't any ack for this communication... Unless there's something special I have to do with VISA? (I'll look into that)

This is our test robot code, literally all of it ( removed some comments to not ake this post huge )
Code:
package org.usfirst.frc.team871.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.SerialPort.Port;

/**
 * Default comment
 */
public class Robot extends IterativeRobot {
	SerialPort thePort;
	Joystick joy;

	/**
	 * This function is run when the robot is first started up and should be
	 * used for any initialization code.
	 */
	public void robotInit() {
		thePort = new SerialPort(9600,Port.kUSB);
		joy = new Joystick(0);
	}

	/**
	 * This function is called periodically during operator control
	 */
	public void teleopPeriodic() {
		if(joy.getRawButton(1)) {
			//System.out.println("Red");
			thePort.writeString("!255R000G000B");  //Sends successfully, (Neopixels turn red) then crashes robot code
			thePort.readString();
		}

		if(joy.getRawButton(2)) {
			//System.out.println("Green");
			thePort.writeString("!000R255G000B"); //Sends successfully, (Neopixels turn Green) then crashes robot code
		}

		if(joy.getRawButton(3)) {
			//System.out.println("Blue");
			thePort.writeString("!000R000G255B"); //Sends successfully, (Neopixels turn Blue) then crashes robot code
		}
	}
	
	/**
	 * Default Comment
	 */
	public void autonomousInit() { }

	/**
	 * This function is called periodically during autonomous
	 */
	public void autonomousPeriodic() { }

	/**
	 * This function is called periodically during test mode
	 */
	public void testPeriodic() { }

}
I don't have the laptop that's got our arduino code on it, but it's a simple bit of code that reads a string in from the serial, and parses out the 3 color components in the format !xxxRxxxGxxxB where ! is the start character, and the x's are the digits of the components. It sends no response.
Reply With Quote