CommPort integration

Discussion in 'Java' started by AndreasW, Nov 11, 2006.

  1. AndreasW

    AndreasW Guest

    Hello,

    i've got a question about the integration of a CommPort into a Java
    programm. I need it for data transfer between the PC and a
    Microcontroller. I'm a newbie in programming and so it would be very
    useful to have some easy examples or an introduction for the
    initialisation of the port and the read/transmit- process. I've
    downloaded "commapi" from Sun Microsystems, but I mean the description
    is a little bit complicated.
    I hope you could help me with a useful link or a helpful example file.

    Thank you very much.
    AW

    I don't know if it is important, but I use the JBuilder from Borland.
     
    AndreasW, Nov 11, 2006
    #1
    1. Advertising

  2. AndreasW wrote:
    > Hello,
    >
    > i've got a question about the integration of a CommPort into a Java
    > programm. I need it for data transfer between the PC and a
    > Microcontroller. I'm a newbie in programming and so it would be very
    > useful to have some easy examples or an introduction for the
    > initialisation of the port and the read/transmit- process. I've
    > downloaded "commapi" from Sun Microsystems, but I mean the description
    > is a little bit complicated.
    > I hope you could help me with a useful link or a helpful example file.
    >
    > Thank you very much.
    > AW
    >
    > I don't know if it is important, but I use the JBuilder from Borland.


    Here is some code taken from an application I wrote. It opens the port,
    sets the parameters and obtains an InputStream. After that it is just
    like any other stream I/O.

    CommPortIdentifier cpi =
    CommPortIdentifier.getPortIdentifier("COM1");
    SerialPort sp =
    (SerialPort)cpi.open("LVDCClient",2500);

    // set serial port parameters
    sp.setSerialPortParams(9600,SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

    sp.disableReceiveTimeout();
    sp.disableReceiveThreshold();

    InputStream is = sp.getInputStream();
    bis = new BufferedInputStream(is);


    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Nov 11, 2006
    #2
    1. Advertising

  3. AndreasW

    AndreasW Guest

    Knute Johnson schrieb:
    > AndreasW wrote:
    >> Hello,
    >>
    >> i've got a question about the integration of a CommPort into a Java
    >> programm. I need it for data transfer between the PC and a
    >> Microcontroller. I'm a newbie in programming and so it would be very
    >> useful to have some easy examples or an introduction for the
    >> initialisation of the port and the read/transmit- process. I've
    >> downloaded "commapi" from Sun Microsystems, but I mean the description
    >> is a little bit complicated.
    >> I hope you could help me with a useful link or a helpful example file.
    >>
    >> Thank you very much.
    >> AW
    >>
    >> I don't know if it is important, but I use the JBuilder from Borland.

    >
    > Here is some code taken from an application I wrote. It opens the port,
    > sets the parameters and obtains an InputStream. After that it is just
    > like any other stream I/O.
    >
    > CommPortIdentifier cpi =
    > CommPortIdentifier.getPortIdentifier("COM1");
    > SerialPort sp =
    > (SerialPort)cpi.open("LVDCClient",2500);
    >
    > // set serial port parameters
    > sp.setSerialPortParams(9600,SerialPort.DATABITS_8,
    > SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    > sp.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    >
    > sp.disableReceiveTimeout();
    > sp.disableReceiveThreshold();
    >
    > InputStream is = sp.getInputStream();
    > bis = new BufferedInputStream(is);
    >
    >

    Fine, thank you for the fast answer. I will look if it is helpful for me.
     
    AndreasW, Nov 11, 2006
    #3
  4. AndreasW

    IchBin Guest

    AndreasW wrote:
    > Hello,
    >
    > i've got a question about the integration of a CommPort into a Java
    > programm. I need it for data transfer between the PC and a
    > Microcontroller. I'm a newbie in programming and so it would be very
    > useful to have some easy examples or an introduction for the
    > initialisation of the port and the read/transmit- process. I've
    > downloaded "commapi" from Sun Microsystems, but I mean the description
    > is a little bit complicated.
    > I hope you could help me with a useful link or a helpful example file.
    >
    > Thank you very much.
    > AW
    >
    > I don't know if it is important, but I use the JBuilder from Borland.


    You can download the Communications API Specification 2.0:
    https://sdlc4e.sun.com/ECom/EComAct...E;jsessionid=4C6A445450E7A7414ADEA49AC390A61E

    It has a lot of sample code.

    --
    Thanks in Advance... http://ichbin.9999mb.com
    IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
    ______________________________________________________________________
    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
     
    IchBin, Nov 11, 2006
    #4
  5. AndreasW wrote:
    > i've got a question about the integration of a CommPort into a Java
    > programm. I need it for data transfer between the PC and a
    > Microcontroller.


    // Get a port identifier
    CommPortIdentifier portId =
    CommPortIdentifier.getPortIdentifier(portName);
    // Open a port
    SerialPort port =
    (SerialPort)portId.open("CommPortExample Application", 30000);
    // Open an input Stream
    InputStream in = port.getInputStream();
    // Read data

    Don't be suprised in you run into problems with Sun's API. If you do,
    take a look at rxtx: http://users.frii.com/jarvi/rxtx/

    Also, if you ever start wanting to add TCP access to your rs232-based
    comms on the microcontroller side, I can strongly recommend Digi's EM
    and ME series of modules,

    Regards,

    Richard
     
    Richard Wheeldon, Nov 11, 2006
    #5
  6. Richard Wheeldon wrote:
    > AndreasW wrote:
    >> i've got a question about the integration of a CommPort into a Java
    >> programm. I need it for data transfer between the PC and a
    >> Microcontroller.

    >
    > // Get a port identifier
    > CommPortIdentifier portId =
    > CommPortIdentifier.getPortIdentifier(portName);
    > // Open a port
    > SerialPort port =
    > (SerialPort)portId.open("CommPortExample Application", 30000);
    > // Open an input Stream
    > InputStream in = port.getInputStream();
    > // Read data
    >
    > Don't be suprised in you run into problems with Sun's API. If you do,
    > take a look at rxtx: http://users.frii.com/jarvi/rxtx/
    >
    > Also, if you ever start wanting to add TCP access to your rs232-based
    > comms on the microcontroller side, I can strongly recommend Digi's EM
    > and ME series of modules,
    >
    > Regards,
    >
    > Richard


    RXTX has at least one serious bug under Windows. I have yet to have a
    problem with Sun's API. I don't really know why Sun doesn't want to
    support it any more but RXTX is not the answer.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Nov 12, 2006
    #6
  7. AndreasW

    AndreasW Guest

    Knute Johnson schrieb:
    > Richard Wheeldon wrote:
    >> AndreasW wrote:
    >>> i've got a question about the integration of a CommPort into a Java
    >>> programm. I need it for data transfer between the PC and a
    >>> Microcontroller.

    >>
    >> // Get a port identifier
    >> CommPortIdentifier portId =
    >> CommPortIdentifier.getPortIdentifier(portName);
    >> // Open a port
    >> SerialPort port =
    >> (SerialPort)portId.open("CommPortExample Application", 30000);
    >> // Open an input Stream
    >> InputStream in = port.getInputStream();
    >> // Read data
    >>
    >> Don't be suprised in you run into problems with Sun's API. If you do,
    >> take a look at rxtx: http://users.frii.com/jarvi/rxtx/
    >>
    >> Also, if you ever start wanting to add TCP access to your rs232-based
    >> comms on the microcontroller side, I can strongly recommend Digi's EM


    >>
    >> Regards,
    >>
    >> Richard

    >
    > RXTX has at least one serious bug under Windows. I have yet to have a
    > problem with Sun's API. I don't really know why Sun doesn't want to
    > support it any more but RXTX is not the answer.
    >




    Thank you very much for every answer. It's a great help for me.
    But there is another problem. Is it correct, that I have to call the
    library "javax.comm.*;" at the beginning of my program? This is written
    in the documentation of Sun's commapi?! It shall be copy into the
    <jdk>\jre\lib directory. But my compiler shows the Error message:
    "Package javax.comm doesn't exists". What's wrong? The other files
    (win32comm.dll and comm.jar) I've put in the right directorys, too?!

    Greetings,

    Andreas
     
    AndreasW, Nov 12, 2006
    #7
  8. AndreasW wrote:
    > Knute Johnson schrieb:
    >> Richard Wheeldon wrote:
    >>> AndreasW wrote:
    >>>> i've got a question about the integration of a CommPort into a Java
    >>>> programm. I need it for data transfer between the PC and a
    >>>> Microcontroller.
    >>>
    >>> // Get a port identifier
    >>> CommPortIdentifier portId =
    >>> CommPortIdentifier.getPortIdentifier(portName);
    >>> // Open a port
    >>> SerialPort port =
    >>> (SerialPort)portId.open("CommPortExample Application", 30000);
    >>> // Open an input Stream
    >>> InputStream in = port.getInputStream();
    >>> // Read data
    >>>
    >>> Don't be suprised in you run into problems with Sun's API. If you do,
    >>> take a look at rxtx: http://users.frii.com/jarvi/rxtx/
    >>>
    >>> Also, if you ever start wanting to add TCP access to your rs232-based
    >>> comms on the microcontroller side, I can strongly recommend Digi's EM

    >
    >>>
    >>> Regards,
    >>>
    >>> Richard

    >>
    >> RXTX has at least one serious bug under Windows. I have yet to have a
    >> problem with Sun's API. I don't really know why Sun doesn't want to
    >> support it any more but RXTX is not the answer.
    >>

    >
    >
    >
    > Thank you very much for every answer. It's a great help for me.
    > But there is another problem. Is it correct, that I have to call the
    > library "javax.comm.*;" at the beginning of my program? This is written
    > in the documentation of Sun's commapi?! It shall be copy into the
    > <jdk>\jre\lib directory. But my compiler shows the Error message:
    > "Package javax.comm doesn't exists". What's wrong? The other files
    > (win32comm.dll and comm.jar) I've put in the right directorys, too?!
    >
    > Greetings,
    >
    > Andreas


    To compile you need to put the comm.jar file in the JDK/jre/lib/ext
    directory.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Nov 13, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AA

    VC and WAB integration.

    AA, Jan 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    486
  2. news.microsoft.com
    Replies:
    0
    Views:
    545
    news.microsoft.com
    May 3, 2004
  3. Topweaver
    Replies:
    0
    Views:
    1,909
    Topweaver
    Mar 22, 2005
  4. Florian Marinoiu

    Credit card integration

    Florian Marinoiu, Jul 15, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    427
  5. Madhuri Mittal

    VB.Net-C# integration

    Madhuri Mittal, Aug 6, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,772
    Kevin Spencer
    Aug 6, 2003
Loading...

Share This Page