有一个要完成的任务:
用Swing开发一个窗口在linux系统上运行,linux系统通过串口与一个IC读写器连接.在IC读写器上插入IC卡时,IC卡的信息能在窗口上显示,同时通过这个窗口也能将信息写到IC卡上.
请问谁有过这方面的经验,告诉我应该从哪里着手?
如果需要,我会提供更具体的情况说明.
有一个要完成的任务:
用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.*;
/**
*
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;
/**
/**
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;
}
/**
*
/**
*
/**
*
[/code]