This is the first time I have ever tried Serial Communication in Java and I ran into a problem. The idea is that all available COM ports are added in the ComboBox.
I have added the comm.jar folder in the libraries. The problem is that nothing is added in the ComboBox. When I add "System.out.println(""+portList);". This is what I get "javax.comm.CommPortEnumerator@81572f".
What am I doing wrong?
Code:package sercomsolar;
/* @author F.S */
import java.io.*;
import javax.comm.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class PortSelect extends javax.swing.JFrame {
protected HashMap map = new HashMap();
protected String selectPort;
protected CommPortIdentifier selectedCOMPort;
public PortSelect() {
initComponents();
}
@SuppressWarnings("unchecked")
//...
private void OK_Button_SerialActionPerformed(java.awt.event.ActionEvent evt) {
Enumeration portList=CommPortIdentifier.getPortIdentifiers();
System.out.println(":" + portList);
while(portList.hasMoreElements()){
CommPortIdentifier cpi= (CommPortIdentifier)portList.nextElement();
map.put(cpi.getName(), cpi);
ComboBox_Serial.addItem(cpi.getName());
}
}
public static void main(String args[]) {
//...
}
// Variables declaration - do not modify
private javax.swing.JComboBox ComboBox_Serial;
private javax.swing.JLabel Label_Serial;
private javax.swing.JButton OK_Button_Serial;
// End of variables declaration
}

