[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rxtx
Subject:    Re: [Rxtx] Can not receive any data with RXTX on Ubuntu 9.10
From:       Daniel Morales Salas <damorales () gmail ! com>
Date:       2010-03-24 12:39:38
Message-ID: d57644fd1003240539t62ef4c48nb103258463f05adc () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I'm sure there is nothing "magic" to do to make RXTX works on ubuntu 9.10,
i'm building an application that use a USB/Serial converter (UART) and i ran
my software on mandriva 2010 and ubuntu 9.10 and it can receive data
perfectly (i'm using rxtx 2.2 pre 2 from cvs).

You can use the event listener as george suggest you or you can do it like
this:

            int availableBytes = inputStream.available();
            while (availableBytes > 0) {
                // Read the serial port
                inputStream.read(readBuffer, 0, availableBytes);
                //Save data
                bytes.add((new Byte(readBuffer[0])));
                availableBytes = inputStream.available();
            }

(This is the entire method i build):

    /**
     * Reads bytes from input stream.
     * @return
     */
    private synchronized ArrayList<Byte> readBytesFromPLCBUS1141() {
        ArrayList<Byte> bytes = new ArrayList<Byte>();
        byte[] readBuffer = new byte[100];

        try {
            int availableBytes = inputStream.available();
            while (availableBytes > 0) {
                // Read the serial port
                inputStream.read(readBuffer, 0, availableBytes);
                //Save data
                bytes.add((new Byte(readBuffer[0])));
                availableBytes = inputStream.available();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        //printBytesFromPLCBUS1141(bytes);

        return bytes;
    }

Both approaches are valid.
Here i've attached the class i use to send and receive data from serial port
(it works on ubuntu 9.10 !!!) so you can use it if you want, of course you
will need to update it to your needs.

Greetings !!!

2010/3/24 George H <george.dma@gmail.com>

> On Mon, Mar 22, 2010 at 3:17 PM, Jens Rabe
> <schaumwaffelpilot@googlemail.com> wrote:
> > Hi folks,
> >
> > I just installed RXTX on an Ubuntu 9.10 system. I then wanted to collect
> > data from a data logger with USB/Serial converter. The program I wrote
> works
> > fine with RXTX in Windows. The data logger is correctly recognized as
> > /dev/ttyUSB0, I set the correct port. My program finds the port and opens
> it
> > without any errors, but no data arrives. The permissions for the port are
> > set right. Is there some additional "magic" to do on Ubuntu Jaunty?
> >
> > Regards,
> > Jens
>
> Hi, maybe you need to set an event listener on the serial port ?
>
> serialPort.addEventListener( ... );
> serialPort.notifyOnDataAvailable(true);
> _______________________________________________
> Rxtx mailing list
> Rxtx@qbang.org
> http://mailman.qbang.org/mailman/listinfo/rxtx
>



-- 
Atte:
Daniel Dario Morales Salas
Ingeniero Civil en Computación e Informática
Teléfono: 02 684 3417
Celular: 09 643 1802
Santiago, Chile

[Attachment #5 (text/html)]

I&#39;m sure there is nothing &quot;magic&quot; to do to make RXTX works on ubuntu \
9.10, i&#39;m building an application that use a USB/Serial converter (UART) and i \
ran my software on mandriva 2010 and ubuntu 9.10 and it can receive data perfectly \
(i&#39;m using rxtx 2.2 pre 2 from cvs).<br> <br>You can use the event listener as \
george suggest you or you can do it like this:<br><br>                       int \
availableBytes = inputStream.available();<br>                       while \
(availableBytes &gt; 0) {<br>                               // Read the serial \
port<br>  inputStream.read(readBuffer, 0, availableBytes);<br>                        \
//Save data<br>                               bytes.add((new \
Byte(readBuffer[0])));<br>                               availableBytes = \
inputStream.available();<br>                       }<br> <br>(This is the entire \
method i build):<br><br>       /**<br>         * Reads bytes from input stream.<br>   \
* @return<br>         */<br>       private synchronized ArrayList&lt;Byte&gt; \
readBytesFromPLCBUS1141() {<br>               ArrayList&lt;Byte&gt; bytes = new \
ArrayList&lt;Byte&gt;();<br>  byte[] readBuffer = new byte[100];<br><br>              \
try {<br>                       int availableBytes = inputStream.available();<br>     \
while (availableBytes &gt; 0) {<br>                               // Read the serial \
port<br>                               inputStream.read(readBuffer, 0, \
availableBytes);<br>  //Save data<br>                               bytes.add((new \
Byte(readBuffer[0])));<br>                               availableBytes = \
inputStream.available();<br>                       }<br>               } catch \
(IOException e) {<br>                       e.printStackTrace();<br>  }<br><br>       \
//printBytesFromPLCBUS1141(bytes);<br>               <br>               return \
bytes;<br>       }<br><br>Both approaches are valid.<br>Here i&#39;ve attached the \
class i use to send and receive data from serial port (it works on ubuntu 9.10 !!!) \
so you can use it if you want, of course you will need to update it to your \
needs.<br> <br>Greetings !!!<br><br><div class="gmail_quote">2010/3/24 George H <span \
dir="ltr">&lt;<a href="mailto:george.dma@gmail.com">george.dma@gmail.com</a>&gt;</span><br><blockquote \
class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, \
204, 204); padding-left: 1ex;"> <div><div></div><div class="h5">On Mon, Mar 22, 2010 \
at 3:17 PM, Jens Rabe<br> &lt;<a \
href="mailto:schaumwaffelpilot@googlemail.com">schaumwaffelpilot@googlemail.com</a>&gt; \
wrote:<br> &gt; Hi folks,<br>
&gt;<br>
&gt; I just installed RXTX on an Ubuntu 9.10 system. I then wanted to collect<br>
&gt; data from a data logger with USB/Serial converter. The program I wrote works<br>
&gt; fine with RXTX in Windows. The data logger is correctly recognized as<br>
&gt; /dev/ttyUSB0, I set the correct port. My program finds the port and opens it<br>
&gt; without any errors, but no data arrives. The permissions for the port are<br>
&gt; set right. Is there some additional &quot;magic&quot; to do on Ubuntu \
Jaunty?<br> &gt;<br>
&gt; Regards,<br>
&gt; Jens<br>
<br>
</div></div>Hi, maybe you need to set an event listener on the serial port ?<br>
<br>
serialPort.addEventListener( ... );<br>
serialPort.notifyOnDataAvailable(true);<br>
_______________________________________________<br>
Rxtx mailing list<br>
<a href="mailto:Rxtx@qbang.org">Rxtx@qbang.org</a><br>
<a href="http://mailman.qbang.org/mailman/listinfo/rxtx" \
target="_blank">http://mailman.qbang.org/mailman/listinfo/rxtx</a><br> \
</blockquote></div><br><br clear="all"><br>-- <br>Atte:<br>Daniel Dario Morales \
Salas<br>Ingeniero Civil en Computación e Informática<br>Teléfono: 02 684 \
3417<br>Celular: 09 643 1802<br>Santiago, Chile<br>

--000e0cd4837036116504828b3996--


["MySerialPortHandler.java" (text/x-java-source)]

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.metalklesk.serial;

import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author metalklesk
 */
public class MySerialPortHandler {

    private CommPortIdentifier portId;
    private SerialPort serialPort;
    private InputStream inputStream = null;
    private OutputStream outputStream = null;
    private boolean opened = false;
    private ArrayList<CommPortIdentifier> list;
    private ResourceBundle spc = \
ResourceBundle.getBundle("org.metalklesk.serial.SerialPortConfiguration");

    private static MySerialPortHandler instance;

    private MySerialPortHandler(){
        list = detectRS232Ports();
        setCommPort(getCommPortIdentifier(spc.getString("serialport")));
        openRS232();
    }

    /**
     * Return a unique instance of the class, this is a Singleton.
     * @return
     */
    public synchronized static MySerialPortHandler getInstance() {
        if(instance == null)
            instance = new MySerialPortHandler();
        return instance;
    }

    private synchronized ArrayList<CommPortIdentifier> detectRS232Ports() {
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        list = new ArrayList<CommPortIdentifier>();

        while (portList.hasMoreElements()) {
            CommPortIdentifier comm = (CommPortIdentifier) portList.nextElement();
            if (comm.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                list.add(comm);
            }
        }

        return list;
    }

    private synchronized boolean openRS232() {
        try {
            serialPort = (SerialPort) portId.open("metalklesk", 5000);
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, \
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);  \
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);  \
serialPort.enableReceiveThreshold(1);  serialPort.enableReceiveTimeout(5000);
            outputStream = serialPort.getOutputStream();
            inputStream = serialPort.getInputStream();
            opened = true;
            
            return opened;
        } catch (IOException ex) {
            return false;
        } catch (UnsupportedCommOperationException ex) {
            return false;
        } catch (PortInUseException ex) {
            return false;
        } catch (NullPointerException ex) {
            return false;
        }
    }

    private CommPortIdentifier getPort(int i) {
        return list.get(i);
    }

    /**
     * Opens the given port by name, for example: /dev/ttyUSB0
     * @param userName
     * @param password
     * @param portName
     * @return
     */
    public synchronized boolean openRS232(String portName) {
        
        if(portName != null && !portName.trim().equals("")){
            closeRS232();
            CommPortIdentifier comm = getCommPortIdentifier(portName);

            if(comm != null) {
                setCommPort(comm);
                return openRS232();
            } else
                return false;
        } else
            return false;
    }

    /**
     * Close the open port if any.
     * @param userName
     * @param password
     * @return
     */
    public synchronized boolean closeRS232() {

        if(inputStream != null)
            try {
                inputStream.close();
            } catch (IOException ex) {
            }
        inputStream = null;

        if(outputStream != null)
            try {
                outputStream.close();
            } catch (IOException ex) {
            }
        outputStream = null;

        if(serialPort != null)
            serialPort.close();
        serialPort = null;

        portId = null;
        opened = false;

        return true;
    }

    /**
     * Light on a bulb, fluorescent or incandescent.
     * @param userName
     * @param password
     * @param userCode
     * @param homeUnit
     * @return
     */
    public synchronized String onBulb(byte userCode, byte homeUnit) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = homeUnit; //ej. home(0x00) + unit(0x00) = A1 (0x00)
                pak[4] = 0x02; //comando 02 (00000010) + ack(00100000) = (00100010 en \
