Forum: Mikrocontroller und Digitale Elektronik Java String per RX TX senden


von Matthias T. (matthias95689)


Lesenswert?

Hi ich habe eine Gui für meine Diplomarbeit geschrieben jetzt muss ich 
den String der durch Textfelder erzeugt wird senden. Ich will per Rs232 
die Daten auf ein anderes Gerät senden. Mein Problem ist, dass es immer 
einen Error beim CommportIdentifier gibt bitte umhilfe.

Quellcode:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener.*;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import gnu.io.*;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.PrintWriter;

public class gridlay extends JFrame implements ActionListener

{
   static CommPortIdentifier portID;
   InputStream ins;
   OutputStream out;
   static SerialPort serss;

   String s1,s2,s3,s4,s5,s6,s7,s8,s9,s01,s02,s03,s04,s05,s06,s07,s08,su;
   int a = 2 ;

   private JComponent conPane;
   private JLabel f1 = new JLabel("Fach1");
   private JLabel f2 = new JLabel("Fach2");
   private JLabel f3 = new JLabel("Fach3");
   private JLabel f4 = new JLabel("Fach4");

   private JTextField f01 = new JTextField("");
   private JTextField f02 = new JTextField("");
   private JTextField f03 = new JTextField("");
   private JTextField f04 = new JTextField("");

   private JLabel f5 = new JLabel("Fach5");
   private JLabel f6 = new JLabel("Fach6");
   private JLabel f7 = new JLabel("Fach7");
   private JLabel f8 = new JLabel("Fach8");

   private JTextField f05 = new JTextField("");
   private JTextField f06 = new JTextField("");
   private JTextField f07 = new JTextField("");
   private JTextField f08 = new JTextField("");

   private JButton bse = new JButton("Starten");
   private JButton bsa = new JButton("Stoppen");
   private JLabel start = new JLabel("Gestoppt");
   private JButton bze = new JButton("Zufall ein");
   private JButton bza = new JButton("Zufall aus");
   private JLabel zufall = new JLabel("Aus");
   private JLabel test = new JLabel ("");


