JavaME serielle Kommunikation

Sue

Grünschnabel
Hallo Leute!

Ich bin neu hier und ich bin ein absoluter Newbie in der Programmierung in Java Micro Edition. Allerdings muss ich mich im Zuge meiner Bachelorarbeit damit auseinandersetzen.

Ich habe ein Digitalfunkgerät (EADS/Cassidian TMR880i), auf dem später die Anwendung laufen soll. Ich kommuniziere seriell also über die serielle Schnittstelle.
In dem Programm muss ich zuerst checken welcher Port das Funkgerät nutzt und diesen dann öffnen.
Das habe ich bisher und funktioniert. Allerdings funktioniert es nur, wenn ich die Parameter wie Baudrate & co. NICHT setze. Habt ihr eine Idee wieso****
Als nächstes müsste ich einen Output Stream öffnen und würde gern erstmal ein Hallo rüberschicken, jedoch bekomme ich das nicht hin.
Wenn das funktioniert, soll das Programm die einkommenden Daten einlesen (schätzungsweise Input Stream) und auf dem Display ausgeben.

Allerdings ist mir nicht klar, wie ich mit dem Funkgerät kommunizieren soll. Wenn ich das Gerät am PC angeschlossen habe (seriell) und das Programm läuft auf dem Gerät, dann müsste ich im PC ein Terminalprogramm wie TeraTerm oder Hyperterminal öffnen und z.B. die Ausgabe Hallo vom Output Stream erhalten bzw. Daten senden können, nicht wahr? Allerdings wird mir immer angezeigt, dass er Port schon besetzt ist, ich aber sicher weiß, dass das der richtige Port ist. Hab ich irgendwie einen Denkfehler?

Und hat jemand eventuell ein Stück Code für den Out-/Input Stream?

Code:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
 
public class HelloWorld extends MIDlet implements CommandListener
{
        private final Command exitCommand = new Command("Exit", Command.EXIT, 1);
        private final Command openCommand = new Command("Open", Command.OK, 3);
        private final Command portsCommand = new Command("Ports", Command.OK, 1);
        private StreamConnection serialConnection = null;
        private final TextBox textBox = new TextBox("Hello World", "Hello World!", 25, TextField.ANY);
       
    public HelloWorld()
    {
        textBox.addCommand(exitCommand);
        textBox.addCommand(openCommand);
        textBox.addCommand(portsCommand);
        textBox.setCommandListener(this);
    }
 
    private void close()
    {
        textBox.setString("in close");
 
        try
        {
            serialConnection.close();
            serialConnection = null;
        }
        catch (final IOException ioException)
        {
        }
    }
 
    public void commandAction(final Command command, final Displayable displayable)
    {
        if (command == exitCommand)
        {
            destroyApp(false);
            notifyDestroyed();
        }
 
        if (command == openCommand)
        {
            open();
        }
 
        if (command == portsCommand)
        {
            getPorts();
        }
 
    }
 
    protected void destroyApp(final boolean unconditional)
    {
        close();
    }
 
    private void getPorts()
    {
        textBox.setString("Port: " + System.getProperty("microedition.commports"));
    }
 
    private void open()
    {
        textBox.setString("open");
 
        try
        {
            CommConnection cc= (CommConnection)Connector.open("comm:COM0"); //hier sollte noch baudrate=9600;bitsperchar=8;stopbits=1;parity=none;blocking=off stehen
            textBox.setString("Success");
        }
        catch (final IOException ioException)
        {
            textBox.setString("Failure" + ioException);
        }
 
    }
 
    protected void pauseApp()
    {
    }
 
    protected void startApp()
    {
        Display.getDisplay(this).setCurrent(textBox);
        textBox.setString("Hello World...");
    }
 
//fehlt Code für den Out-/Input Stream
}

Danke für eure Hilfe!!

Liebe Grüße
Sue
 

Neue Beiträge

Zurück