🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2469

Sun's javax.comm simple read example ...

#2469
From: pre
Date: Thu, 09 Nov 2000 00:00
69 lines
2799 bytes
Hello,

I'am learning how to use the javax.comm.SerialPort class with the SimpleRead
example found at
http://java.sun.com/products/javacomm/javadocs/API_users_guide.html

I have modified the code and added two lines...

    public SimpleRead() {
        try
        {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {}
        try
        {
            is = serialPort.getInputStream();
            os = serialPort.getOutputStream();        // Added
            os.write("ATZ".getBytes());                // Added
        }
        catch (IOException e) {}
        ....
    }

When I use hyper terminal, "ATZ" has "OK" for reply... So the stuff seems to
work...
But when I use the following code from within Java:

    public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
        ...
        case SerialPortEvent.DATA_AVAILABLE:
        System.out.println ("DATA_AVAILABLE");
        byte[] readBuffer = new byte[500];
        int readLen=0;
        byte b;
        try
        {
            while (is.available() > 0)
            {
                readLen = is.read(readBuffer);
            }
            System.out.println("Read="+readLen);
            for (int j=0; j<=readLen; j++)
            {
                b=readBuffer[j];
                System.out.println(j+" = "+b);
            }
        }
}

I have the following output...

DATA_AVAILABLE
Read=3
0 = 73
1 = -84
2 = -83
3 = 0

...which should be the string "OK", and now here's my question: How to
translate this 4 bytes reply to the ASCII string "OK" ?

OS: WinNT4 SP6
JC: Java version "1.2.2" Classic VM (build JDK-1.2.2-004, native threads,
symcjit) The JDK of JBuilder 3.5

Many thanks for any help...

Philippe.
Technical Details
Message-ID: <8udvu4$2a$1@news1.skynet.be>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f82aa,d18d8d150e938fd9,start
X-Google-Attributes: gidf82aa,public
X-Google-Thread: f5e83,d18d8d150e938fd9,start
X-Google-Attributes: gidf5e83,public
X-Google-Thread: 113ae9,d18d8d150e938fd9,start
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 1089d0,d18d8d150e938fd9,start
X-Google-Attributes: gid1089d0,public
From: "pre" <pre@winbox.com>
Subject: Sun's javax.comm simple read example ...
Date: 2000/11/09
Message-ID: <8udvu4$2a$1@news1.skynet.be>
X-Deja-AN: 691579143
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Complaints-To: abuse@skynet.be
X-Trace: news1.skynet.be 973767428 74 212.166.17.172 (9 Nov 2000 10:57:08 GMT)
Organization: Belgacom Skynet SA/NV
X-MSMail-Priority: Normal
NNTP-Posting-Date: 9 Nov 2000 10:57:08 GMT
Newsgroups: borland.public.jbuilder.java.api,comp.lang.java.help,comp.lang.java.softwaretools,it.comp.java