writing to serial port (COMM)

Discussion in 'Java' started by Andreas, May 17, 2004.

  1. Andreas

    Andreas Guest

    Greetings,

    I am just starting to use the COMM package to communicate with a serial
    device.
    I have found all ports and opened the correct one without problem.
    According to the serial device's manual I am supposed to "send AT plus a CR
    ($41, $54, $0D) and await the same answer". The problem is that I am not
    sure how to transfer "AT plus a CR".
    I have seen in a few examples (in this group's archives) how you can write
    to a serial port, and I am doing the following:

    CommPortIdentifier portId =
    CommPortIdentifier.getPortIdentifier("COM2");
    SerialPort serialPort = (SerialPort)portId.open( "MySerialApp", 2000 );
    serialPort.getOutputStream().write("AT <CR>".getBytes());

    I am guessing this is not how it should be done (the "AT <CR>" I mean).
    After you all have recovered from your laughing attacks, maybe someone
    could help me understand this basic stuff?
    It would be greatly appreciated.

    Best,
    Andreas
    ---
    "Remember, half the people in the world are below average."
     
    Andreas, May 17, 2004
    #1
    1. Advertising

  2. Andreas wrote:
    > Greetings,
    >
    > I am just starting to use the COMM package to communicate with a serial
    > device.
    > I have found all ports and opened the correct one without problem.
    > According to the serial device's manual I am supposed to "send AT plus a CR
    > ($41, $54, $0D) and await the same answer". The problem is that I am not
    > sure how to transfer "AT plus a CR".
    > I have seen in a few examples (in this group's archives) how you can write
    > to a serial port, and I am doing the following:
    >
    > CommPortIdentifier portId =
    > CommPortIdentifier.getPortIdentifier("COM2");
    > SerialPort serialPort = (SerialPort)portId.open( "MySerialApp", 2000 );
    > serialPort.getOutputStream().write("AT <CR>".getBytes());
    >
    > I am guessing this is not how it should be done (the "AT <CR>" I mean).
    > After you all have recovered from your laughing attacks, maybe someone
    > could help me understand this basic stuff?
    > It would be greatly appreciated.
    >
    > Best,
    > Andreas
    > ---
    > "Remember, half the people in the world are below average."
    >
    >


    "AT\r".getBytes() or byte[] buf = { 0x41, 0x54, 0x13 };

    CR is a nmenonic for carriage return.

    --

    Knute Johnson
    email s/nospam/knute/
    Molon labe...
     
    Knute Johnson, May 17, 2004
    #2
    1. Advertising

  3. Andreas

    Andreas Guest

    Knute Johnson wrote:
    > "AT\r".getBytes() or byte[] buf = { 0x41, 0x54, 0x13 };
    >
    > CR is a nmenonic for carriage return.


    Thank you Knute.
    It actually struck me when I looked up the ASCII-codes for the hex-numbers.
    (duh..)

    Best,
    Andreas
     
    Andreas, May 17, 2004
    #3
  4. Andreas

    Roedy Green Guest

    On Mon, 17 May 2004 20:45:40 +0200, "Andreas"
    <> wrote or quoted :

    >It actually struck me when I looked up the ASCII-codes for the hex-numbers.


    if the problem is remembering the hex, decimal or octal codes, see
    http://mindprod.com/jgloss/ascii.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 17, 2004
    #4
  5. Andreas

    Andreas Guest

    Andreas, May 17, 2004
    #5
  6. Andreas wrote:
    > Thank you Knute.
    > It actually struck me when I looked up the ASCII-codes for the hex-numbers.
    > (duh..)


    But some of the hex codes for ASCII are easy to remember:

    A few easy to remember characters are:

    0x00: NUL
    0x20: space
    0x30: '0'
    0x40: '@'
    0x7f: DEL

    Knowing these then help for other characters:

    Digits 0-9:

    0x30 is '0', 0x39 is '9'. digit + 0x30 = ASCII code of digit.

    Uppercase letters:

    0x40 is '@', after that the uppercase letters start, and are easy to
    count. 0x41 = 'A', 0x42 = 'B' ... Position of letter in alphabet + 0x40
    = uppercase letter's ASCII code.

    Lowercase letters:

    + 0x20 offset from uppercase letters. Easy to count.


    Some things are even easier to remember in octal. 0100 is '@'.

    /Thomas
     
    Thomas Weidenfeller, May 18, 2004
    #6
  7. Andreas

    blackmonk

    Joined:
    Nov 16, 2010
    Messages:
    2
    Hi guys, i know this is old and all but i'm trying to read input from a weight scale and output it to a gui i've created. I'm very new to java and i'm using this package (javax.comm)for the first time. pls help with any code that you might have that reads from a serial port. My scale connects to the pc using a usb-serial converter.
     
    blackmonk, Nov 16, 2010
    #7
    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. Greg Pedder
    Replies:
    0
    Views:
    688
    Greg Pedder
    Feb 8, 2004
  2. yakka
    Replies:
    3
    Views:
    8,396
    jc9121
    Aug 17, 2006
  3. Sundar

    sync/async serial comm..

    Sundar, Nov 21, 2006, in forum: C Programming
    Replies:
    3
    Views:
    506
    osmium
    Nov 21, 2006
  4. Replies:
    1
    Views:
    3,021
    Michael DOUBEZ
    Mar 4, 2009
  5. matchstick86

    Serial comm from BRAM

    matchstick86, Feb 19, 2010, in forum: VHDL
    Replies:
    1
    Views:
    608
    matchstick86
    Mar 9, 2010
Loading...

Share This Page