473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Why do the outputs differ when I run this code using NetBeans 6.8 and Eclipse?

108 100+
When I am running the following code using Eclipse and NetBeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COM ports but when running it in NetBeans, it does not seem to find any ports ..

public static void test(){
Enumeration lists=CommPortIdentifier.getPortIdentifiers();

System.out.println(lists.hasMoreElements());
while (lists.hasMoreElements()) {
CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType() )) {
System.out.println(
"Name is serail portzzzz " +
cn.getName() +
" Owned status " +
cn.isCurrentlyOwned());

try{
SerialPort port1=(SerialPort)cn.open("ComControl",800000);
port1.setSerialPortParams(
9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
System.out.println("Before get stream");
OutputStream out=port1.getOutputStream();
InputStream input=port1.getInputStream();
System.out.println("Before write");
out.write("AT".getBytes());
System.out.println("After write");
int sample=0;
//while((( sample=input.read())!=-1)){
System.out.println("Before read");
//System.out.println(input.read() + "TEsting ");
//}
System.out.println("After read");
System.out.println("Receive timeout is "+port1.getReceiveTimeout());
}
catch(Exception e) {
System.err.println(e.getMessage());
}
}
else {
System.out.println(
"Name is parallel portzzzz " +
cn.getName() +
" Owned status " +
cn.isCurrentlyOwned() +
cn.getPortType()+" ");
}
}
}

Output with Netbeans,

false

Output using Eclipse,

true
Name is serail portzzzz COM1 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail portzzzz COM2 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is parallel portzzzz LPT1 Owned status false2
Name is parallel portzzzz LPT2 Owned status false2
Dec 29 '10 #1
5 1701
Dheeraj Joshi
1,123 Expert 1GB
Please do not double post the question.

Are you using external Java or the Java bundled with the IDE's?

Regards
Dheeraj Joshi
Dec 30 '10 #2
phpuser123
108 100+
I am using an external java bundle..
Do you think that's what making the problem?
I tried finding the java bundle in the IDE but could n't find it.
Dec 30 '10 #3
phpuser123
108 100+
I am using an external java bundle..
Do you think that's what making the problem?
I tried finding the java bundle in the IDE but could n't find it.
Dec 30 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
Not sure what may be the issue. If you post the whole code we can try to execute it and figure out the problem.

Regards
Dheeraj Joshi
Dec 30 '10 #5
phpuser123
108 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4. import javax.comm.*;
  5.  
  6. public class SMS {
  7.  
  8.  
  9.     public static void main(String[] args) {
  10.         Enumeration lists=CommPortIdentifier.getPortIdentifiers();
  11.         System.out.println(CommPortIdentifier.PORT_SERIAL);
  12.         System.out.println(lists.hasMoreElements());
  13.         while (lists.hasMoreElements()){
  14.             CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();
  15.  
  16.             if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())){
  17.                 System.out.println("Name is serail portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned());
  18.  
  19.                 try{
  20.                     SerialPort port1=(SerialPort)cn.open("ComControl",800000);
  21.                     port1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
  22.                     //System.out.println("Before get stream");
  23.                     OutputStream out=port1.getOutputStream();
  24.                     InputStream input=port1.getInputStream();
  25.                     System.out.println(input.available());
  26.  
  27.                     //System.out.println("Before write");
  28.                     out.write("AT".getBytes());
  29.                     //System.out.println("After write");
  30.                     int sample=0;
  31.                     //while((( sample=input.read())!=-1)){
  32.                     //System.out.println("Before read");
  33.                         //System.out.println(input.read() + "TEsting ");
  34.                     //}
  35.                         //System.out.println("After read");
  36.                     //System.out.println("Receive timeout is "+port1.getReceiveTimeout());
  37.                 }catch(Exception e){
  38.                     System.err.println(e.getMessage());
  39.                 }
  40.             }
  41.  
  42.             else{
  43.                 System.out.println("Name is parallel portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned()+cn.getPortType()+"    ");
  44.             }
  45.         }
  46.     }
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
Here is the whole code..
Dec 30 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eduardo Hercos Rodrigues | last post by:
Hi, How to print directly from PHP code using CUPS? Thanks, "Eduardo Hercos Rodrigues"
2
by: Umpty | last post by:
Trying to use Microsoft Indexing Service. Here is my code using SQL Query Analyzer, which works perfectly. SELECT * FROM OPENQUERY(FileSystem, 'SELECT RANK, FileName, Characterization FROM...
1
by: Chaitanya | last post by:
please tell me ,the tld files like struts-bean.tld, struts-html.tld, struts-logic.tld are generated automatically or done by ourselves using Netbeans. As they are automatically generated in...
0
by: ApexData | last post by:
I have a Split Database. FE / BE. It has been working fine, on a server for months. The BE exists in a secure folder used by 5 users who have full rights to the application. A number of other...
1
myusernotyours
by: myusernotyours | last post by:
hi all, Am building an desktop app that needs to access a mysql database and am using netbeans 6 can someone direct me to a good tutorial that shows how this can be done?
0
by: =?Utf-8?B?S2luZXRpYyBKdW1wIEFwcGxpZmUgZm9yIC5ORVQg | last post by:
Refactor .NET code using Visual Studio and Refactor! Pro Modifying the existing source code without changing its functionality is called refactoring of Source Code. Visual Studio gives us a lots of...
1
atksamy
by: atksamy | last post by:
Hi, I have a form with a few buttons which execute code when pressed like running validations on the database. some of these code could could run for a few minutes so is there any way to show the...
0
by: arahmoun | last post by:
I am developing a Dbase application in a mobile environment using NetBeans. I created tables that cannot be displayed. I am also using MySql for Data connect. Please tell me how to make these tables...
0
by: phpuser123 | last post by:
When I am running the following codes using Eclipse and Netbeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COm ports but...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.