Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > writing to serial port (COMM)

Reply
Thread Tools

writing to serial port (COMM)

 
 
Andreas
Guest
Posts: n/a
 
      05-17-2004
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."


 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      05-17-2004
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...
 
Reply With Quote
 
 
 
 
Andreas
Guest
Posts: n/a
 
      05-17-2004
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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-17-2004
On Mon, 17 May 2004 20:45:40 +0200, "Andreas"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Andreas
Guest
Posts: n/a
 
      05-17-2004
Roedy Green wrote:
> if the problem is remembering the hex, decimal or octal codes, see
> http://mindprod.com/jgloss/ascii.html


Thanks. I'm sure that table can come in handy.


 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      05-18-2004
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
 
Reply With Quote
 
blackmonk blackmonk is offline
Junior Member
Join Date: Nov 2010
Posts: 2
 
      11-16-2010
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing serial port data to the gzip file Petr Jakes Python 6 12-19-2006 07:57 AM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM
Reading from serial port & writing to X console lec Python 1 07-17-2003 04:24 PM
Re: Serial port and PS/2 port schematics OR Assistive Tech. suggestion naive.verizon@locality.net Computer Support 1 07-10-2003 11:46 AM
Re: Serial port and PS/2 port schematics °Mike° Computer Support 1 07-09-2003 10:30 PM



Advertisments