Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > serial port reading

Reply
Thread Tools

serial port reading

 
 
Willie
Guest
Posts: n/a
 
      09-07-2005
Hi, my friends,

I am working on a device connecting to the serial port. I need to read
data from the device. I used the SimpleRead.java from SUN's website.
http://java.sun.com/developer/releas...impleRead.java

The port I used is COM1. But it didn't give me what I want. The data
was stored in the log area of the device. The previous version for the
application was in C++ and worked well. They use
ReadFile(hComm,s,maxtoread,&read,0) to retrieve the data from the
device.

Does the inputstream not fit the application or I did other things
wrong? Any help is good. Thank you in advance.

Willie

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-08-2005
On 7 Sep 2005 15:06:00 -0700, "Willie" <(E-Mail Removed)> wrote or
quoted :

>But it didn't give me what I want.


what happened?

Did you get garbled data, nothing at all, valid data but not what you
expected?

There are so many things to configure before a serial port will work
correctly:
baud rate, character width, stop bits, parity, flow control.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-08-2005
On Thu, 08 Sep 2005 03:17:26 GMT, Roedy Green
<(E-Mail Removed)> wrote or quoted :

>There are so many things to configure before a serial port will work
>correctly:
>baud rate, character width, stop bits, parity, flow control.


Then you have the connectors, and cables which usually are missing
conductors.

For background on serial ports see
http://mindprod.com/jgloss/rs232c.html
and chase the links.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
jan V
Guest
Posts: n/a
 
      09-08-2005
Willie,

It seems you need to learn how to tackle debugging in a systematic way.

You've connected your device to your Java app via a cable and a host for
your Java app, OK?

Is any data flowing over that cable? If not, forget the program, your
problem is probably cabling.

What's the log area of the device (we really can't read minds in this
newsgroup, you need to be in alt.mystic for that...) ?

Have you checked that your very first transmission to the device is
bit-for-bit what it needs to be? Your device isn't going to answer if you
send it junk...

Break the problem down. Tackle each sub-problem one at a time.


"Willie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi, my friends,
>
> I am working on a device connecting to the serial port. I need to read
> data from the device. I used the SimpleRead.java from SUN's website.
> http://java.sun.com/developer/releas...impleRead.java
>
> The port I used is COM1. But it didn't give me what I want. The data
> was stored in the log area of the device. The previous version for the
> application was in C++ and worked well. They use
> ReadFile(hComm,s,maxtoread,&read,0) to retrieve the data from the
> device.
>
> Does the inputstream not fit the application or I did other things
> wrong? Any help is good. Thank you in advance.
>
> Willie
>



 
Reply With Quote
 
Willie
Guest
Posts: n/a
 
      09-08-2005
I used serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE) to set the parameters
and
....
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
int r=0;
try {
while
((r=inputStream.read(readBuffer))!=-1){//(inputStream.available() > 0)
{
int numBytes = inputStream.read(readBuffer);
System.out.println(new String(readBuffer, 0, r));
}
....

to print the output. The output repeated like this :
(Q )
(Q )
(Q )
....
I don't know what's that.

My expected output is a string of digital data. Thanks,

Willie


Roedy Green wrote:
> On 7 Sep 2005 15:06:00 -0700, "Willie" <(E-Mail Removed)> wrote or
> quoted :
>
> >But it didn't give me what I want.

>
> what happened?
>
> Did you get garbled data, nothing at all, valid data but not what you
> expected?
>
> There are so many things to configure before a serial port will work
> correctly:
> baud rate, character width, stop bits, parity, flow control.
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.comAgain taking new Java programming contracts.


 
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
emulate a serial port in windows (create a virtual 'com' port) Pom Python 2 01-31-2007 07:49 PM
Serial Port programming - Reading DSR from port msalerno Perl Misc 3 07-14-2005 12:58 PM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM
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