RE:Serial communication using java

Hello,
First of all, I want to make clear thatI did not double post it as previously I posted it in Networking section..But I was told that I have not posted it at appropirate place....thats wht I am posting here.
I am a newbie in Java.I have started with Netbeans.I have designed a interface using Netbeans.It has 5 texboxes and two buttons named "Start" and "Stop".
I want to receive data from the serial port and display the data in text boxes.I want when I press Start button, then it should start listening to the serial port .If adat is present on serial port, then it must receive it and displayin the text boxes.when I press Stop button, then it should stop receiving data as well close connection.
can please anyone help me on this?
I would be highly thankful for this.
Regards,
Jass

Hello All,
I am using the javax.comm for serial communication using serial to usb converter at port COM4(I check using device manager.).Beside that I have also added the option in the programming to look into other COMs also.I have placed "comm.jar " and "javax.properties" into jdk\lib\ext and "win32.dll" into jdk\bin.
But I am getting the following output:
Wed Dec 24 02:23:43 EST 2008: COM4 null
Serial port List is  javax.comm.CommPortEnumerator@1a46e30
Serial port ID  is null
BUILD SUCCESSFUL (total time: 0 seconds)
The code Is as follows:
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.*;
import java.util.*;
public class serialport implements Runnable, SerialPortEventListener
    static CommPortIdentifier portId, portId1;
    public SerialPort serialPort;
    public OutputStream outputStream;
    public InputStream inputStream;
    Thread readThread;
    static Enumeration portList;
     static String TimeStamp;
    public static void main(String args[])     
    {try {
          portId1 = CommPortIdentifier.getPortIdentifier("COM4");
          }catch(Exception e) {
      TimeStamp = new java.util.Date().toString();
      System.out.println(TimeStamp + ": COM4 " + portId1);}
           portList = CommPortIdentifier.getPortIdentifiers();
           System.out.println("Serial port List is  "+portList+"\n");
           portId = (CommPortIdentifier) portList.nextElement();
          System.out.println("Serial port ID  is "+portId+"\n");
       while (portList.hasMoreElements()) {
          portId = (CommPortIdentifier) portList.nextElement();
          if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            if (portId.getName().equals("COM3")) {
                 System.out.println("Serial port COM3 is found\n");
            serialport Port = new serialport();
            else if (portId.getName().equals("COM4")) {
                 System.out.println("Serial port COM4 is found\n");
            serialport Port = new serialport();
            else if (portId.getName().equals("COM6")) {
                 System.out.println("Serial port COM6 is found\n");
            serialport Port = new serialport();
            else if (portId.getName().equals("COM7")) {
                 System.out.println("Serial port COM7 is found\n");
            serialport Port = new serialport();
            else if (portId.getName().equals("COM5")) {
                 System.out.println("Serial port COM8 is found\n");
            serialport Port = new serialport();
  public serialport()
    try {
      serialPort = (SerialPort) portId.open("MainClassApp", 2000);
    } catch (PortInUseException e) {
              System.out.println("Port is owned by another application \nor port cannot be opened\n");
    try {
      inputStream = serialPort.getInputStream();
    } catch (IOException e) {
         System.out.println("IOstream for port is not available\n");}
    try {
      serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {
         System.out.println("Serial port is not properly configured\n");}
    try {
      serialPort.addEventListener(this);
    } catch (TooManyListenersException e) {
         e.printStackTrace();}
    serialPort.notifyOnDataAvailable(true);
    readThread = new Thread(this);
    readThread.start();
    public void run() {
       try {
         Thread.sleep(2000);
           } catch (InterruptedException e) {      e.printStackTrace();}
    public void serialEvent(SerialPortEvent event) {
         Runtime rt = Runtime.getRuntime() ;
         Process p;
    switch (event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
      break;
    case SerialPortEvent.DATA_AVAILABLE:
      byte[] readBuffer = new byte[1];
      try {
        while (inputStream.available() > 0)
               int numBytes = inputStream.read(readBuffer);
               System.out.print(new String(readBuffer));
                break;
        System.out.print(new String(readBuffer));
            } catch (Exception e) {
           e.printStackTrace();}
      break;}  }  }Kindly help........I really wanna to know where is the error???
Thanks
Edited by: jass11 on Dec 23, 2008 11:39 PM
Edited by: jass11 on Dec 23, 2008 11:51 PM

Similar Messages

  • How to read HardDisk Serial number using java

    In my project the requirement is how to read the hard dish serial number using java library. Please do let me now if u get any help or any information regarding this issue. This is urgent for me

    In my project the requirement is how to read the hard
    dish serial number using java library. Please do let
    me now if u get any help or any information regarding
    this issue. This is urgent for meThat's a pretty goofy 'requirement' for a Java application, which is supposedly meant to do platform-independent things, to do something very platform-specific that it has no business doing in the first place.

  • Serial Communication In JAVA

    Hi.
    I just wanted to know if serial communication is possible using java. If yes, which are the classes used.
    Thank you.

    I have found javax.comm for Linux and Solaris but not for Windows can any body help me about it .
    How can I comunicate using rs232 two computers using Java in Windows.
    Tkns
    I

  • Problems with Serial Communication using Labview 6 and Solaris 8

    I am working on a Driver for a Temperature Controller. But I am stuck at the very basics. I am using Labview 6 and the platform is Solaris 8 on a SUN Ultra 60 Workstation. I can not get the Serial communication to work. When I am running raw (uncompiled) code it works (I can read from and write to ttya and ttyb) but once compiled I get error code 37 (device not found). I have tried the following steps to fix this with no luck.
    1) I made sure that the "serpdrv" file is in the same folder with the executable. I also make sure the serpdrv file is added as a support file when building the app.
    2) I changed from using traditional serial VI's to labview 6's new visa functions. With these "new" VI's when
    I try to initiliaze the visa device and wire a control to the "visa reference" input only 1 serial port shows up (ASRL2, missing ASRL1). I am not sure if this is part of same problem or whole new issue.
    3) I reinstalled both visa and labview 6.0.2 update hoping this would help with no luck
    4) I placed the following entry into the ".labviewrc" file
    labview.serialdevices: "/dev/ttya:/dev/ttyb"
    If anybody has had the same problem I would love to hear about it and if you have any solutions
    Jamie Shea

    Hi Jamie,
    1. Do you have NI-VISA driver installed on the machine on which you are running this executable?? If you are trying to run the executable on the same machine on which the development program has ran fine, then you can ignore this point.
    2. If you have done all the changes that are suggested by other discussions related to this topic, then try changing the Port input to Visa Serial Configure.Vi from a control to a constant and try it. In some case, I have seen this to do the trick. I think this point should solve your problem. If it does do tell me. :-))

  • I was unable to establish a serial communication using a DLL library file

    i had designed a VI application in Labview7.1, now i had upgraded Labview to 8.5 but my application is not responding. The design includes
    Application: I am trying to access a third party controller, through serial communication(RS232 Cable). I am configuring the serial port using a third party DLL library file using call library function block. but i cannot get the starting reciever response.

    hi santosh,
                       i cant get u, How do i check whether the dll is activex dll or not. else i do have an activex dll. Mouse, keyboard are USB connected. no other serial communication is connected to it. I am geting 2 errors when i tried to register the file
                         1. DLL server point not found          --    sometimes
                         2. The module was not found        -- sometimes
                  One more thing is i am able to get the reciever status for the first time but was unable to connect for the consequtive bit/byte loadings. to the third party controller connected at the other end.

  • How to generate Serial numbers using JAVA SCRIPT

    how to generate serial numbers(incrementing by 1) using JAVA SCRIPT
    thanking you,
    pola pradeep

    i am afraid that whether ur looking for this. bcoz its a simple for loop
    <script language="JavaScript">
    //count = limit value for u
    for(i=0;i<count;++i){
         alert(i);
    </script>
    or if ur looking for something else, pls mention ur requrment precisely
    aleena

  • Arduino due and Labview wirelss serial communication using Xbee

    Hello.
    I am controlling a mobile robot using the Arduino due and labview
    PWM value caculated on the labview is sent to Arduino due and then Due controls the robot.
    These communicate wirelessly by xbee.
    Now, I'd like to increase the communication speed between Arduino due and Labview.
    but, when i set the value of the "Wait(ms)" function to below 10ms  in Labview, communication has unstability.
    so please let me know how increase the communication speed.
    thank you.
    -experiment image-
    https://www.youtube.com/watch?v=oZdMCdHlDhM
    - Arduino source-
    #include <string.h>
    int PWM1 = 5;
    int DIR1 = 4; //direc
    int PWM2 = 6;
    int DIR2 = 7; //dir
    float readNumber = 0;
    float In1, In2, pwm, newtime, A;
    float newposition1 = 0;
    float newposition2 = 0;
    unsigned int Aold1 = 0;
    unsigned int Bnew1 = 0;
    unsigned int Aold2 = 0;
    unsigned int Bnew2 = 0;
    volatile long encoder1Pos = 0;
    volatile long encoder2Pos = 0;
    int encoder1PinA = 8;//Encoder A pin
    int encoder1PinB = 9;//Encoder B pin
    int encoder2PinA = 11;//Encoder A pin
    int encoder2PinB = 12;//Encoder B pin
    int Direction1, Direction2;
    float pwm1_limit=255;
    float pwm2_limit=255;
    float count_old = 0;
    float power1_old, power1_old2, power1_old3, power1_old4, power1_old5;
    void setup() {
    // put your setup code here, to run once:
    pinMode(DIR1, OUTPUT);
    pinMode(DIR2, OUTPUT);
    Serial.begin(115200);
    Serial.flush();
    Serial2.begin(115200);
    Serial2.flush();
    pinMode(encoder1PinA, INPUT);
    digitalWrite(encoder1PinA, HIGH); // turn on pullup resistor
    pinMode(encoder1PinB, INPUT);
    digitalWrite(encoder1PinB, HIGH); // turn on pullup resistor
    pinMode(encoder2PinA, INPUT);
    digitalWrite(encoder2PinA, HIGH); // turn on pullup resistor
    pinMode(encoder2PinB, INPUT);
    digitalWrite(encoder2PinB, HIGH); // turn on pullup resistor
    attachInterrupt(encoder1PinA, d1EncoderA, CHANGE);
    attachInterrupt(encoder1PinB, d1EncoderB, CHANGE);
    attachInterrupt(encoder2PinA, d2EncoderA, CHANGE);
    attachInterrupt(encoder2PinB, d2EncoderB, CHANGE);
    void loop() {
    if(Serial2.available()>0){
    String first = Serial2.readStringUntil('!');//랩뷰에서 받는 2개의 값을 분리하기 위한 소스("!"앞까지 끊고, "@"앞까지 끊음 ex)123!456@을 받으면 123과 456으로 나눔)
    String second = Serial2.readStringUntil('@');//http://stackoverflow.com/questions/29504679/splitting-a-comma-separated-string-through-serial-arduino
    float x = first.toFloat();//위에서 분리된 문자를 float형으로 바꿔줌
    float y = second.toFloat();
    newposition1 = -encoder1Pos; //Encoder signal
    newposition2 = encoder2Pos; //Encoder signal
    count_old = 0;
    float power1 = x;
    float power2 = y;
    if(power1 >= 0){
    Direction1 = LOW;
    else{
    Direction1 = HIGH;
    if(power2 >= 0){
    Direction2 = HIGH;
    else {
    Direction2 = LOW;
    power1 = abs(power1);
    power2 = abs(power2);
    if(power1 > pwm1_limit){
    power1 = pwm1_limit;
    if(power2 > pwm2_limit){
    power2 = pwm2_limit;
    digitalWrite(DIR1, Direction1); //HIGH = back, LOW = forward
    digitalWrite(DIR2, Direction2); //HIGH = back, LOW = forward
    analogWrite(PWM1, power1);//PWM Speed Control
    analogWrite(PWM2, power2);//PWM Speed Control
    String strValue = String(newposition1);//숫자를 문자형으로 변환
    String Q = "!";
    String strValue2 = String(newposition2);
    String stringThree = strValue + Q + strValue2;//문자 합치기
    Serial2.println(stringThree);//Send encoder pulse to Labview
    else {//when Serial communication stop
    float count = count_old+1;
    if(count > 10000){
    newposition1 = 0; //Encoder initialization
    newposition2 = 0; //Encoder initialization
    encoder1Pos = 0;
    encoder2Pos = 0;
    else{
    newposition1 = newposition1; //Encoder signal
    newposition2 = newposition2; //Encoder signal
    count_old = count;
    Serial.println(count);
    //Encoder Read//////////////////////////////////////////////////////////
    void d1EncoderA()
    Bnew1^Aold1 ? encoder1Pos++ : encoder1Pos--;
    Aold1 = digitalRead(encoder1PinA);
    void d1EncoderB()
    Bnew1 = digitalRead(encoder1PinB);
    Bnew1^Aold1 ? encoder1Pos++ : encoder1Pos--;
    void d2EncoderA()
    Bnew2^Aold2 ? encoder2Pos++:encoder2Pos--;
    Aold2=digitalRead(encoder2PinA);
    void d2EncoderB()
    Bnew2=digitalRead(encoder2PinB);
    Bnew2^Aold2 ? encoder2Pos++:encoder2Pos--;
    }

    piZviZ wrote:
    Only data rate working is 9600  between labview and launchpad(arm cortex m4).Where all data rates work between Arduino serial port monitor and launchpad(arm cortex m4).
    Since the only thing that changed is the Launchpad, then that must be the issue.  Are you sure this device can handle more than just the 9600 baud rate?  Are you sure you are even setting the baud rate on this device?

  • How to read the hard disk serial number using java this is urgent

    Please do let me know any knows how to read the hard disk unique number provided by manufactruer using java library

    I don't know; I think the fate of the free worldrests upon the answer.
    Well, as long as the non-free world stays unharmed,
    it can't be so bad ...I think the "Axis of Evil" constitutes a group of countries that are just "misunderstood".

  • About serial cable communication using Java

    Hello everyone,
    I want to use javax.comm to do serial cable communication on Linux platform. Currently, I can not find enough learning materials (tutorials and samples) from searching the net. Could anyone help to recommend some good ones?
    thanks in advance,
    George

    corss post, again and again

  • Problem in Accessing serial port using java comm Api

    I have installed java comm Api in my pc.
    i have gone through the instalation instruction which comes on this package.
    I have done the instalation like this
    Copy win32com.dll to my <JDK>\bin directory.
    Copy comm.jar to my <JDK>\lib directory.
    Copy javax.comm.properties to my <JDK>\lib directory.
    and restart the system.
    But when i run the BlackBox , it is giving me message
    "serial port not found".
    Can any one tell me , what is the exact problem ?

    I'm not sure what you mean by BlackBox, but I have used the COMM api extensively.
    The majority of problems is that the api cannot see the serial port (which is what you are describing) and this is caused by incorrect placing of the javax.comm.properties file.
    As well as <JDK>\lib, try putting it into <JRE>\lib as well. That has often solved problems on my setup.

  • How to read and write from the serial port using java

    can anyone tel me how to capture data from a serial port and display on the screen and also store it in a database.

    Java Comm API, JDBC

  • Some question on serial communication using J2ME

    I want my Palm communicate with the other devices throught its serial port and have the following codes.
    But it does not work. It always returns "No this connection" (ConnectionNotFoundException e).
    Could anyone please give me some suggestions on how to correct it ?
    I am sure that the baudrate is correct and there is no parity bit.
    Thank you very much
    if (c == connectCommand){
    try{
    String URI = "comm:0;baudrate=9600;bitsperchar=8";
    InputConnection inputCon = (InputConnection) Connector.open(URI);
    InputStream is = inputCon.openInputStream();
    t.setString("Success");
    catch(IllegalArgumentException e)
    t.setString("Argument not correct");
    catch (ConnectionNotFoundException e)
    t.setString("No this connection");
    catch(IOException e)
    t.setString("Can't not make this connection");
    }

    Hi, futurefield
    What should I do with the port name I got ?
    open the port with the name that I used to transmit data ?
    use Connector.open(portname) instead of Connector.open(URI) ?
    Would you please give me more hints ?
    Thank you

  • Data communication using java

    Hi every one,
    I have a question.
    Can I achieve data transmission between computers using some individual defined address rather than the IP address?
    Is there a way possible to achieve this?
    Thank you
    Song

    Hi,
    No, I mean to achieve another communication protocol totally disregard the ip address of the computer.
    For example, I have a physical connection of the two computers and I define each computer a kind of address and I need they can transmit data to each other using the new type of address I defined
    Thank you
    Song

  • Serial Communication using Labview with Tiva C launchpad ARM cortex M4

    I am able  to comunicate perfectly  between labview and launchpad at 9600 baudrate..When i trying to communicate with bauadrate of 115200 labview gives error "specifed state of attribute is not valid"
    I tried to communicate with serial monitor comes with arduino and its well work with it at 115200 baudrate...
    Awaiting for your replay!!!

    piZviZ wrote:
    Only data rate working is 9600  between labview and launchpad(arm cortex m4).Where all data rates work between Arduino serial port monitor and launchpad(arm cortex m4).
    Since the only thing that changed is the Launchpad, then that must be the issue.  Are you sure this device can handle more than just the 9600 baud rate?  Are you sure you are even setting the baud rate on this device?

  • How to send data using serial Communication

    I want to make serial communication using RXTXcomm.jar file.I was written the code.From this I got the list of serial ports avilable on pc but then after when I was tring to send command to machine which is attached to port it didn't gave any reply.
    Tell me that how to send command to port?

    This is how I do it:// open port, get ownership
    SerialPort serialPort= (SerialPort)portId.open(APPLICATIONNAME, timeout);
    // no framing and no threshold
    serialPort.disableReceiveFraming();
    serialPort.disableReceiveThreshold();
    // communication speed, parity, stopbits and databits
    serialPort.setSerialPortParams(BAUDRATE, SerialPort.DATABITS_8,
         SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    // no handshaking or other flow control
    serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    // timer on any read of the serial port
    serialPort.enableReceiveTimeout(TIMEOUT);
    // open streams for reading and writing
    InputStream is= serialPort.getInputStream();
    OutputStream os= serialPort.getOutputStream();... then you use the 'os' stream for writing and the 'is' stream for reading.
    kind regards,
    Jos

Maybe you are looking for

  • Slow performance while loading the reports while previewing the report in sql server data tools

    Hi there, I am facing a weird issue where I am able to load and view deployed report in report manager in no time (in a second) but the same report is taking almost two minutes for preview Around 2500 records are to be displayed in it. My report show

  • Keep footer div at the bottom of the page

    ok, really simple im sure, il i want to do is keep a div at the bottom of the page.. not the browser window so it can always be seen, but at the bottom of all the content, what information would i apply to this div? ive tried top;100% minus the heigh

  • Bulk Load API Status

    Hi, I'm using Oracle Endeca 2.3. I encountered a problem in data integrator, Some batch of records were missing in the Front end and when I checked the status of Graph , It Showed "Graph Executed sucessfully". So, I've connected the Bulk loader to "U

  • PSE 8 Elements - Not ACR 5.7

    I just installed Lightroom 2.7 and it says it is up to ACR 5.7. I also just bought and installed PSE 8 and it says that ACR is 5.5. Why isn't PSE 8 shipped with 5.7 and do I have to personally download it?

  • Problems activating Adobe Viewer

    I recently purchased an e-reader a LEGGO from IBS Italy.  I have purchased two books but I can't download them as they require me to active the device by using my Adobe account.  There is provision for this on the e-reader.  I tap in logging  in with