Go to Post FIRST truly isnt about building robots, but allowing yourself to reach higher and farther than you ever could. - Brandon Holley [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2011, 22:47
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
Using the cRIO serial port in Java

I am looking for a Jave code snippet of how to configure the cRIO serial port and how to use it. Can it take over the System.Out functionality?

I am also looking for code to do formatted number to string conversion. Is there any native Java class? I need something simple. I do not need all of the Swing overhead.

I am planning on sending data out the cRIO serial port into a PC running HyperTerminal to make an elaborate disgnostic screen. I will send it ANSI escape sequences to control the cursor. I've done this in C and it is a great tool for the team to maintain the robot.

Daniel
  #2   Spotlight this post!  
Unread 07-02-2011, 23:05
kinganu123 kinganu123 is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Piscataway, NJ
Posts: 243
kinganu123 is on a distinguished road
Re: Using the cRIO serial port in Java

I'm just a bit confused on what you mean by the serial port...
I thought the serial port from the module was to connect to the digital sidecar....
__________________
  #3   Spotlight this post!  
Unread 08-02-2011, 01:59
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Using the cRIO serial port in Java

Quote:
Originally Posted by Daniel View Post
I am looking for a Jave code snippet of how to configure the cRIO serial port and how to use it. Can it take over the System.Out functionality?

I am also looking for code to do formatted number to string conversion. Is there any native Java class? I need something simple. I do not need all of the Swing overhead.

I am planning on sending data out the cRIO serial port into a PC running HyperTerminal to make an elaborate disgnostic screen. I will send it ANSI escape sequences to control the cursor. I've done this in C and it is a great tool for the team to maintain the robot.

Daniel
If you switch the CONSOLE OUT DIP switch off, the serial port will not be controlled by the System.out. You can then use the SerialPort class in WPILib to access the port.

Have you considered using a TCP connection to the PC instead?

-Joe
  #4   Spotlight this post!  
Unread 08-02-2011, 08:55
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
Re: Using the cRIO serial port in Java

The serial port on the cRIO is the 9-pin D connector.

I prefer serial RS232 communications because it is simple. No setting of IP address, just plug and go. I've used this in the past and liked it.

I am asking for an example of using the SerialPort class that has actually worked. Specifically the constructor with try-catch logic in Java.
  #5   Spotlight this post!  
Unread 08-02-2011, 10:58
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: Using the cRIO serial port in Java

Code:
package com.shadowh511.mayor.util;

import edu.wpi.first.wpilibj.SerialPort;

/**
 *
 * @author Team 2412
 */
public class Arduino {
    /*
     * Hopefully, i will be able to have an arduino be hooked up to the robot
     * and communicate with the serial port.  I can use this to do many things,
     * such as maintain a LCD screen and display data on it to help the electrical
     * and mechanical teams figure out what went wrong.
     *
     * In all realism, it will most likely just be a fun cool thing for me to
     * play with :D
     */
    private SerialPort serial;

    public Arduino() {
        try {
            serial = new SerialPort(115200);
            this.serial.disableTermination();
            this.serial.print("h");
            System.out.println("Arduino Starting, waiting 0.5 seconds to get data");
            String e = this.getData();
            edu.wpi.first.wpilibj.Timer.delay(0.125);

            if(e.equals("h")) {
                System.out.println("Arduino communications locked in");
            }
        }
        catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
        }
    }

    public String getData() {
        try {
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public boolean sendData(byte[] buffer) throws Exception {
        try {
            int count = buffer.length;
            this.serial.write(buffer, count);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }
    
    public boolean printf(String data) {
        try {
            this.serial.print(data);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }

    public String requestData() {
        try {
            this.serial.print("r");
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public int requestData(String request) {
        try {
            this.serial.print(request);
            return NumberUtils.stringToInt(this.getData());
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return 0;
        }
    }
}
  #6   Spotlight this post!  
Unread 08-02-2011, 12:06
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
Re: Using the cRIO serial port in Java

Does this work regardless of the CONSOLE OUT switch position on the cRIO?

I do not want console data mixed in with my diagnostic data, so I prefer the switch in the OFF position. Can I still send data to the Serial port?
  #7   Spotlight this post!  
Unread 08-02-2011, 12:11
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: Using the cRIO serial port in Java

I would test that if i were you, I don't know
  #8   Spotlight this post!  
Unread 08-02-2011, 18:08
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
Re: Using the cRIO serial port in Java

Why does netbeans not find the valueOf() function?

Is there a special class to load?

long l;
String s;
s = valueOf(l);
  #9   Spotlight this post!  
Unread 17-02-2011, 08:02
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
Re: Using the cRIO serial port in Java

Because you need to use:


long l;
String s;
s = String.valueOf(l);
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi