heise online · c't · iX · Technology Review · Telepolis · mobil · Security · Netze · heise open · heise resale · Autos · c't-TV · Jobs · Kiosk
Zum Inhalt
c't

c't Projekte - c't-Bot und c't-Sim - Mailinglisten

c't-Bot und c't-Sim


[Voriger (Datum)] [Nächster (Datum)] [Voriger (Thread)] [Nächster (Thread)]
[Nach Datum][Nach Thread]

Re: [ct-bot] ComConnection

Absender: Benjamin Benz
Datum: Sa, 29.04.2006 23:21:35
In-reply-to: <4453C303.40402@xxxxxxxx>
References: <004d01c66b9d$e65f2370$3d01a8c0@Dothan> <4453C303.40402@xxxxxxxx>


Also ich wäre sehr für die RXTX-Library, zumindest solange die Commapi nicht in der aktuellen Version Windows unterstützt. Unter Linux macht aber selnst die aktuelle Commapi probleme.

MfG Benjamin Benz

Benjamin Benz wrote:
Der zweite Link enthält leider eine abgelaufene Session-ID

MfG Benjamin Benz

Max Odendahl wrote:
Hallo,

hier ein Vorschlag für einen Patch für eine Klasse ComConnection sowie
die zusaetzlichen Elemente wie GUI.
Mit diesem Patch sind auch Verbindungen zu realen Bots über die serielle
Schnittstelle möglich.

Verwendet wird die Java Communication API:
http://java.sun.com/products/javacomm/

Die Version 2 dieser API unterstützt auch noch offiziell Windows, z.B
hier:
https://sdlc2b.sun.com/ECom/EComActionServlet;jsessionid=4AD24BB09BD0FFE655861153749C37BF

Getestet mit Version 2 unter Windows XP.

Gruss
Max
Index: Changelog.txt
===================================================================
RCS file: /ctbot/ct-Sim/Changelog.txt,v
retrieving revision 1.11
diff -u -r1.11 Changelog.txt
--- Changelog.txt    28 Apr 2006 13:58:57 -0000    1.11
+++ Changelog.txt    29 Apr 2006 14:53:51 -0000
@@ -1,5 +1,7 @@
CHANGELOG fuer c't-Sim
======================
+2006-04-29 Max Odendahl (maximilian.odendahl@xxxxxxxxxxxxxx) GUI Buttons und Klasse ComConnection hinzugefügt, Verbindung zu realen Bots über seriellen Port möglich
+
2006-04-26 Benjamin Benz (bbe@xxxxxxxx) Anzeige fuer Mauskamerabilder entkaefert

2006-04-26 Benjamin Benz (bbe@xxxxxxxx) Anzeige fuer Mauskamerabilder eingefuehrt
Index: config/ct-sim.xml
===================================================================
RCS file: /ctbot/ct-Sim/config/ct-sim.xml,v
retrieving revision 1.1
diff -u -r1.1 ct-sim.xml
--- config/ct-sim.xml    28 Apr 2006 13:58:56 -0000    1.1
+++ config/ct-sim.xml    29 Apr 2006 14:53:51 -0000
@@ -8,6 +8,8 @@

    <parameter name="parcours" value="parcours/maze.xml"/>
    <parameter name="botport" value="10001"/>
+   +    <SerialBot port="COM13"/>
<bots> <bot name="ctSim.Model.Bots.CtBotSimTest_0">
Index: ctSim/ctSim/JD2xxConnection.java
===================================================================
RCS file: /ctbot/ct-Sim/ctSim/ctSim/JD2xxConnection.java,v
retrieving revision 1.1
diff -u -r1.1 JD2xxConnection.java
--- ctSim/ctSim/JD2xxConnection.java 17 Mar 2006 17:36:13 -0000 1.1
+++ ctSim/ctSim/JD2xxConnection.java    29 Apr 2006 14:53:51 -0000
@@ -1,5 +1,6 @@
package ctSim;

+
import java.io.IOException;

import mindprod.ledatastream.LEDataInputStream;
@@ -10,6 +11,7 @@

    private JD2XX jd = new JD2XX();

