Results 1 to 5 of 5
  1. #1
    grayhat555 is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default microcontroller on serial doesn't receive input

    Finally found the correct forum to paste this question of mine.

    Hi! I have this Java code to write to a serial port. The code compiles all right, and the hardware is a USB-to-Serial and has no problem (I have tried it on hyperterminal).
    NO EXCEPTION occurs, but the microcontroller on the other end of the serial doesn't receive ANY input.

    Java Code:
    SerialPort s_port;
    OutputStream o_stream;
    Enumeration<?> en;
    CommPortIdentifier portId[];
    
    s_port = null;
    o_stream = null;
    en=CommPortIdentifier.getPortIdentifiers();
    int i = 0;
    while(en.hasMoreElements())
    {
    en.nextElement();
    i++;
    }
    System.out.println("there are "+i +" ports");
    en=CommPortIdentifier.getPortIdentifiers();
    portId = new CommPortIdentifier;
    i = 0;
    while(en.hasMoreElements())
    {
    portId = (CommPortIdentifier) en.nextElement();
    System.out.println("port "+portId.toString() +" is a " +portId.getName()
    +" of type " +portId.getPortType());
    i++;
    }
    for(int a=0; a<i; a++)
    {
    if(portId[a].getName().equals("COM5"))
    {
    System.err.println("COM5 is in index "+a);
    addressInArray = a;
    break;
    }
    }
    
    try {
    System.out.println("A: initializing it");
    if(addressInArray!=1000)
    s_port = (SerialPort)portId[addressInArray].open("tesis Server v1.0", 30000);
    s_port.setSerialPortParams(19200,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    s_port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE
    | SerialPort.FLOWCONTROL_NONE);
    o_stream = s_port.getOutputStream();
    } catch (IOException e) {
    System.err.println("unknown exception 4");
    e.printStackTrace();
    }
    char c1 = 'L';
    char c2 = '\n';
    try
    {
    System.out.println("A: writing");
    o_stream.write(c1);
    o_stream.write(c2);
    }catch(Exception ex){
    System.err.println("cannot write");
    }
    I know that the microcontroller doesn't receive any input because it's supposed to light a certain LED when it receives any input. Hyperterminal does that well.

    Any ideas pls?

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Is this JInput?

  3. #3
    grayhat555 is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    Is this JInput?
    nope, it's javax.comm

  4. #4
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Hmm, never used it before. Sorry :)

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,769
    Blog Entries
    7
    Rep Power
    21

    Default

    Why do you iterate over the Enumeration multiple times? You only have to iterate once over it, select the port you want and voila.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Bluetooth Communication with Microcontroller
    By 00145217 in forum Networking
    Replies: 0
    Last Post: 11-29-2010, 08:24 PM
  2. Replies: 1
    Last Post: 07-30-2010, 09:29 AM
  3. not able to receive packets?? pls help.
    By abdullahansari in forum New To Java
    Replies: 1
    Last Post: 06-24-2010, 03:19 AM
  4. error in file transfer from pc to microcontroller
    By santhosh_el in forum Networking
    Replies: 0
    Last Post: 11-06-2009, 10:58 AM
  5. Replies: 0
    Last Post: 12-02-2008, 11:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •