Welcome! Log In Create A New Profile

Advanced

my first java attempt

Posted by ZachHoeken 
my first java attempt
June 10, 2007 05:59PM
Hoeken:~/Desktop/reprap/trunk/reprap/host zachsmith$ svn diff
Index: src/org/reprap/gui/steppertest/Main.java
===================================================================
--- src/org/reprap/gui/steppertest/Main.java (revision 650)
+++ src/org/reprap/gui/steppertest/Main.java (working copy)
@@ -48,32 +48,64 @@
public static void main(String[] args) throws Exception {
Thread.currentThread().setName("Stepper Exerciser");
JFrame frame = new JFrame();
- Main inst = new Main(frame);
- inst.setVisible(true);
+
+ try {
+ Main inst = new Main(frame);
+ }
+ catch (Exception e){
+
+ JOptionPane.showMessageDialog(null, e.getMessage());
+
+ return;
+ }
+
+ //inst.setVisible(true);
}

public Main(JFrame frame) throws Exception {
super(frame);

- SNAPAddress myAddress = new SNAPAddress(localNodeNumber);
- communicator = new SNAPCommunicator(Preferences.loadGlobalString("Port(name)"),
- baudRate, myAddress);
+ SNAPAddress myAddress = new SNAPAddress(localNodeNumber);

- extruder = new GenericExtruder(communicator,
- new SNAPAddress(Preferences.loadGlobalString("Extruder0_Address")),
- Preferences.getGlobalPreferences(), 0);
+ String port = Preferences.loadGlobalString("Port(name)");
+ String err = "";

- initGUI();
- Utility.centerWindowOnScreen(this);
+ try {
+ communicator = new SNAPCommunicator(port,baudRate, myAddress);
+ }
+ catch (gnu.io.NoSuchPortException e)
+ {
+ err = "There was an error opening " + port + ".\n\n";
+ err += "Check to make sure that is the right path.\n";
+ err += "Check that you have your serial connector plugged in.";
+
+ throw new Exception(err);
+ }
+
+ if (err.length() == 0)
+ {
+ extruder = new GenericExtruder(communicator,
+ new SNAPAddress(Preferences.loadGlobalString("Extruder0_Address")),
+ Preferences.getGlobalPreferences(), 0);
+
+ initGUI();
+ Utility.centerWindowOnScreen(this);
+ }
}

public void dispose() {
+
super.dispose();
- if (extruder != null) extruder.dispose();
- motorX.dispose();
- motorY.dispose();
- motorZ.dispose();
- communicator.dispose();
+ if (extruder != null)
+ extruder.dispose();
+ if (motorX != null)
+ motorX.dispose();
+ if (motorY != null)
+ motorY.dispose();
+ if (motorZ != null)
+ motorZ.dispose();
+ if (communicator != null)
+ communicator.dispose();
}

private void initGUI() throws Exception {
Re: my first java attempt
June 10, 2007 07:36PM
Ooops! Sorry Zach - doesn't work...

When I run it with a RepRap attached I get:

Opening port /dev/ttyS0
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
CAPA extruder vRefFactor set to 7
Experimental: JNI_OnLoad called.

Then it locks up. If I revert to the old version that goes fine. Did
you test it on just a single stepper board? Does that work? If so,
then it may be something to do with having all three in the loop.

Best wishes

Adrian

Dr Adrian Bowyer
[staff.bath.ac.uk]
[reprap.org]

Quoting Zach 'Hoeken' Smith :

> hey guys,
>
> update your host svn copies!
>
> after the ruckus on the list today, i figured i should work and accomplish
> something on the project. i decided to take a look at the java and see if i
> could fix a simple bug. actually, first i learned how to compile it! i
> installed ant and figured out how that worked. (on osx no less!!) i mucked
> a bit in the build files and figured it out.
>
> a few ant runs later, and i was in business. i did notice that ant jar
> doesnt remove the jar directory first, so i updated the clean target to do
> that. thats been checked in. i was also getting a weird error:
>
> Warning: 'file:./build-user.xml' in
> /Users/zachsmith/Desktop/reprap/trunk/reprap/host/build.xml should be
> expressed simply as './build-user.xml' for compliance with other XML tools
>
> so i removed the file:./ from the build.xml file. let me know if this
> causes problems for anyone!!
>
> then, onto the real java code. the first thing i'd like to do is get rid of
> as many of the uncaught exceptions that trigger ugly, unhelpful error
> dialogs. a first easy one to test was opening the 'stepper exerciser'
> dialog without a board plugged in. i had a slight bit of trouble figuring
> out what level to put my try/catch blocks in, but i got it eventually. now
> it will give you an error and not even take you to the stepper dialog.
> thats all the further i went because i'm tired, satisfied for the night, and
> wanted to share the changes with you guys before i went to bed.
>
> anyway, here is a zip file. so long as there are no objections, i'll commit
> it tomorrow and give some of the other areas the same treatment.
>
> for your reference, i've also attached the svn diff output.
>
> ~Zach
>


_______________________________________________
Developers mailing list
Developers@reprap.org
[reprap.org]
Sorry, only registered users may post in this forum.

Click here to login