+       private int list() throws IOException{
        int count=0;
        Object[] devs= jd.listDevicesByDescription();
@@ -43,7 +45,7 @@
} - /**
+    /*
     * Beendet die laufende Verbindung
     *      * @throws IOException
@@ -62,5 +64,6 @@
        super();
        // TODO Auto-generated constructor stub
    }
+ }
Index: ctSim/ctSim/Controller/Controller.java
===================================================================
RCS file: /ctbot/ct-Sim/ctSim/ctSim/Controller/Controller.java,v
retrieving revision 1.6
diff -u -r1.6 Controller.java
--- ctSim/ctSim/Controller/Controller.java 28 Apr 2006 13:58:57 -0000 1.6
+++ ctSim/ctSim/Controller/Controller.java    29 Apr 2006 14:53:51 -0000
@@ -387,8 +387,37 @@
                System.out.println("Real Bot via JD2XX startet");
            }
        }
+       +
+        if (type.equalsIgnoreCase("CtBotSerial")) {
+            Connection com = waitForSerial();
+            if (com != null) {
+ bot = new CtBotRealCon(this, new Point3f(0.5f, 0f, 0f), new Vector3f(1.0f, -0.5f, 0f), com);
+                }
+        }
+
+                   addBot(bot);
    }
+
+
+        /**
+         * Wartet auf eine eingehende Serial-Verbindung
+         * @author Max Odendahl
+         * @return
+         */
+
+        private Connection waitForSerial(){
+            ComConnection com = new ComConnection();
+            try {
+                com.connect();
+                System.out.println("Serial-Connection aufgebaut");
+                return com;
+            } catch (Exception ex) {
+ ErrorHandler.error("Serial Connection nicht moeglich: " + ex);
+                return null;
+            }
+        }

    /**
     * Wartet auf eine eingehende JD2XX-Verbindung
Index: ctSim/ctSim/View/ControlFrame.java
===================================================================
RCS file: /ctbot/ct-Sim/ctSim/ctSim/View/ControlFrame.java,v
retrieving revision 1.6
diff -u -r1.6 ControlFrame.java
--- ctSim/ctSim/View/ControlFrame.java 28 Apr 2006 13:58:56 -0000 1.6
+++ ctSim/ctSim/View/ControlFrame.java    29 Apr 2006 14:53:52 -0000
@@ -70,6 +70,8 @@
    private JButton addTestBotButton;
        private JButton addJD2XXBotButton;
+   +    private JButton addSerialBotButton;

    private JButton addSimBotButton;

@@ -115,7 +117,7 @@
        Dimension buttDim = new Dimension(100, 50);
               buttonPanel = new JPanel();
-        buttonPanel.setPreferredSize(new Dimension(400,50));
+        buttonPanel.setPreferredSize(new Dimension(500,50));
        BoxLayout panelLayout = new BoxLayout(buttonPanel,
                javax.swing.BoxLayout.X_AXIS);
        this.add(buttonPanel);
@@ -175,6 +177,17 @@
        addJD2XXBotButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                controller.addBot("CtBotRealJD2XX");
+            }
+        });
+       +//         ********* addSerialButton ********************
+        addSerialBotButton = new JButton();
+        addSerialBotButton.setPreferredSize(buttDim);
+        buttonPanel.add(addSerialBotButton);
+        addSerialBotButton.setText("Neuer Serial-Bot");
+        addSerialBotButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent evt) {
+                controller.addBot("CtBotSerial");
            }
        });
       Index: ctSim/ctSim/ComConnection.java
===================================================================
RCS file: ctSim/ctSim/ComConnection.java
diff -N ctSim/ctSim/ComConnection.java
--- /dev/null    1 Jan 1970 00:00:00 -0000
+++ ctSim/ctSim/ComConnection.java    1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,91 @@
+package ctSim;
+
+
+import java.io.IOException;
+import mindprod.ledatastream.LEDataInputStream;
+import mindprod.ledatastream.LEDataOutputStream;
+import javax.comm.*;
+
+
+import com.sun.org.apache.xerces.internal.parsers.DOMParser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Abgeleitete Klasse ComConnection, serielle Verbindung zu realen Bots
+ * @author Maximilian Odendahl (maximilian.odendahl@xxxxxxxxxxxxxx)
+ * + * + */
+public class ComConnection extends Connection {
+      +    SerialPort  port;
+   +    private static final String CONFIGFILE = "config/ct-sim.xml";
+   +    // TODO: probably read out from config hashtable
+    private String GetConfigValue(String AName)
+    {
+        try
+        {
+            DOMParser parser = new DOMParser();
+            parser.parse(CONFIGFILE);
+ + Document doc = parser.getDocument(); + Node n = doc.getDocumentElement().getElementsByTagName("SerialBot").item(0); + return n.getAttributes().getNamedItem(AName).getNodeValue();
+        }
+        catch (Exception ex)
+        {
+            return "";
+        }
+       +           +    }
+ + public void connect() throws IOException,NoSuchPortException,UnsupportedCommOperationException,PortInUseException + {
+            CommPortIdentifier portId;
+
+            try {
+ portId = CommPortIdentifier.getPortIdentifier(GetConfigValue("port"));
+                port = (SerialPort)portId.open("CtSim",2000);
+             +                //TODO: read from config file
+ port.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
+                port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
+                port.enableReceiveTimeout(60000);
+ + setDis(new LEDataInputStream(port.getInputStream())); + setDos(new LEDataOutputStream( port.getOutputStream()));
+           +           +        } catch (IOException ex) {
+            ErrorHandler.error("Error while creating Streams "+ex);
+            throw ex;           +        }
+    }
+
+
+    /**
+     * Beendet die laufende Verbindung
+     * +     * @throws IOException
+     * @throws Exception
+     */
+ public synchronized void disconnect() throws IOException, Exception {
+        super.disconnect();
+        try {
+            port.close();
+        } catch (Exception Ex) {
+            throw Ex;
+        }
+    }   +   +    public ComConnection() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+
+}
------------------------------------------------------------------------

_______________________________________________
ct-bot-entwickler Mailingliste
ct-bot-entwickler@xxxxxxxxxxxxxxxxx
http://www.heise.de/bin/newsletter/listinfo/ct-bot-entwickler


_______________________________________________
ct-bot-entwickler Mailingliste
ct-bot-entwickler@xxxxxxxxxxxxxxxxx
http://www.heise.de/bin/newsletter/listinfo/ct-bot-entwickler






Copyright © 2007 Heise Zeitschriften Verlag Kritik, Anregungen bitte an c't-WWW Datenschutzhinweis   Impressum