Serialevent

im having serialevent() in my class.i want it to be triggered when
a single byte comes in the serial port.For each single byte received
in the serial port i want the serialevent() to be triggerred.
In the simpleread program in the demo, in serial event() im getting group of bytes read from the serial port.kindly help me regarding this
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(19200,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
System.out.println("main thread exited");
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[120];
int numBytes=0;
try {
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
for(int i=0;i<numBytes;i++)
System.out.print(new String(readBuffer,i,1));
// System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}

Have a StringBuffer as a class variable, and each time you get a serial event, append the new bytes:
public class RecieveBuffer
    private StringBuffer buffer=new StringBuffer();
    /** put data into buffer */
    public void receive(byte[] data)
        buffer.append(new String(data));
    /** get accumulated data */
    public String getData()
        return buffer.toString();
    /** clear out old data */
    public void clear()
        buffer.setLength(0);
}

Similar Messages

  • Regarding serialevent

    im having serialevent() in my class.i want it to be triggered when
    a single byte comes in the serial port.For each single byte received
    in the serial port i want the serialevent() to be triggerred.
    In the simpleread program in the demo, in serial event() im getting group of bytes read from the serial port.kindly help me regarding this
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;
    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;
    public static void main(String[] args) {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    // if (portId.getName().equals("/dev/term/a")) {
    SimpleRead reader = new SimpleRead();
    public SimpleRead() {
    try {
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    } catch (PortInUseException e) {}
    try {
    inputStream = serialPort.getInputStream();
    } catch (IOException e) {}
         try {
    serialPort.addEventListener(this);
         } catch (TooManyListenersException e) {}
    serialPort.notifyOnDataAvailable(true);
    try {
    serialPort.setSerialPortParams(19200,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}
    readThread = new Thread(this);
    readThread.start();
    System.out.println("main thread exited");
    public void run() {
    try {
    Thread.sleep(20000);
    } catch (InterruptedException e) {}
    public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    byte[] readBuffer = new byte[120];
    int numBytes=0;
    try {
    while (inputStream.available() > 0) {
    numBytes = inputStream.read(readBuffer);
    for(int i=0;i<numBytes;i++)
    System.out.print(new String(readBuffer,i,1));
    // System.out.print(new String(readBuffer));
    } catch (IOException e) {}
    break;
    }

    kindly help me regarding this topic

  • AT Commands , Hyper Terminal and java

    Hi,
    I have following problem, i have PCMCIA Type -11 Wireless modem.its installed on my system COM4 port.
    Now first problem is that when i try to connect with hyper terminal to COM4 there is no response from it .It become Idle.but when i connect with COM3 which is my Dialup modem port it works fine with all AT commands.
    Now 2nd things is that same with below code i tried to send sms using AT command on COM4 its has same behaviour as it was in Hyper terminal mean no response. no Data Available event occour
    Please help me in this regard and suggest me a solution.
    package serialio;
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class SimpleWrite
        implements Runnable, SerialPortEventListener
      public void run()
      static Enumeration portList;
      static CommPortIdentifier portId;
      static String dest = "0517111930";
      static String messageString = "Hello";
      InputStream inputStream;
      static SerialPort serialPort;
      static OutputStream outputStream;
      public void serialEvent(SerialPortEvent event)
        switch (event.getEventType())
          case SerialPortEvent.BI:
          case SerialPortEvent.OE:
          case SerialPortEvent.FE:
          case SerialPortEvent.PE:
          case SerialPortEvent.CD:
          case SerialPortEvent.CTS:
          case SerialPortEvent.DSR:
          case SerialPortEvent.RI:
          case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
          case SerialPortEvent.DATA_AVAILABLE:
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line = "";
            try
              while ( (line = reader.readLine()) != null)
                System.out.println(line);
            catch (IOException e)
              System.err.println("Error while reading Port " + e);
            break;
        } //switch
      public SimpleWrite(SerialPort serial)
        try
          inputStream = serial.getInputStream();
          try
            serial.addEventListener(this);
          catch (TooManyListenersException e)
            System.out.println("Exception in Adding Listener" + e);
          serial.notifyOnDataAvailable(true);
        catch (Exception ex)
          System.out.println("Exception in getting InputStream" + ex);
      public static void main(String[] args)
    //    String line1="AT+CMGF=1\r\n";
    //    String line2="AT+CMGS=\""+ dest+"\"\r\n";
    //    String line3=messageString+"\r\n";
    //    String line4="\u001A";
        String line1 = "AT+CMGF=1\r\n";
        String line2 = "AT+CMGS=" + dest + "\r\n";
        String line3 = messageString + "^Z\r\n";
    //    String line4 = "\u001A";
        portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements())
          portId = (CommPortIdentifier) portList.nextElement();
          if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
            System.out.println("SMS Sending........");
            if ( portId.getName().equals("COM4"))
              System.out.println("SMS Sending....Port Found");
              try
                serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
                SimpleWrite wr = new SimpleWrite(serialPort);
              catch (PortInUseException e)
                System.out.println("Port In Use " + e);
              try
                outputStream = serialPort.getOutputStream();
              catch (IOException e)
                System.out.println("Error writing to output stream " + e);
              try
                serialPort.setSerialPortParams(
                    2400,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
              catch (UnsupportedCommOperationException e)
              try
                outputStream.write(line1.getBytes());
                outputStream.write(line2.getBytes());
                outputStream.write(line3.getBytes());
                outputStream.flush();
              catch (IOException e)
                System.out.println("Error writing message " + e);
      /** show text in the text window
       * @param Text text string to show on the display
      public static void showText(String Text)
        System.out.println(Text);
    }

    * SerialWrite.java
    * Created on September 10, 2008, 2:51 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package com.sms;
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class SerialWrite implements Runnable, SerialPortEventListener
    static String output="";
    public void run()
    static Enumeration portList;
    static CommPortIdentifier portId;
    static String dest = "+91999999999";
    static String messageString = "Hello Testing11";
    InputStream inputStream;
    static SerialPort serialPort;
    static OutputStream outputStream;
    public void serialEvent(SerialPortEvent event)
    switch (event.getEventType())
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
              System.out.println("Error");
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    String line = "";
    try
    while ( (line = reader.readLine()) != null)
    if(line.equalsIgnoreCase("OK") || (line.indexOf("+CMGS") != -1))
         output=line;
              Thread.sleep(10);
    catch (Exception e)
    System.err.println("Error while reading Port " + e);
    break;
    } //switch
    public SerialWrite(SerialPort serial)
    try
    inputStream = serial.getInputStream();
    try
    serial.addEventListener(this);
    catch (TooManyListenersException e)
    System.out.println("Exception in Adding Listener" + e);
    serial.notifyOnDataAvailable(true);
    catch (Exception ex)
    System.out.println("Exception in getting InputStream" + ex);
    public static void main(String[] args) throws Exception
         int i=0;
    String line0 = "ATZ\r\n";
    String line1 = "AT+CMGF=1\r\n";
    String line2 = "AT+CSCA=\"+919888888\"\r\n";
    //String line3 = "AT+CMGS="+"\""+ dest + "\""+"\r\n";
    String line3 = "AT+CMGS="+"\""+ args[0] + "\""+"\r\n";
    //String line4 = messageString;
    String line4 = args[1];
         portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements())
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
    System.out.println("SMS Sending........");
    if ( portId.getName().equals("/dev/ttyACM0"))
    System.out.println("SMS Sending....Port Found");
    try
    serialPort = (SerialPort) portId.open("SerialTestApp", 2000);
    SerialWrite wr = new SerialWrite(serialPort);
    catch (PortInUseException e)
    System.out.println("Port In Use " + e);
    try
    outputStream = serialPort.getOutputStream();
    catch (IOException e)
    System.out.println("Error writing to output stream " + e);
    try
    serialPort.setSerialPortParams(
    115200,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    catch (UnsupportedCommOperationException e)
    try
    outputStream.write(line0.getBytes());
              Thread.sleep(10);
    while(!output.equalsIgnoreCase("ok"))
              Thread.sleep(10);
              output="";
    outputStream.write(line1.getBytes());
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
    outputStream.write(line2.getBytes());
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
         for(i=0;i<3;i++)
    outputStream.write(line3.getBytes());
    Thread.sleep(10);
    outputStream.write(line4.getBytes());
    Thread.sleep(10);
    outputStream.write(26);
    outputStream.write("\r\n".getBytes());
    outputStream.flush();
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
              System.out.println("Message Sent !!!!!!!!!1");
    catch (IOException e)
    System.out.println("Error writing message " + e);
    /** show text in the text window
    * @param Text text string to show on the display
    public static void showText(String Text)
    System.out.println("TEXT "+Text);
    }

  • How to use the serial port

    hello
    I would like to know if there is other library than comm to use to establish communication with the serial port ..
    can we do this with pure java ,I mean without the need of using any library ???
    if not then what is the best library to use ???
    any examples ??
    I have other question
    when i use the library comm
    I use the public void serialEvent(SerialPortEvent event) to get my data
    but that data comme line by line
    is there a way to get all the data at once ???
    than kyou in advance

    There you go
    http://java.sun.com/products/javacomm/
    Some extra resources
    http://www.google.co.in/search?q=java+access+serial+po
    rt&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.
    mozilla:en-US:officialmaybe I was not clear ,I know the comm lib
    Im already using it
    but am asking if there any other lib that will work for windows
    thank you

  • Problem in reading input form files while parsing them in javacc

    I need to parse a language called DISP (delay insensitive sequential processes) using javacc. I need help with reading the input which we parse, eg for a matched brace example i dont want to just check if all the braces are matched, i also want to do something everytime i read a brace.
    Is declaring tokens and using token.image the only way?
    and can anyone explain what "parser object" "token manager" etc are and how the whole thing works, in simple words. The documents have details but i keep getting getting lost in them

    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;
    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;
    public static void main(String[] args) {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    //if (portId.getName().equals("/dev/term/a")) {
    SimpleRead reader = new SimpleRead();
    public SimpleRead() {
    try {
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    } catch (PortInUseException e) {}
    try {
    inputStream = serialPort.getInputStream();
    } catch (IOException e) {}
         try {
    serialPort.addEventListener(this);
         } catch (TooManyListenersException e) {}
    serialPort.notifyOnDataAvailable(true);
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}
    readThread = new Thread(this);
    readThread.start();
    public void run() {
    try {
    Thread.sleep(20000);
    } catch (InterruptedException e) {}
    public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    byte[] readBuffer = new byte[20];
    try {
    while (inputStream.available() > 0) {
    int numBytes = inputStream.read(readBuffer);
    System.out.print(new String(readBuffer));
    } catch (IOException e) {}
    break;
    }

  • CTS Based Simple Bike Speedometer - Problem with CTS Pulse

    Everytime a magnet rotates, a sensor sends a CTS signal...I know the hardware works, as it works with another Speedometer writen with Delphi (Spinner on SourceForge). However, my program is getting the right speed, then numbers way too big for about three pulses, the right speed, garbage again, etc.... I'm assuming there is something about the CTS protocol and how the Java program needs to respond to a CTS event that I'm not getting. Or could it be my use of systemtime?
    Here's code snippets.....
    Oh, and I'm using DSR for cadence, and RI for heartrate, any similar issues that I need to be aware of using them?
    Thanks
         serialPort = (SerialPort)portID.open("IntervalTrack", 0);
            serialPort.setSerialPortParams(9600,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            serialPort.addEventListener(this);
            serialPort.notifyOnDSR(true);
            serialPort.notifyOnCTS(true);
            serialPort.notifyOnCarrierDetect(true);
            serialPort.notifyOnRingIndicator(true);
            serialPort.notifyOnDataAvailable(true);
            serialPort.setDTR(false);
            serialPort.setRTS(true);--- snip ----
        public void serialEvent(SerialPortEvent e) {
                System.out.println(e.getEventType());
                switch (e.getEventType())
                    case SerialPortEvent.CTS:
                        doCTS();
                        break;
                    case SerialPortEvent.DSR:               
                        doDSR();
                        break;
                    case SerialPortEvent.RI:
                        doRI();
                        break;
        private void doCTS(){
            double dblSpeedT2 = System.currentTimeMillis();
            double dblDeltaSpeedTime = dblSpeedT2 - this.dblSpeedT1;
           //todo resolve divide by zero  if (dblDeltaSpeedTime == 0.0)
            //                  dblDeltaSpeedTime = 1;
            this.dblSpeedKmPerHour = 3.6 * this.getWheelSizeInMM() /
                          dblDeltaSpeedTime;
            this.dblSpeedT1 = dblSpeedT2;
        }

    Just for future reference if someone googles this unanswered question (so much for Java forums help.....).
    The problem was that I needed to distinguish between the evt. changing from true to false and only computing for one or the other. So if it was false I computed, if it was true I continued. (err....or was it the other way around?) either way, thats the fix.....not sure on the why of this though..

  • Java comm

    I HAVE A PROBLEM WITH JAVA-COMM.
    I USE THE JAVA-COMM FOR COMMUNICATION WITH GSM BUT I HAVE A PROBLEM WITH THE COMMUNICATION WHEN I RECEIVE THE REPLYES OF THE AT'COMMANDS.
    THE TIMEOUT NOT FUNCTION AND THE PROGRAMM GO IN BLOCK BECAUSE IT WAIT THE REPLY WHO NOT DELIVERED.
    I USE THE LISTENER. THERE IS ANOTHER METOD FOR ACCEPT THE REPLIES AND SET THE TIMEOUT?
    THANK.

    What platform are you using ? (Windows/Solaris...)
    Can your program print a list of all serial interfaces available and is your chosen interface in that list ?
    When your program outputs the AT command, does anything happen ?
    Does your serialEvent() method in the listener receive ANYTHING ?
    i.e. just print the eventType.
    Once you can see the DATA_AVAILABLE event, you can read data.
    The biggest problem I've had with the package is making sure it sees the interfaces in the first place.

  • Self defined Event processing problem

    Hi every1�Cthe situation is like the following:
    2 PCs communicate through Bluetooth serial port profile by 3 classes that i wrote.
    First, BluetoothManger, it implements SerialportEventListener of Javax.comm package,its job is to read the incoming data from the other end and store them into an array,and it works.
    Second,DataReceiver,it implements EventObject, so whenever it copies the array from BluetoothManger, it will pass them into the next stage Algorithm.
    Third,Algorithm., it implements EventListener, it has function @public void dataChanged(DataReceiver dr)@, this function is causing a loop to run forever
    The other end is sending 20 numbers each frame,and there are only 10 frames,but once the sender side start sending stuff, the receiver end kept running forever...
    The following is the code,thanks very much in advance for anybody's voice!!!
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class BluetoothManager implements SerialPortEventListener{
         static CommPortIdentifier portId;
        static Enumeration portList;     
         InputStream inputStream;
        SerialPort serialPort;
           DataReceiver dr;
           Convert c;
           byte[] tempBuffer;
           byte[] smallArray;
           int[] intArray;
           int[] ints;
           int k;
        int h;
        public BluetoothManager()
             tempBuffer=new byte[100];
             smallArray=new byte[100];
             ints=new int[20];
             intArray=new int[230];
             dr=new DataReceiver(ints);
             c=new Convert();
             k=0;
             h=0;
        public void listenToPort()
              portList=CommPortIdentifier.getPortIdentifiers();
              while(portList.hasMoreElements()){
                   portId = (CommPortIdentifier) portList.nextElement();
                   if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
                        System.out.println("found..." + portId.getName());
                        if (portId.getName().equals("COM6")){// 4
                             try {
                               System.out.println("about to try.." + portId.getName());
                               serialPort = (SerialPort) portId.open("SerialPort", 2000);
                           } catch (PortInUseException e) { System.out.println("Exception: Port in use!"); }
                           try {
                               inputStream = serialPort.getInputStream();
                           } catch (IOException e) {}
                             try {
                               serialPort.addEventListener(this);
                             } catch (TooManyListenersException e) {}
                           serialPort.notifyOnDataAvailable(true);
                           try {
                               serialPort.setSerialPortParams(9600,
                                   SerialPort.DATABITS_8,
                                   SerialPort.STOPBITS_1,
                                   SerialPort.PARITY_NONE);
                           } catch (UnsupportedCommOperationException e) {}
        public int[] storeFrameArray(byte[] temp)
              smallArray=temp;          
              for(int i=0;i<20;i++){
                   byte[] temp2=new byte[4];
                   System.arraycopy(smallArray,k,temp2,0,4);
                   ints=c.toInt(temp2);
                   k=k+4;
                   if (k>=80) k=0;               
              return ints;
         public DataReceiver getDataRX(){
              return dr;
         public void serialEvent(SerialPortEvent event)
    switch(event.getEventType()) {
         case SerialPortEvent.DATA_AVAILABLE:
              try{
                   while(inputStream.available()>0){
                        inputStream.read(tempBuffer);
                                  dr.setArray(this.storeFrameArray(tempBuffer));
              }catch(IOException e){           }
         break;
    import java.util.*;
    public class DataReceiver extends EventObject{
         int[] rxArray;
         int h;
        boolean dataChangedFlag;
         public DataReceiver(int[] ints)
              super(ints);
              rxArray=new int[20];
              dataChangedFlag=false;
             h=0;
         public void setArray(int[] array)
              System.arraycopy(array,0,rxArray,0,20);
             dataChangedFlag=true;
         public int[] getIntArray()
              return rxArray;
         public boolean getFlag()
              dataChangedFlag=false;
              return dataChangedFlag;
         public void addDataReceiverListener(Algorithm algo)
              while(dataChangedFlag=true){
                   algo.dataChanged(this);
    import java.util.*;
    public class Algorithm implements EventListener {
         boolean finishFlag;
         int[] alArray;
         int[] partInts;
         int[] events;
         int eventIndex;
         int[] dd;
         int i;
         int result;
         DataReceiver drr;
         public Algorithm(BluetoothManager bMAL)
              drr=bMAL.getDataRX();
              finishFlag=false;
              alArray=new int[230];
              partInts=new int[20];
              events=new int[500];
              dd=new int[20];
              result=0;
              eventIndex=0;
              drr.addDataReceiverListener(this);     
         public void calculate(int[] intss)
              for(int i=0;i<20;i++)dd=intss[i]*5;     
              for(int j=0;j<20;j++){
                   if(dd[j]<100&&dd[j]>50){
                   events[eventIndex]=dd[j];
                   System.out.println("Index"+eventIndex+":"+dd[j]);
                   eventIndex++;
         public void dataChanged(DataReceiver data)
              data.getFlag();
              partInts=data.getIntArray();
              calculate(partInts);
    Thanks again

    > Hi every1�Cthe situation is like the following:
    What?
    ~

  • Troubles writing a string of numbers in binary mode to a file.

    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
            int x;
            while ((x = stringRW.codePointAt(i)) != -1) {
                try {
                    out.write(x); // Copia o arquivo.
                    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
            at java.lang.String.codePointAt(String.java:715)
            at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
            at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
            at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
            at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
            at gnu.io.RXTXPort.eventLoop(Native Method)
            at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)But the problem in fact, is that the generated file is not a binary file. For check if the generated file is or not binary, I do open it in Notepad. When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.
    Some one have some guess on how I need to proceed?
    Edited by: cstrieder on Aug 5, 2009 1:15 PM

    cstrieder wrote:
    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:Are you saying that you want to write the individual characters of your string to a file? Or are you saying that you want to write the integer values from your string to a file? I.e., do you want to write the number "1" as a character or do you want to write the value 1 to a file?
    >
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
    int x;
    while ((x = stringRW.codePointAt(i)) != -1) {
    try {
    out.write(x); // Copia o arquivo.
    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
    at java.lang.String.codePointAt(String.java:715)
    at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
    at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
    at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
    at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
    at gnu.io.RXTXPort.eventLoop(Native Method)
    at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
    Your exception is telling you exactly what the problem is. Your index is beyond the length of your string. Instead of using a while loop to iterate over the String, try using a for-loop instead. i.e.
    for(int i = 0; i < myString.length(); i++) {
      // blah blah blah
    But the problem in fact, is that the generated file is not a binary file.Every file is a binary file. What you're doing is writing the character value to the file. Instead of that, you may want to try parsing your character value into an integer and then writing that value.
    For check if the generated file is or not binary, I do open it in Notepad.That's not an appropriate method for determining the byte values written to your file(s). Use a hex editor instead.
    When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.Again, that's because you're writing the character values, not the integer values.

  • Getting started in Java Comm API

    Hi This is all new to me. So I would really appreciate if anyone can help me figure this out..I am trying to read from the serial port using a VS4000 Image Scanner(Symbol). I want to scan a driver's license bar code. I believe PDF417 is the type of barcode to read driver's license. However, Im just curious if there is any code out there that actually parses the information out of the license. I need to get the lastname, firstname,dob,gender,address,drivers #, etc.. Does any one have any idea where I could get more information in how to scan a driver's license. I need more guidance in how to really do this. Although, I went to the introduction to Java Communications and found a example code "SimpleRead.java". However, I get some errors....
    can anyone help..I have a nullpointer ..not sure how to fix it...
    I get this error :
    java.lang.NullPointerException
         at SimpleRead.<init>(SimpleRead.java:64)
         at SimpleRead.main(SimpleRead.java:53)
    Exception in thread "main" Process terminated with exit code 1
    Here is the original code :
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;
    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;
    public static void main(String[] args) {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    //if (portId.getName().equals("/dev/term/a")) {
    SimpleRead reader = new SimpleRead();
    public SimpleRead() {
    try {
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    } catch (PortInUseException e) {}
    try {
    inputStream = serialPort.getInputStream();
    } catch (IOException e) {}
         try {
    serialPort.addEventListener(this);
         } catch (TooManyListenersException e) {}
    serialPort.notifyOnDataAvailable(true);
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}
    readThread = new Thread(this);
    readThread.start();
    public void run() {
    try {
    Thread.sleep(20000);
    } catch (InterruptedException e) {}
    public void serialEvent(SerialPortEvent event) {
    switch(event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    byte[] readBuffer = new byte[20];
    try {
    while (inputStream.available() > 0) {
    int numBytes = inputStream.read(readBuffer);
    System.out.print(new String(readBuffer));
    } catch (IOException e) {}
    break;
    Thanks a bunch!! :)
    Jess...

    I actually got my scanner to work. I got my SimpleRead.java to work as an application. I set up this as an applet. Now my problem is that I the inputread reading from the serial port is not reading correct data always. It sometimes does scan correct data at times and other times it will not. So, I am not sure what is wrong. Does anyone have any clue why this could happen?

  • URGENT: Capturing data through serial port

    Hi,
    My problem is with the use of javax.comm API. I have an RFID tag reader connected to
    the serial port. It is a handheld reader and reads tags when its trigger is pulled. The
    data that is read is sent to the serial port. This is what I want to capture.
    I tried to test the reading operation by running the SimpleRead sample. What I see is
    that I pull the trigger once to read 1 tag, but that generates 3 DATA_AVAILABLE events.
    The tag ID that is read is 16 bytes, preceded by a 3 byte AIM Identifier (that declares
    the following data was read from an RFID tag, and not a barcode which has different
    AIM Identifiers for the different symbologies - but I digress.) By inserting some println's,
    I was able to see that the 19 bytes of data are read 8 bytes at a time. The first 8 bytes
    are read on the first DATA_AVAILABLE event, the next 8 are read on the second event
    and the last 3 bytes are read on the 3rd DATA_AVAILABLE event.
    This is strange & not good for me. How can my application know that the data read in
    these 3 separate DATA_AVAILABLE events is to be concatenated to form a single
    tag ID? Why is the single trigger-pull & tag read operation broken up into chunks of
    8 bytes? Is there some configuration setting that will give me the behavior I want?
    (I cannot rely on the length of the tag ID being 16 bytes always, because the same
    reader will also be reading barcodes where the data may have varying length)
    Thanks for any help. This is really urgent.
    - Ajoy

    please use the [ code ]and [code ] tags for code.
    I don't think you have a problem with the code, it's more like understanding how to make it work.
    to make the read method return.You do not have a read() method.
    The code is behaving as it should.
    You need to use the SimpleRead class as a thread, add and remove the Serial port listener as needed.
    You read all data available, then send it to a method to parse the buffer.
    You can count how much data was read so you know how much to parse.
    I never used receive threshhold.
    Here is example (sample)of my serial port reader
    //SerialIO
       public void serialEvent(SerialPortEvent event) {
            switch(event.getEventType()) {
                  case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                break;
            case SerialPortEvent.DATA_AVAILABLE:
                this.dataManager.readData();
    //DataManager
    public void readData() {
         String str;
         int     bytes = 0;
         long endTime, now;
         try {
              while (this.owner.isComPortOpen
                   && (SerialIO.inStream.available() > 0)) {
                   bytes = SerilIO.inStream.read(this.buffer);
                   if (bytes > 0) {
                   if (bytes > this.buffer.length) {
                        System.out.println( ": Input buffer overflow!");
         **Here is where you parse your buffer
                   sendDataToParser(bytes, buffer);
              } catch (IOException ex) {
                   System.out.println( ": Cannot read input stream");
          * Stops the serialEvent listener
         protected void stopSerialEvent() {
              SerialIO.serialPort.removeEventListener();
              try {
                   Thread.sleep(2000);
                   flushInputStream();
              } catch (InterruptedException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
          * Starts the Serial event listener
         protected void startSerialEvent() {
              // TODO Auto-generated method stub
              try {
                   SerialIO.serialPort.addEventListener(SerialIO);
              } catch (TooManyListenersException e) {
                   // TODO Auto-generated catch block
                   //System.out.println("startSerialEvent in dataManager");
                   e.printStackTrace();

  • How to convert data read in byte to decimal number?

    The following are a source code to read from a serial port, but i can't convert the data that i read to decimal number and write it on a text file.....can anyone kindly show me how to solve it? thanks
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class Read implements Runnable, SerialPortEventListener {
         // Attributes for Serial Communication
         static Enumeration portList;
         static CommPortIdentifier portId;
         SerialPort serialPort;
         static OutputStream outputStream;
         InputStream inputStream;
         Thread readThread;
         public static void main(String s[])
         portList=CommPortIdentifier.getPortIdentifiers();
         while(portList.hasMoreElements())
              portId=(CommPortIdentifier)portList.nextElement();
              if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL)
                   if(portId.getName().equals("COM1"))
                        System.out.println( portId.getName());
                        Read ss=new Read();
              }     // end of while
    }          // end of main
    public Read()     {
    try{
              serialPort=(SerialPort)portId.open("Read", 2000);
    catch(PortInUseException e)     {}
         try{
              inputStream=serialPort.getInputStream();
              System.out.println(inputStream);
    catch(IOException e)     {}
         try{
              serialPort.addEventListener(this);
    catch(Exception e)     {}
              serialPort.notifyOnDataAvailable(true);
         try{
              serialPort.setSerialPortParams(9600,
              SerialPort.DATABITS_8,
              SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
              }catch(UnsupportedCommOperationException e)     {}
              readThread=new Thread(this);
              readThread.start();
         }//end of constructor
         public void run()
              try     {
                   Thread.sleep(200);
              }catch(InterruptedException e)     {}
         public void serialEvent(SerialPortEvent event)
              switch(event.getEventType())
                   case SerialPortEvent.BI:
                   case SerialPortEvent.OE:
                   case SerialPortEvent.FE:
                   case SerialPortEvent.PE:
                   case SerialPortEvent.CD:
                   case SerialPortEvent.CTS:
                   case SerialPortEvent.DSR:
                   case SerialPortEvent.RI:
                   case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                   break;
                   case SerialPortEvent.DATA_AVAILABLE:
                   byte[]readBuffer=new byte[8];
                   try{
                        while(inputStream.available()>0)
                             int numBytes=inputStream.read(readBuffer);
                             //System.out.println("hello");
                        System.out.print(new String(readBuffer));
                        }catch(IOException e)     {}
                   break;
                   }     // end of switch
                   try     {
                        inputStream.close();
                        }catch(Exception e5)     {}
         }          // end of serialEvent

    Is it a float or a double?
    For a float, the decimal should be 4 bytes (small numbers like 1.1 start with the byte 0x40). Convert these 4 bytes to an int, using byte-shifting would probably be easiest.
    int value = ((b3 << 24) + (b2 << 16) + (b1 << 8) + b0);//b# are bytesNow to convert it to a float, use
    Float.intBitsToFloat(value);Now if you want double percision, You will have 8 bytes instead of 4, and need to be converted to a long instead of an int through byte-shifting. Then use Double.longBitsToDouble(long bits) to get the double

  • Simple read code from RS232

    Hi
    I want to read stream of bytes from rs232 connected to microcontroller which send data ,i 'm sure that data arrive proberely before the serial cable but the code have aproblem see it
    package myserial;
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    * @author volcano_lab
    public class Main implements  Runnable, SerialPortEventListener {
        /** Creates a new instance of Main */
        public Main() {try {
                 cp=CommPortIdentifier.getPortIdentifier("COM1");
                try {
                    cpe=cp.open("begSer",2000);
                   serialPort=(SerialPort)cpe;
                    try {
                        serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
                                SerialPort.STOPBITS_1,
                                SerialPort.PARITY_NONE);
                    } catch (UnsupportedCommOperationException ex) {
                        ex.printStackTrace();
                   // System.out.println(cpe.getName());
                } catch (PortInUseException ex) {
                    ex.printStackTrace();
            } catch (NoSuchPortException ex) {
                ex.printStackTrace();
        readThread = new Thread(this);
              readThread.start();
         public void run() {
         try {
             Thread.sleep(20000000);
         } catch (InterruptedException e) {}
         * @param args the command line arguments
        public static void main(String[] args) {
            Main reader=new Main();
         public void serialEvent(SerialPortEvent event) {
         switch (event.getEventType()) {
         case SerialPortEvent.BI:
         case SerialPortEvent.OE:
         case SerialPortEvent.FE:
         case SerialPortEvent.PE:
         case SerialPortEvent.CD:
         case SerialPortEvent.CTS:
         case SerialPortEvent.DSR:
         case SerialPortEvent.RI:
         case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
      break;
         case SerialPortEvent.DATA_AVAILABLE:
             byte[] readBuffer = new byte[20];
             try {
              while (inputStream.available() > 0) {
                  int numBytes = inputStream.read(readBuffer);
              System.out.print(new String(readBuffer));
             } catch (IOException e) {}
             break;
        Thread readThread;
        CommPortIdentifier cp;
        CommPort cpe;
        SerialPort serialPort;
        InputStream inputStream;
    }and is there options that i have to make with my serial in pc
    Thanks in advance

    So what's the problem?

  • Javacomm: problem with the receive data

    Hello to all,
    I have a problem on receiving data from a serial port.
    As I figured out The port is obtained by the program I post
    here bellow..but I can't receive data.
    Do you have any hints?
    Thanks in advance.
    Mandy
    import javax.comm.*;
    import java.io.*;
    public class SerialRead extends Thread implements SerialPortEventListener
         private InputStream in;
         public SerialRead(String port)
              try
                   CommPortIdentifier id_porta;
                   id_porta = CommPortIdentifier.getPortIdentifier(port);
                   CommPort porta = id_porta.open("Read from serial porta", 200);
                   in = porta.getInputStream();
                   SerialPort porta_seriale = (SerialPort)porta;
                   porta_seriale.setSerialPortParams(9600, SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                   porta_seriale.addEventListener(this);
                   this.start();
              catch (NoSuchPortException ne)
                   System.out.println("The port " + port + "is not  present");
              catch (PortInUseException pe)
                   System.out.println("The port " + port + "is used by " + pe.
                        currentOwner);
              catch (UnsupportedCommOperationException ue)
                   System.out.println(
                        "The porta does not support the properties defined");
              catch (java.util.TooManyListenersException tme)
                   System.out.println(
                        "Ther can be only one owner of the port");
              catch (IOException ioe)
                   System.out.println("Error ofi IO");
         public void run()
              try
                   Thread.sleep(10000);
              catch (InterruptedException e)
         public void serialEvent(SerialPortEvent event)
              System.out.println("1");
             switch ( event.getEventType() )
                   case SerialPortEvent.BI :
                   case SerialPortEvent.OE :
                   case SerialPortEvent.FE :
                   case SerialPortEvent.PE :
                   case SerialPortEvent.CD :
                   case SerialPortEvent.CTS :
                   case SerialPortEvent.DSR :
                   case SerialPortEvent.RI :
                   case SerialPortEvent.OUTPUT_BUFFER_EMPTY :
                        break;
                   case SerialPortEvent.DATA_AVAILABLE :
                        byte[] readBuffer = new byte[20];
                        try
                             while ( in.available() > 0 )
                                  int numBytes = in.read(readBuffer);
                             System.out.println(new String(readBuffer));
                        catch (IOException e)
                        break;
         public static void main(String[] args)
             System.out.println(args[0]);
             if ( args.length < 1 )
                   System.out.println("Use java SerialRead <port name>");
              else
                   SerialRead reading = new SerialRead(args[0]);
    }

    Hi Abdul,
    Check if the data you are getting for the two fields in your data loading are correct. I think it has some illegal characters(I guess it has a trailing space). If possible try and correct it in the source system itself.
    If you are doing full load for the master data, everytime the system is going to pull these values in and throw error. One other way of avoiding it will be to maintain routines to eliminate these.
    The quickfix will be to correct it at the PSA level and load it again.
    Regards.

  • Java sound triggers

    Hello all and thanks for reading this post.
    I'm trying to make a simple piece of code where an event in a serial port will trigger a sound.
    I got quite far and came up with this.
    * @(#)SimpleRead.java     1.12 98/06/25 SMI
    * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
    * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license
    * to use, modify and redistribute this software in source and binary
    * code form, provided that i) this copyright notice and license appear
    * on all copies of the software; and ii) Licensee does not utilize the
    * software in a manner which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind.
    * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
    * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
    * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
    * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
    * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
    * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
    * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
    * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
    * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
    * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control
    * of aircraft, air traffic, aircraft navigation or aircraft
    * communications; or in the design, construction, operation or
    * maintenance of any nuclear facility. Licensee represents and
    * warrants that it will not use or redistribute the Software for such
    * purposes.
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineEvent;
    import javax.sound.sampled.LineListener;
    import javax.sound.sampled.LineUnavailableException;
    * Class declaration
    * @author
    * @version 1.8, 08/03/00
    public class SimpleRead implements Runnable, SerialPortEventListener {
        static CommPortIdentifier portId;
        static Enumeration           portList;
        InputStream                inputStream;
        SerialPort                serialPort;
        Thread                readThread;
        int i = 0;
        Clip m_clip;
        Clip c_clip;
        int side = 0;
         * Method declaration
         * @param args
         * @see
        public static void main(String[] args) {
        boolean                portFound = false;
        String                defaultPort = "COM1";
         if (args.length > 0) {
             defaultPort = args[0];
         portList = CommPortIdentifier.getPortIdentifiers();
         while (portList.hasMoreElements()) {
             portId = (CommPortIdentifier) portList.nextElement();
             if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
              if (portId.getName().equals(defaultPort)) {
                  System.out.println("Found port: "+defaultPort);
                  portFound = true;
                  SimpleRead reader = new SimpleRead();
         if (!portFound) {
             System.out.println("port " + defaultPort + " not found.");
         * Constructor declaration
         * @see
        public SimpleRead() {
         try {
             serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
         } catch (PortInUseException e) {}
            serialPort.setDTR(true);
         try {
             inputStream = serialPort.getInputStream();
         } catch (IOException e) {}
         try {
             serialPort.addEventListener(this);
         } catch (TooManyListenersException e) {}
         serialPort.notifyOnDataAvailable(true);
            serialPort.notifyOnDSR(true);
         try {
             serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                                SerialPort.STOPBITS_1,
                                SerialPort.PARITY_NONE);
         } catch (UnsupportedCommOperationException e) {}
            File clipFile = new File("sound/snare.wav");
            AudioInputStream     audioInputStream = null;
              try
                   audioInputStream = AudioSystem.getAudioInputStream(clipFile);
              catch (Exception e)
                   e.printStackTrace();
              if (audioInputStream != null)
                   AudioFormat     format = audioInputStream.getFormat();
                   DataLine.Info     info = new DataLine.Info(Clip.class, format);
                   try
                        m_clip = (Clip) AudioSystem.getLine(info);
                                    c_clip = (Clip) AudioSystem.getLine(info);
                        m_clip.open(audioInputStream);
                                    c_clip.open(audioInputStream);
                   catch (LineUnavailableException e)
                        e.printStackTrace();
                   catch (IOException e)
                        e.printStackTrace();
         readThread = new Thread(this);
         readThread.start();
         * Method declaration
         * @see
        public void run() {
         try {
             Thread.sleep(20000);
         } catch (InterruptedException e) {}
         * Method declaration
         * @param event
         * @see
           public void serialEvent(SerialPortEvent event) {
         switch (event.getEventType()) {
         case SerialPortEvent.BI:
         case SerialPortEvent.OE:
         case SerialPortEvent.FE:
         case SerialPortEvent.PE:
         case SerialPortEvent.CD:
         case SerialPortEvent.CTS:
         case SerialPortEvent.DSR:
               if(i == 0) {
                    i = 1;
                 if(side == 1) {
                    m_clip.stop();
                    m_clip.setFramePosition(0);
                    m_clip.start();
                    side = 0;
                 } else {
                    c_clip.stop();
                    c_clip.setFramePosition(0);
                    c_clip.start();
                    side = 1;
                 } else {
                    i = 0;
                 System.out.println("DSR event"+ i); 
         case SerialPortEvent.RI:
         case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
             break;
         case SerialPortEvent.DATA_AVAILABLE:
             byte[] readBuffer = new byte[20];
             try {
              while (inputStream.available() > 0) {
                  int numBytes = inputStream.read(readBuffer);
              System.out.print(new String(readBuffer));
             } catch (IOException e) {}
             break;
    }Which in java terms is quite simple code!
    Now, the script worked. But I can only trigger the event about once every second or so. If I trigger it more frequently than that, I hear nothing, or garbled sounds.
    The sound I'm trying to play is a simple drum hit sound, so a drum roll messes up completely.
    I'm no expert, I was wondering if perhaps threading somehow would help, but I'm not sure how to do this.
    If someone could kindly point me in the right direction I'd much appreciate it.
    Thanks for reading through :)

    I am having a similar problem getting sounds from a Java applet heard when used via Citrix nFuse. The application works fine outside of Citrix, but I hear nothing when run via Citrix. I have opened a support call with Citrix, and they are testing with the Microsoft JVM (with some better results), but that is not something that I would like to do.
    Does anyone have any experience in getting any sound files played via Java via Citrix? Any help would be appreciated.

Maybe you are looking for

  • How can I change the AppleID in iMessage on my MacBook?

    I just downloaded the iMessage app for my MacBook and it seems to work great. Only issue is: I have 2 Apple IDs and, of course, the wrong one is now logged in. I would like to know if there is a way to change the Apple ID associated with my iMessage

  • Line Item dIm use

    Hi LIne item dim of the cube increases the loading performance or the query performance. Reagards

  • Acrobat Reader DC Save Folder

    I have just upgraded to Acrobat Reader DC. The problem is that I had a shortcut to a commonly used drive in the default location. However, now this does not help me as it does not show the shortcut. I am also unable to create a shortcut since it does

  • NDATA: How to mask special characters?

    Hello, using NDATA functionality there is a problem if search strings contain special characters like ( or ) or a comma etc. Is it possible to mask the search term? Otherwise there will be an error like "DRG-50901: text query parser syntax error". Ex

  • Is there a way to naming a card reader?

    Hi everyone! I’m new in Java, especially Javacard. I’m using GEMPC Twin smart card reader, GemXpresso211 PK_IS card and OCF1.2 for off-card application. I was able to run sample javacard program and obtain information about registered terminals from