binario) -> 22H  pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return "onBulb:" + isBulbOn(userCode, homeUnit, \
readBytesFromPLCBUS1141());  } catch (IOException ex) {
                return "onBulb:false";
            } catch (NullPointerException ex) {
                return "onBulb:false";
            }
        } else
            return "onBulb:false";
    }

    /**
     * Light off a bulb, fluorescent or incandescent.
     * @param userName
     * @param password
     * @param userCode
     * @param homeUnit
     * @return
     */
    public synchronized String offBulb(byte userCode, byte homeUnit) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = homeUnit; //home unit A1 (0x00)
                pak[4] = 0x03; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return "offBulb:" + isBulbOff(userCode, homeUnit, \
readBytesFromPLCBUS1141());  } catch (IOException ex) {
                return "offBulb:false";
            } catch (NullPointerException ex) {
                return "offBulb:false";
            }
        } else
            return "offBulb:false";
    }

    /**
     * Lights on an incandescent bulb with a given bright (0-100) and fade rate (in \
                seconds)
     * @param userName
     * @param password
     * @param userCode
     * @param homeUnit
     * @param brightValue
     * @param fadeValue
     * @return
     */
    public synchronized String dimmer(byte userCode, byte homeUnit, int brightValue, \
int fadeValue) {  if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = homeUnit; //home unit A1 (0x00)
                pak[4] = 0x0c; //comando
                pak[5] = Byte.parseByte(Integer.toHexString(brightValue), 16); \
                //bright
                pak[6] = Byte.parseByte(Integer.toHexString(fadeValue), 16); //fade
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return "dimmer:" + isDimmerSet(userCode, homeUnit, \
readBytesFromPLCBUS1141());  } catch (IOException ex) {
                return "dimmer:false";
            } catch (NullPointerException ex) {
                return "dimmer:false";
            }
        } else
            return "dimmer:false";
    }

    /**
     * Lights on all the user bulbs.
     * @param userName
     * @param password
     * @param userCode
     * @return
     */
    public synchronized String onAllUserLights(byte userCode) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = 0x00; //home unit A1 (0x00)
                pak[4] = 0x07; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return "onAllUserLights:" + isAllUserLightsOn(userCode, \
readBytesFromPLCBUS1141());  } catch (IOException ex) {
                return "onAllUserLights:false";
            } catch (NullPointerException ex) {
                return "onAllUserLights:false";
            }
        } else
            return "onAllUserLights:false";
    }

    /**
     * Lights off all the user lights.
     * @param userName
     * @param password
     * @param userCode
     * @return
     */
    public synchronized String offAllUserLights(byte userCode) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = 0x00; //home unit A1 (0x00)
                pak[4] = 0x09; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return "offAllUserLights:" + isAllUserLightsOff(userCode, \
readBytesFromPLCBUS1141());  } catch (IOException ex) {
                return "offAllUserLights:false";
            } catch (NullPointerException ex) {
                return "offAllUserLights:false";
            }
        } else
            return "offAllUserLights:false";
    }

    /**
     * Lights on all home lights.
     * @param userName
     * @param password
     * @param userCode
     * @param home
     * @return
     */
    public synchronized boolean onAllHomeLights(byte userCode, byte home) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = home; //home unit A1 (0x00)
                pak[4] = 0x01; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return isAllHomeLightsOn(userCode, home, readBytesFromPLCBUS1141());
            } catch (IOException ex) {
                return false;
            } catch (NullPointerException ex) {
                return false;
            }
        } else
            return false;
    }

    /**
     * Lights off all home lights.
     * @param userName
     * @param password
     * @param userCode
     * @param home
     * @return
     */
    public synchronized boolean offAllHomeLights(byte userCode, byte home) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = home; //home unit A1 (0x00)
                pak[4] = 0x06; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return isAllHomeLightsOff(userCode, home, readBytesFromPLCBUS1141());
            } catch (IOException ex) {
                return false;
            } catch (NullPointerException ex) {
                return false;
            }
        } else
            return false;
    }

    /**
     * Lights off all home units.
     * @param userName
     * @param password
     * @param userCode
     * @param home
     * @return
     */
    public synchronized boolean offAllHomeUnits(byte userCode, byte home) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = home; //home unit A1 (0x00)
                pak[4] = 0x00; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return isAllHomeUnitsOff(userCode, home, readBytesFromPLCBUS1141());
            } catch (IOException ex) {
                return false;
            } catch (NullPointerException ex) {
                return false;
            }
        } else
            return false;
    }

    /**
     * Lights off all user units.
     * @param userName
     * @param password
     * @param userCode
     * @return
     */
    public synchronized boolean offAllUserUnits(byte userCode) {
        if(opened) {
            try {
                byte[] pak = new byte[8];
                pak[0] = 0x02; //inicio pak
                pak[1] = 0x05; //largo
                pak[2] = userCode; //user code D1
                pak[3] = 0x00; //home unit A1 (0x00)
                pak[4] = 0x08; //comando
                pak[5] = 0x00; //data 1
                pak[6] = 0x00; //data 2
                pak[7] = 0x03; //fin pak
                outputStream.write(pak);
                outputStream.flush();

                waitBeforeReadingBytes(1000);

                return isAllUserUnitsOff(userCode, readBytesFromPLCBUS1141());
            } catch (IOException ex) {
                return false;
            } catch (NullPointerException ex) {
                return false;
            }
        } else
            return false;
    }

    /**
     * Returns an arraylist with all the ports identified as CommPortIdentifier.
     * @return
     */
    public synchronized ArrayList<CommPortIdentifier> getPortsAsCommPortIdentifier() \
{  return list;
    }

    /**
     * Return an arraylist with the name of all the detected ports.
     * @param userName
     * @param password
     * @return
     */
    public synchronized ArrayList<String> getPortsAsString(String userName, String \
password) {  ArrayList<String> s = new ArrayList<String>();
        s = new ArrayList<String>();
        if(list != null)
            for(int i=0; i<list.size(); i++) {
                s.add(list.get(i).getName());
            }

        return s;
    }

    /**
     * Sets a port.
     * @param portId
     */
    public synchronized void setCommPort(CommPortIdentifier portId) {
        this.portId = portId;
    }

    private synchronized void waitBeforeReadingBytes(int ms) {
        //wait 1 second before reading bytes
        try {
            this.wait(ms);
        } catch (InterruptedException ex) {
            Logger.getLogger(MySerialPortHandler.class.getName()).log(Level.SEVERE, \
null, ex);  }
    }

    /**
     * Reads bytes from input stream.
     * @return
     */
    private synchronized ArrayList<Byte> readBytesFromPLCBUS1141() {
        ArrayList<Byte> bytes = new ArrayList<Byte>();
        byte[] readBuffer = new byte[100];

        try {
            int availableBytes = inputStream.available();
            while (availableBytes > 0) {
                // Read the serial port
                inputStream.read(readBuffer, 0, availableBytes);
                //Save data
                bytes.add((new Byte(readBuffer[0])));
                availableBytes = inputStream.available();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        //printBytesFromPLCBUS1141(bytes);
        
        return bytes;
    }

    private synchronized boolean isBulbOn(byte userCode, byte homeUnit, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==homeUnit && bytes.get(4).byteValue()==2 \
                && bytes.get(5).byteValue()==100 &&
                    bytes.get(6).byteValue()==0 && bytes.get(7).byteValue()==28)
                return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isBulbOff(byte userCode, byte homeUnit, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==homeUnit && bytes.get(4).byteValue()==3 \
                && bytes.get(5).byteValue()==0 &&
                    bytes.get(6).byteValue()==0 && bytes.get(7).byteValue()==28)
                return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isDimmerSet(byte userCode, byte homeUnit, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==homeUnit && \
bytes.get(4).byteValue()==12 && bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllUserLightsOn(byte userCode, ArrayList<Byte> \
bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==7 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllUserLightsOff(byte userCode, ArrayList<Byte> \
bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==9 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllHomeLightsOn(byte userCode, byte home, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==1 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllHomeLightsOff(byte userCode, byte home, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==6 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllHomeUnitsOff(byte userCode, byte home, \
ArrayList<Byte> bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==0 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private synchronized boolean isAllUserUnitsOff(byte userCode, ArrayList<Byte> \
bytes) {  if(bytes.size() >= 9) {
            if(bytes.get(0).byteValue()==2 && bytes.get(1).byteValue()==6 && \
                bytes.get(2).byteValue()==userCode &&
                    bytes.get(3).byteValue()==0 && bytes.get(4).byteValue()==8 && \
bytes.get(7).byteValue()==28)  return true;
            else
                return false;
        } else
            return false;
    }

    private void printBytesFromPLCBUS1141(ArrayList<Byte> bytes) {
        for(int i=0; i<bytes.size(); i++) {
            System.out.print(bytes.get(i).byteValue() + " ");
        }
        System.out.println("");
    }

    /**
     * Returns a port as CommPortIdentifier by a given name.
     * @param portName
     * @return
     */
    private synchronized CommPortIdentifier getCommPortIdentifier(String portName) {
        CommPortIdentifier comm = null;
        if(list != null) {
            for(int i=0; i<list.size(); i++) {
                comm = list.get(i);
                if(comm.getName().equalsIgnoreCase(portName)) {
                    break;
                } else
                    comm = null;
            }
        }

        return comm;
    }

    /**
     * Close the input and output streams and the port before garbage collector \
                destroy the object.
     */
    @Override
    public void finalize() {
        if(inputStream != null)
            try {
                inputStream.close();
            } catch (IOException ex) {
            }
        inputStream = null;

        if(outputStream != null)
            try {
                outputStream.close();
            } catch (IOException ex) {
            }
        outputStream = null;

        if(serialPort != null)
            serialPort.close();
        serialPort = null;

        portId = null;
        opened = false;
    }

}



_______________________________________________
Rxtx mailing list
Rxtx@qbang.org
http://mailman.qbang.org/mailman/listinfo/rxtx


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic