Pessoal,
Estou iniciando o trabalho com java e api’s agora estou tentando usar a commapi para listar minhas portas seriais, executei toda a configuração dita no arquivo da Sun, e executo o SerialDemo, porém nenhuma porta é lista, uso o Eclipse e meu arquivo classpath esta assim:
[size=“9”]<?xml version=“1.0” encoding=“UTF-8”?>
<classpath>
<classpathentry kind=“src” path=“src”/> <classpathentry kind=“con” path=“org.eclipse.jdt.launching.JRE_CONTAINER”/>
<classpathentry kind=“lib” path=“C:/j2sdk1.4.2_04/lib/j2ee.jar”/>
<classpathentry kind=“lib” path=“C:/j2sdk1.4.2_04/lib/comm.jar”/>
<classpathentry kind=“output” path=“WEB-INF/classes”/>
</classpath>[/size]
Segue também um trecho do arquivo java SimpleRead que acompanha o pacote, eu coloquei alguns System.out e notei que a linha System.out.println(“passo 02:”); nunca é executada
Peço por favor uma ajuda…
[b]
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
System.out.println("passo 01:" + portList);
while (portList.hasMoreElements()) {
System.out.println("passo 02:");
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (portId.getName().equals("COM1")) {
if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}[/b]
Eu estou com o mesmo problema, utilizando o SerialDemo, com Sistema Operacional windows 98, se vc souber de alguma coisa, me avise.
Eu fiz desse jeito aki ó …
e deu certo …
Esta é a classe responsável por verificar as portas seriais …
[code]
import java.util.Enumeration;
import javax.comm.*;
public class SerialSupport {
public Enumeration listPortChoices() {
CommPortIdentifier portId;
Enumeration en = CommPortIdentifier.getPortIdentifiers();
return en;
}
}[/code]
Mostra em um combo box quais com´s estão disponíveis …
import java.util.Enumeration;
import javax.swing.JFrame;
import javax.comm.*;
import serial.SerialSupport;
//--------------------------------------------------------------------------//
// Autor:Felipe Cunha //
// Data:06/09/2004 //
// //
// controleRemotoView
public class SerialConfig extends JFrame {
static CommPortIdentifier portId;
Enumeration en=null;
SerialSupport serialsupport =new SerialSupport();
private javax.swing.JPanel jContentPane = null;
private javax.swing.JComboBox jComboBox = null;
private javax.swing.JLabel jLabel = null;
/**
* This is the default constructor
*/
public SerialConfig() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(258, 200);
this.setContentPane(getJContentPane());
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJComboBox(), null);
jContentPane.add(getJLabel(), null);
}
return jContentPane;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private javax.swing.JComboBox getJComboBox() {
if(jComboBox == null) {
jComboBox = new javax.swing.JComboBox();
jComboBox.setBounds(32, 61, 146, 19);
en=serialsupport.listPortChoices();
while (en.hasMoreElements()) {
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
jComboBox.addItem(portId.getName());
}
}
}
return jComboBox;
}
/**
* This method initializes jLabel
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getJLabel() {
if(jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setBounds(15, 20, 233, 29);
jLabel.setText("Soh pra debug, mostra a com q está disponível");
}
return jLabel;
}
} // @jve:visual-info decl-index=0 visual-constraint="10,10"