求解决方案 - 涉及到串口设备的问题

有一个要完成的任务:

用Swing开发一个窗口在linux系统上运行,linux系统通过串口与一个IC读写器连接.在IC读写器上插入IC卡时,IC卡的信息能在窗口上显示,同时通过这个窗口也能将信息写到IC卡上.

请问谁有过这方面的经验,告诉我应该从哪里着手?

如果需要,我会提供更具体的情况说明.

使用SUN公司有提供一个java的串口开发包[color=red]comm.jar[/color]下面提供一段读写串口的代码,可以参考下:
[code="java"]
package serial;
import java.io.*;
import javax.comm.*;
/**
*

  • This bean provides some basic functions to implement full dulplex
  • information exchange through the srial port.
    *
    */
    public class SerialBean{

    /* PortName="COM1","COM2" etc. */
    String PortName;

    CommPortIdentifier portId;
    SerialPort serialPort;
    static OutputStream out;
    static InputStream in;
    SerialBuffer serialBuffer;
    ReadSerialThread readSerialThread;
    /**

    • Constructor
    • @param PortID the ID of the serial to be used. 1 for COM1,
    • 2 for COM2, etc. */ public SerialBean(String PortName){ this.PortName = PortName; }

    /**

    • This function initialize the serial port for communication. It startss a
    • thread which consistently monitors the serial port. Any signal capturred
    • from the serial port is stored into a buffer area.
      *
      */
      public int Initialize(){
      final int InitSuccess = 1;
      final int InitFail = -1;
      try{
      portId = CommPortIdentifier.getPortIdentifier(PortName);
      try{
      serialPort = (SerialPort)

          //timeout = 2000mis
          portId.open("Serial_Communication", 2000);
      } catch (PortInUseException e){
              return InitFail;
      }
      
      //Use InputStream in to read from the serial port, and OutputStream
      //out to write to the serial port.
      try{
          in  = serialPort.getInputStream();
          out = serialPort.getOutputStream();
      } catch (IOException e){
          return InitFail;
      }
      
      //Initialize the communication parameters to 9600, 8, 1, none.
      try{
          serialPort.setSerialPortParams(9600,
                      SerialPort.DATABITS_8,
                      SerialPort.STOPBITS_1,
                      SerialPort.PARITY_NONE);
      } catch (UnsupportedCommOperationException e){
          return InitFail;
      }
      

      } catch (NoSuchPortException e){
      return InitFail;
      }

      // when successfully open the serial port, create a new serial buffer,
      // then create a thread that consistently accepts incoming signals from
      // the serial port. Incoming signals are stored in the serial buffer.
      serialBuffer = new SerialBuffer();
      readSerialThread = new ReadSerialThread(serialBuffer, in);
      readSerialThread.start();

      // return success information
      return InitSuccess;
      }

    /**
    *

    • This function returns a string with a certain length from the incomin
    • messages. *
    • @param Length The length of the string to be returned. * */ public String ReadPort(int Length){ String Msg; Msg = serialBuffer.GetMsg(Length); return Msg; }

    /**
    *

    • This function sends a message through the serial port. *
    • @param Msg The string to be sent. * */ public void WritePort(String Msg){ try{ for (int i = 0; i < Msg.length(); i++) out.write(Msg.charAt(i)); } catch (IOException e) {} }

    /**
    *

    • This function closes the serial port in use. * / public void ClosePort(){ /如何正常关闭线程?*/ //readSerial.stop(); serialPort.close(); } }

[/code]