   public gridlay()
   {

      try {ins = serss.getInputStream();
         out = serss.getOutputStream();
         serss.addEventListener(new commListener());
    }
    catch (Exception e) { System.out.println("Fehler: "+e);}
    serss.notifyOnDataAvailable(true);
    try {serss.setSerialPortParams(9600,
                                   SerialPort.DATABITS_8,
                                   SerialPort.STOPBITS_1 ,
                                   SerialPort.PARITY_NONE);}
    catch (UnsupportedCommOperationException e) {}

      conPane = (JComponent)this.getContentPane();
      conPane.setToolTipText("ContentPane");
      FlowLayout fenster = new FlowLayout();
      fenster.setHgap(10);
      fenster.setVgap(20);
      conPane.setLayout(fenster);

      f1.setBackground( Color.cyan );
      f1.setPreferredSize( new Dimension(60,20) ) ;
      f1.setAlignmentX(Label.CENTER);
      conPane.add(f1);
      f2.setBackground( Color.cyan );
      f2.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f2);
      f3.setBackground( Color.cyan );
      f3.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f3);
      f4.setBackground( Color.cyan );
      f4.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f4);

      f01.setBackground( Color.white );
      f01.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f01);
      f02.setBackground( Color.white );
      f02.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f02);
      f03.setBackground( Color.white );
      f03.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f03);
      f04.setBackground( Color.white );
      f04.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f04);

      f5.setBackground( Color.yellow );
      f5.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f5);
      f6.setBackground( Color.cyan );
      f6.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f6);
      f7.setBackground( Color.cyan );
      f7.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f7);
      f8.setBackground( Color.cyan );
      f8.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f8);

      f05.setBackground( Color.white );
      f05.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f05);
      f06.setBackground( Color.white );
      f06.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f06);
      f07.setBackground( Color.white );
      f07.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f07);
      f08.setBackground( Color.white );
      f08.setPreferredSize( new Dimension(60,20) ) ;
      conPane.add(f08);


      bse.setBackground( Color.cyan );
      bse.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(bse);

      bsa.setBackground( Color.yellow );
      bsa.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(bsa, BorderLayout.NORTH);

      start.setBackground( Color.yellow );
      start.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(start, BorderLayout.NORTH);

      bze.setBackground( Color.green );
      bze.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(bze, BorderLayout.EAST);

      bza.setBackground( Color.green );
      bza.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(bza, BorderLayout.EAST);

      zufall.setBackground( Color.yellow );
      zufall.setPreferredSize( new Dimension(80,20) ) ;
      conPane.add(zufall, BorderLayout.NORTH);

      test.setBackground( Color.yellow );
      test.setPreferredSize( new Dimension(200,20) ) ;
      conPane.add(test, BorderLayout.NORTH);

        bze.addActionListener(this);
        bza.addActionListener(this);
        bse.addActionListener(this);
        bsa.addActionListener(this);


      initFrame() ;


   }

   void bzein()
    {
       a = 0;
       zufall.setText("Ein");


    }
    void bzaus()
    {
       a = 1;
       zufall.setText("Aus");

    }
    void bsein()
    {
        s1 = f01.getText();
        s2 = f02.getText();
        s3 = f03.getText();
        s4 = f04.getText();
        s5 = f05.getText();
        s6 = f06.getText();
        s7 = f07.getText();
        s8 = f08.getText();

        s01 = ("$F1")+s1+("#");
        s02 = ("$F2")+s2+("#");
        s03 = ("$F3")+s3+("#");
        s04 = ("$F4")+s4+("#");
        s05 = ("$F5")+s5+("#");
        s06 = ("$F6")+s6+("#");
        s07 = ("$F7")+s7+("#");
        s08 = ("$F8")+s8+("#");

        su = s01+s02+s03+s04+s05+s06+s07+s08;

        test.setText(su);
        start.setText("Gestartet");




    }
    void bsaus()
    {
        start.setText("Gestoppt");
        //test.setText("ABC");
    }



    private void initFrame()
   {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
      setLocation(250,150) ;
      setSize(300,350);
      setTitle("    Enrichmentsystem");
      setVisible(true);
   }
    /*public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == bze) bzein();
        else if (e.getSource()== bza) bzaus();

        if (e.getSource() == bse) bsein();
        else if (e.getSource()== bsa) bsaus();






    }*/
    public static void main(String[] args)
    {
        try
        {
            portID = CommPortIdentifier.getPortIdentifier("COM14");
            serss = (SerialPort) portID.open("mein_programm",2000);

        }

        catch(Exception exc)
        {
            System.out.println("Fehler :"+exc);
        }

        //gridlay a = new gridlay();
        //WindowListener w = new WindowAdapter()
        //{
        //    public void windowClosing(WindowEvent e)
        //    {
        //        System.exit(0);
        //    }
        //};
    }


    public void actionPerformed(ActionEvent ae) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    public class sendeListener implements ActionListener

    {

    public void actionPerformed(ActionEvent e)

    {

      if (e.getSource() == bze) bzein();
      else if (e.getSource()== bza) bzaus();

      if (e.getSource() == bse) bsein();
      else if (e.getSource()== bsa) bsaus();

      PrintWriter aus = new PrintWriter(out);
      aus.println(su);
      //aus.flush();
      //aus.close();
      su = su + a;
      System.out.println(su);

    }
  }

  public class commListener implements SerialPortEventListener
  {
    public void serialEvent(SerialPortEvent event)
    {
      if(event.getEventType()==SerialPortEvent.DATA_AVAILABLE)
      {
        byte[] readBuffer = new byte[20];
        try
        {
          while (ins.available() > 0) {int numBytes = 
ins.read(readBuffer);}
          String nachricht = new String(readBuffer);

        }
        catch (IOException e)
        {
            System.out.println("Fehler: "+e);
        }
      }
    }
  }
}


Wenn ich dieses Programm ausführe kommt immer diese Fehlermeldung:
java.lang.UnsatisfiedLinkError: 
/Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found. 
Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching 
architecture in universal wrapper thrown while loading 
gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: 
/Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found. 
Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching 
architecture in universal wrapper
  at java.lang.ClassLoader$NativeLibrary.load(Native Method)
  at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1716)
  at java.lang.Runtime.loadLibrary0(Runtime.java:823)
  at java.lang.System.loadLibrary(System.java:1045)
  at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
  at gridlay.main(gridlay.java:247)
Java Result: 1

von Hanno (Gast)


Lesenswert?

"librxtxSerial.jnilib: no matching architecture in universal wrapper"

Bist du sicher, dass du die passende native Lib für deine CPU und dein 
OS installiert hast?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.