Results 1 to 10 of 10
Thread: Serial Communication
- 02-29-2012, 04:56 PM #1
Member
- Join Date
- Feb 2012
- Location
- Bruges, BELGIUM
- Posts
- 16
- Rep Power
- 0
Serial Communication
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?
Java 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 }
- 02-29-2012, 05:14 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
Re: Serial Communication
You need to print out each element of the enumeration, as that class doesn't have its own toString() (which is what println calls for non-Strings), resulting in it using the toString() of Object.
Please do not ask for code as refusal often offends.
- 02-29-2012, 05:23 PM #3
Member
- Join Date
- Feb 2012
- Location
- Bruges, BELGIUM
- Posts
- 16
- Rep Power
- 0
Re: Serial Communication
OK, but the real problem is that nothing is added in the ComboBox using this part of the code:
Java Code:private void OK_Button_SerialActionPerformed(java.awt.event.ActionEvent evt) { Enumeration portList=CommPortIdentifier.getPortIdentifiers(); while(portList.hasMoreElements()){ CommPortIdentifier cpi= (CommPortIdentifier)portList.nextElement(); map.put(cpi.getName(), cpi); ComboBox_Serial.addItem(cpi.getName()); } }
-
Re: Serial Communication
Time to do some debugging. If you add System.out.println(...) statements to that method, do the elements get extracted and do their names make sense? If you change that method to simply add Strings from an array into the combo box, does it work?
- 02-29-2012, 05:32 PM #5
Member
- Join Date
- Feb 2012
- Location
- Bruges, BELGIUM
- Posts
- 16
- Rep Power
- 0
- 02-29-2012, 05:35 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Serial Communication
Most likely it's an incorrect installation of that comm package. It surprises me that it still can be downloaded (unless it's for a Linux/Unix box) because it was discontinued for MS Windows boxes.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-02-2012, 12:26 PM #7
Member
- Join Date
- Feb 2012
- Location
- Bruges, BELGIUM
- Posts
- 16
- Rep Power
- 0
Re: Serial Communication
Ok then,
Can anyone suggest me a better library then?
- 03-02-2012, 01:57 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Serial Communication
Google for RXTX, it's a clone of the javacomm package (identical API).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-05-2012, 11:29 PM #9
Member
- Join Date
- Feb 2012
- Location
- Bruges, BELGIUM
- Posts
- 16
- Rep Power
- 0
- 03-06-2012, 07:07 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Serial Communication
Good to read you succeeded. Those RS/232 ports are quite a problem because Microsoft keeps on changing their driver APIs, that Sun javaxcomm package was released without any JSR and RS/232 is not as obsolete as they want to make us believe (usb otoh is a problem too with Java ;-)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Help with USB/Serial communication
By Blackmore in forum Advanced JavaReplies: 0Last Post: 08-16-2011, 08:45 PM -
Serial communication via ethernet-serial hub
By Idiodyssey in forum New To JavaReplies: 0Last Post: 05-04-2011, 02:23 PM -
Serial port Communication Problem
By rjagan in forum New To JavaReplies: 8Last Post: 04-20-2011, 12:36 PM -
serial communication is very slow while reading from serial port
By elsanthosh in forum AWT / SwingReplies: 1Last Post: 07-30-2010, 08:29 AM -
serial port communication in java
By elsanthosh in forum New To JavaReplies: 2Last Post: 04-06-2010, 06:33 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks