How to empty Serial port buffer ???

Hi!
I am having problems with serial port. I want to clear i
serial ports buffer, but i dont know how to do this. I am receiving NMEA data through that port and every now and then i need to clear it because there are too much data and i dont need them all. Could someone please help me?

Hi,
Take a look at this link.
http://www.sc-systems.com/JavaDoc/Serialio.SerOutputStream.html
flush
public void flush() throws IOException
Causes any buffered data on the output stream to be written. Note: when using txDrain be advised that some OS's (like WinNT) do not provide a timeout on the OS level drain/flush call. In this case if handshake (flow control) is disabled from the far end your txDrain call will block until drain can complete. (i.e. until the handshake state changes). Because of this the default mechanism for flush is to watch the txBuffer. This will allow you to abort a stalled OutputStream since your code will not be locked up at the native level.
Throws: IOException
if an error occurs. Overrides:
flush in class OutputStream
However the above function and the class defining this is not provided by SUN.
I hope this helped.
Roopasri Vittal
Developer Technical Support
Sun Microsystems
http://sun.com/developers/support

Similar Messages

  • Empty serial port buffer?

    Is it possible to empty the buffer of the serial input port without reading from it?

    izze wrote in news:5065000000080000002B8B0000-
    [email protected]:
    > Is it possible to empty the buffer of the serial input port without
    > reading from it?
    You have several options.
    Old standard serial VI's
    Use "Bytes at Serial Port" to get number of byte present and wire it to
    "Serial Port Read" and don't use the data from the VI.
    VISA flush buffer
    The function "VISA Flush I/O Buffer".
    This did not work for me, it took to long time.
    VISA eqvivalent of number of bytes at serial port.
    There is a VISA property to read number of bytes on the receive buffer of
    the serial port. Use this to get number of bytes and wire this number to
    the VISAread function.
    The pro
    blem is that this only works for serial port.
    Use VISA read
    -1- Get VISA timeout value (VISA property node)
    -2- Set VISA timout to 0 (VISA property node)
    -3- make a while loop with
    VISA read function with e.g 1000 bytes to read.
    End the while loop when number of bytes read is 0
    -4- Set VISA timeout back to the value set in step 1
    Rolf

  • Serial Port buffer is annoying.

    Hi, I'm having a hard time dealing with my serial port. When I send a command (for instance, 'Whello', which should display 'hello' on the instrument panel), it doesn't seem to actually send. If I send Whellowoiaydsociahncu4ynriausfaiu(insert at least 80 characters), the display will read "hellowoiayds" (the display is 12 characters wide).
    So how in the world do I tell the COM port to send the command without requiring all 80 characters? Note that I can have it send "W1234567890" and press send 8 times, and the command will be sent on the 10th attempt. I assume the buffer is being filled as I send the short command, and only actually sends after it is full. If I don't send something to the buffer within 2 seconds, the buffer is cleared.
    Is this a computer problem or programming thing? I've tried turning off FIFO, but it didn't help (maybe I have to reboot to make that setting work?)
    Thanks for your help,
    -James

    Have you tried to place a \n (linefeed) at the end of your buffer. Many serial instruments that I am familiar with (note that I am NOT an expert on serial instruments) typically use a line buffer for parsing and don't start to parse until they get a complete line (80 characters) or detect the end of input with a carraige return or linefeed (or both). So, you may consider sending "whello\n" or "whello\r\n".
    Good luck...

  • How to recognize Serial Port Device in Forms.

    Hi All,
    I am using Forms 6i. I want to know how to recognize a serial port device in forms. I have a requirement to recognize the reading of one serial port device into my form in my application and I have to store that reading value into database.
    How can I acheive this?
    Waiting for ur reply.
    Thanks in Advance.
    Gopinath Kona

    hello,
    i havent worked on Linux but have been extensively using it on windows.
    did you try running any code ?
    rohan

  • How to abort serial port VISA from wating.

    Hello All
    How can I abort serial port VISA while wating for a byte to arrive.
    Lets say I have timeout set for 3 min. but I want to cancel it before that , how to do it programatically?
    I tried to set timeout to 0 while wating for data, and it works, but I do not like this method.
    Thanks in advance
    Pawel

    Hi again
    I have made some investigations, and here is what I found:
    None of Serial Port Brake nor Set Time out work while the "VISA read" is active. All property node can access VISA class only when the "VISA read" is finished.
    Therefore, it looks like there is nothing I can do when VISA is active. The only solution is not to allow VISA read.vi to activate. I think I can use your idea and monitor the amount of bytes at the port.
    I wanted to avoid it.
    Thank you for your help
    Pawel

  • How to read serial port only when new data has been sent to it

    I've written this very simple vi to read the serial port whenever the MKS Helium Detector sends a new value.  The timing of new data is controlled directly from the front panel of the MKS instrument.  I thought it was as simple as looking at the "bytes at port", and reading the port only if the value is not zero.  The problem I'm having is that the read function is occuring whether I want it to or not.  Consequently, the "Scan from String" function is returning an error (0) once in a while, because it's reading the serial port as it's being updated (I think).   Apparently, when the port is in the process of being updated, it is not zero.   Anyway, I'm assuming there is a simple fix, but I'm having no luck finding the Easter egg.  Any help would be, as always, very much appreciated. 
    Attachments:
    MKSRead.vi ‏55 KB

    You can approach your problem in a couple of ways. The way you've got it written now, as soon as the number of bytes is non-zero, you read and convert. This means that when a partial string is there, you conversion is nor correct. One way is to wait until non-zero bytes like you do now, and then in another loop, read until the byte count is equal to zero and then do the conversion. You can also read until the cr\lf is detected and then do the conversion on the string. You can also enable the termination character for the read but then you'll have to increase the number of bytes to read to something other than just the number of bytes first available. If the instrument always returns the same number of bytes, you can use that as a constant for the VISA Read. Then the read will terminate whenever the byte count OR the termination character is detected.
    I modified your VI to show you how you might put it in a loop and what for the CR/LF to be detected. You would want to add a timeout to this so that if the character does not show up, the loop will not run infinitely
    Attachments:
    MKSRead_mod.vi ‏68 KB

  • How to read serial port and substring

    I am new for labview .I send data from microcontroller with C languange every 1 minute this codeprintf("T%3.2f,H%3.2f",fTemp_true,fRh_true);
    And I read data with Hyperterminal it show this T29.11,H67.88 I want to show 29.11 and 67.88 only and stroe in database. I study connect serial port in example and I have a question. If I use this code.Can I auto read every 1 minute or this code can read 1 time only and I have to click every 1 minute.How to auto read when I send data to serial port with microcontroller every 1 minute. And I cannot substring 29.11 and 67.88 because %3.2f can show T29.11,H67.88 or T129.11,H100 . and  How can I simple send data to database. Thank you . 

    No, you don't have to click run every minute. You just need to place a while loop around the VISA Read. You could use Wait (ms) but it would be better to use something like the Elapsed Time function and wire the time has elapsed output to a case statement with the VISA Read inside the true case.
    This is one way to parse the string:
    If you have the database connectivity toolkit, you can easily write to a database. There is also something called LabSQL.
    Message Edited by Dennis Knutson on 01-22-2010 01:42 PM
    Attachments:
    Parse String.png ‏16 KB

  • How to access serial port using servlet

    I want to communicate with a microcontroller connected to the serial port of my computer.
    *I am using the following:
    Windows 98 operating system
    Tomcat web server 4.1
    *The directory structure is as given:
    Tomcat 4.1/webapps/myjsp/web-inf/classes/remoteservlets.
    I have placed my jsp files in my jsp folder and classfiles in remote servlets folder.
    **my java program has compiled correctly.**
    ** my simple java application which accesses the serial port works fine.***
    *when I start tomcat I am able to access the sevlet as the servlet responds with the button name i have pressed.
    **** I have also tried the following
    Copied file comm.jar in <JAVA_HOME>\jre\lib\ext
    Copied file javax.comm.properties in <JAVA_HOME>\jre\lib
    Copied file win32com.dll in <JAVA_HOME>\lib and also in c:\windows\system32 and c:\windows\system
    ***************which helped me do away with errors.
    still I don't get any output. I dont get any errors either.
    PLEASE HELP. URGENT. i am at my wits end.
    Thank you.

    Servlet is the one which runs in the server side...if u want to comunicate with the serial port of the server in which ur servlet is running can be done but making use of Communication api available....
    U can download the Api from http://java.sun.com/products/javacomm/index.jsp
    There are three levels of classes in the Java communications API:
    High-level classes like CommPortIdentifier and CommPort manage access and ownership of communication ports.
    Low-level classes like SerialPort and ParallelPort provide an interface to physical communications ports. The current release of the Java communications API enables access to serial (RS-232) and parallel (IEEE 1284) ports.
    Driver-level classes provide an interface between the low-level classes and the underlying operating system. Driver-level classes are part of the implementation but not the Java communications API. They should not be used by application programmers.
    regards
    shanu

  • "how to read serial port using labview 6.0"

    sir i am doing a project and is in a need to extract data from serial port. can anyone help me

    This link, and the links from it, are a great place to start:
    http://zone.ni.com/devzone/conceptd.nsf/webmain/8DECBF3E0B714BF3862568F9006E7851?opendocument
    2006 Ultimate LabVIEW G-eek.

  • How to detect serial port

    CommPortIdentifier portId;
              Enumeration en = CommPortIdentifier.getPortIdentifiers();
              Vector v=new Vector();
              while (en.hasMoreElements())
                   portId = (CommPortIdentifier) en.nextElement();
                   if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                             v.addElement(portId.getName());
              }

    refer this URL
    http://www.java2s.com/Code/Java/Development-Class/ReadfromaSerialportnotifyingwhendataarrives.htm
         * Project                     :
         * Class                     : GUIFrame.java
         * Purpose                    :
         * Date_Created               :
         * @ Version 1.0
    import javax.swing.JFrame;
    // import javax.swing.JPanel;
    import javax.swing.JMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import java.awt.event.*;
    import javax.comm.*;
    import java.awt.*;
    import javax.swing.*;
    // import javax.swing.border.TitledBorder;     
    public class GUIFrame extends JFrame implements ActionListener
         JButton connectPort;
         JComboBox combo;     
         //JButton baudRate;
         //JComboBox baudRateCombo;     
         public JTextArea textArea;     
         JButton sendData;
         public SerialConnection serialConnection;
         public GUIFrame()
              setLayout(null);
              setTitle("First Frame");
              serialConnection = new SerialConnection();                    
              setJMenuBar(createMenuBar());
              combo = new JComboBox();
              combo.setBounds(50, 50, 80, 25);
              listPort();
              combo.addActionListener(this);
              connectPort = new JButton("Connect");
              connectPort.setBounds(150, 50, 100, 25);
              connectPort.addActionListener(this);
              sendData = new JButton("Send Data");
              sendData.setBounds(150, 150, 100, 25);
              sendData.addActionListener(this);
              textArea = new JTextArea();
              textArea.setBounds(300, 300, 400, 300);
              textArea.setFont(new Font("sansserif",0,18));
              add(connectPort);
              add(combo);
              add(sendData);
              add(textArea);;
              setSize(400, 300);
              setVisible(true);
              addWindowListener(new MainWindowAdapter());
         public static void main(String arg[])
              System.out.println("Hi");
              new GUIFrame();
         public JMenuBar createMenuBar()
              JMenuBar menuBar = new JMenuBar();
              JMenu fileMenu = new JMenu("File");
              JMenuItem connectMenuItem = new JMenuItem("Connect");
              connectMenuItem.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae){
                        try{
                             if(serialConnection.portName == null){
                                  serialConnection.portName = combo.getSelectedItem().toString();
                             serialConnection.openConnection();
                        catch(Exception ex)
              JMenuItem disconnectMenuItem = new JMenuItem("Disconnect");
              disconnectMenuItem.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae){
                        try{
                             serialConnection.closeConnection();
                        catch(Exception ex)
              fileMenu.add(connectMenuItem);
              fileMenu.add(disconnectMenuItem);
              menuBar.add(fileMenu);
              return menuBar;
         public void listPort()
              CommPortIdentifier portId;          
              java.util.Enumeration enumeration = CommPortIdentifier.getPortIdentifiers();
              while(enumeration.hasMoreElements())
                   portId = (CommPortIdentifier)enumeration.nextElement();
                   if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                        if(!portId.isCurrentlyOwned())
                             combo.addItem(portId.getName());
         public void actionPerformed(ActionEvent ae)
              if(ae.getSource() == connectPort)
                   System.out.println("Connect is clicked");     
                   try
                        if(serialConnection.portName == null)
                             serialConnection.portName = combo.getSelectedItem().toString();
                        serialConnection.openConnection();
                   catch(Exception ex)
              if(ae.getSource() == combo)
                   System.out.print("Port Name = " + combo.getSelectedItem().toString());
                   serialConnection.portName = combo.getSelectedItem().toString();
              if(ae.getSource() == sendData)
                   byte b[] = new byte[5];
                   b[0] = (byte)0xaa;
                   b[1] = (byte)0xbb;
                   b[2] = (byte)0xcc;
                   b[3] = (byte)0xdd;
                   b[4] = (byte)0xee;     
                   try
                        serialConnection.getOutputStream().write(b);
                        display(b);
                   catch(Exception ex)
         public class MainWindowAdapter extends WindowAdapter
              public void windowClosing(WindowEvent win)
                   dispose();
                   System.exit(0);
         public void display(byte[] b)
              for(int i=0; i< b.length; i++)
                   textArea.append(Integer.toHexString (b[i] & 0xff) + " ");
              textArea.append("\n");
         * Project                     :
         * Class                     : SerialConnection.java
         * Purpose                    :
         * Date_Created               :
         * @ Version 1.0
    import javax.comm.*;
    import java.io.*;
    public class SerialConnection
         private OutputStream os;
         private InputStream is;
         private CommPortIdentifier portId;
         public SerialPort sPort;
         private boolean open;
         public String portName;
         SerialConnection serialConnection;
         public SerialConnection()
              serialConnection=this;
              PortHandler portHandler = new PortHandler(serialConnection);
              portHandler.init(serialConnection);
         public void setOutputStream(OutputStream os)
              this.os=os;
         public OutputStream getOutputStream()
              return os;
         public void setInputStream(InputStream is)
              this.is=is;
         public InputStream getInputStream()
              return is;
         * A Method to open the SerialConnection
    public void openConnection() throws Exception
              try
                   portId = CommPortIdentifier.getPortIdentifier(portName);
              catch (javax.comm.NoSuchPortException e)
                   System.out.println("noPort : "+e);
              try
                   sPort = (SerialPort)portId.open("port", 3000);               
                   open = true;
              catch (javax.comm.PortInUseException e)
                   throw new Exception();
              try
                   setOutputStream(sPort.getOutputStream());
                   setInputStream(sPort.getInputStream());               
                   System.out.println("IO stream is opened");
              catch (java.io.IOException e)
                   sPort.close();                    
         *A Method to Close the port and clean up associated elements.
         public void closeConnection()
              // If port is already closed just return.
              if (!open)
                   return;
              if (sPort != null)
                   try
                        this.os.close();
                        this.is.close();
                        System.out.println("IO stream is opened - CloseConnection");
                   catch (java.io.IOException e)
                        System.err.println(e);
                   sPort.close();
                   System.out.println("Port is closed");
              System.out.println("Flag Open - 1 : " + open );
              open = false;
              System.out.println("Flag Open - 2 : " + open);
         * Send a one second break signal.
         public void sendBreak()
              sPort.sendBreak(1000);
         * Reports the open status of the port.
         * @return true if port is open, false if port is closed.
         public boolean isOpen()
              return open;
         * A Method to add the event listener to the SerialPort
         public void addEventListener(java.util.EventListener listener)throws Exception
              System.out.println("Is not in opened state");
              if(isOpen())
                   System.out.println("Is in opened state");
                   try
                        sPort.addEventListener((javax.comm.SerialPortEventListener)listener);
                   catch (java.util.TooManyListenersException e)
                        sPort.close();               
                   // Set notifyOnDataAvailable to true to allow event driven input.
                   sPort.notifyOnDataAvailable(true);
                   // Set notifyOnBreakInterrup to allow event driven break handling.
                   sPort.notifyOnBreakInterrupt(true);
                   // Set receive timeout to allow breaking out of polling loop during
                   // input handling.
                   try
                   sPort.enableReceiveTimeout(50);
                   //sPort.enableReceiveTimeout(-1);
                   catch (javax.comm.UnsupportedCommOperationException e)
                        e.printStackTrace();
                   // Add ownership listener to allow ownership event handling.
                   portId.addPortOwnershipListener((javax.comm.CommPortOwnershipListener)listener);
         import javax.comm.*;
         public class PortHandler implements SerialPortEventListener,CommPortOwnershipListener{
              public SerialConnection serialConnection;
              public PortHandler(SerialConnection serialConnection)
                   this.serialConnection=serialConnection;
                   try{
                        serialConnection.addEventListener((SerialPortEventListener)this);
                        System.out.println("New Port Handler is called");
                   catch(Exception e)
                        System.out.println("Exception PortHandler(); " +e);
                        e.printStackTrace();
                   // Add this object as an event listener for the serial port.
                   System.out.println("PortHandler is initialised...");
              public SerialConnection getConnection(){
                   return serialConnection;
              public void setSerialConnection(SerialConnection serialConnection){
                   this.serialConnection = serialConnection;
              public void init(SerialConnection serialConnection){
                   setSerialConnection(serialConnection);
              public void serialEvent(SerialPortEvent e){
                   System.out.println("Event Initialised");
                   //Determine type of event.
                   switch (e.getEventType())
                        case SerialPortEvent.DATA_AVAILABLE:
                             try{
                                  readData();                              
                             catch(java.io.IOException e1)
                                  System.out.println("IO Excep "+e1.getMessage());
                                  e1.printStackTrace();
                             catch(Exception e1)
                                  System.out.println("Exception from Serial Event "+e1.getMessage());
                                  e1.printStackTrace();
                        break;
                        case SerialPortEvent.BI:
                        break;
              public void readData() throws java.io.IOException
                   byte b[]=new byte[8500];
                   int i=0,selectOption=0;
                   int newData=0;
                   int doubleLength=0;
                   int length=0;
                   // String mid="",strLen="";
                   while (newData != -1)
                        try     
                             System.out.println("getInputStream().available() : " + serialConnection.getInputStream().available());
                             newData = serialConnection.getInputStream().read();
                             System.out.println("newData\t"+newData);
                             if (newData == -1)
                                  System.out.println("\n End of the File\n");
                                  break;
                             if(i==0){
                                  b=(byte)newData;
                                  System.out.print("\n MSg ID \t= " + Integer.toString(newData&0xff,16)+"\n----------------------------");
                                  if(b[0] == (byte)0x00)
                                       i=-1;
                                       i++;
                                       continue;
                                  i++;
                                  //System.out.println("Method is called - selectOption : " + selectOption);
                                  continue;
                             if(i==1)
                                  b[i]=(byte)newData;
                                  System.out.print("\n Length =\t"+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                  length=newData;
                                  if(length == 0)
                                       i=0;
                                       continue;
                                  i++;
                                  continue;
                             b[i]=(byte)newData;
                             if((b[0] == (byte)0x07) && (i == 2) || (b[0] == (byte)0xaf) && (i == 2) || (b[0] == (byte)0xec) && (i == 2)
                                  || (b[0] == (byte)0x5c) && (i == 2) || (b[0] == (byte)0xbe) && (i == 2) )
                                  String string = String.valueOf((byte)b[0]);
                                  String strLen = Integer.toString(b[2]&0xff,16) + Integer.toString(b[1]&0xff,16);
                                  System.out.println("\n\nLength String = " + strLen + "\n\n");
                                  java.math.BigInteger bi=new java.math.BigInteger(strLen,16);
                                  strLen = bi.toString();
                                  doubleLength = Integer.parseInt(strLen);
                                  System.out.println("\nLength int = " + doubleLength + "\n");
                                  //System.out.println("Method is called");
                             i++;
                             // Added by Siva on Jan 06
                             switch(selectOption)
                                  case 0:
                                       if(i>length+1)
                                            try
                                                 b[i]=(byte)newData;     
                                                 System.out.print("\nThe Last Byte =\t"+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                                 System.out.print("\n"+i+" i Value =\t"+Integer.toString(newData&0xff,16));
                                                 System.out.println("\n----------------------- FINISHED------------------------------");
                                                 // service(b);     
                                                 System.out.println("\n----------------------- After Service------------------------------");
                                                 i=-1;
                                                 i++;               
                                                 continue;
                                            }catch (Exception e)
                                                 System.out.println("Exception in calling service 0:"+e.getMessage());
                                                 e.printStackTrace();
                                                 b[i]=(byte)newData;
                                       System.out.print("\nMSg ID \t= "+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                       break;
                   }catch (java.io.IOException ex)     {
                        System.err.println("Abstarct Port handler Exception\t"+ex);
                   catch(Exception e1)
                        System.out.println("Exception from Read Data "+e1.getMessage());
                        e1.printStackTrace();
                   System.out.println("-----------------------------");
              public void ownershipChange(int type){
                   if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED){
              public void destroy()     
                   try{
                        serialConnection.closeConnection();     
                   }catch(Exception e){
                        System.out.println("Exception 2:"+e);     
                        e.printStackTrace();
              public void finalize(){
                   destroy();

  • How to remove serial port driver

    Hi,
    I am developing test driver for serial port. I can't able to remove existing driver (su) from solaris 8.
    I tried "rem_drv su" and rebooted system. system does not came up again and generates panic (core dump). Could anybody help me regarding this problem.
    Thanks in advance,
    -Mahantesh

    Instrument drivers are in the "LabVIEW\instr.lib" folder. Each driver should be in its own folder. To delete it, just delete the folder. You may need to update the palette menu to reflect the removal of the directory.
    Also, what do you mean by NI installing the driver? Are you referring to using the Help -> Find Instrument Driver? If so, what did you enter in the search criteria? Leybold isn't even in the list of manufacturers.

  • How to read COM port in Developer 4.5 or 6i?

    Dear all
    Have any one please let me know how to create forms with Developer6i join Barcode Scanner in COM port?
    At the time, I import OLE Library interface to be developer's package body (Component MSCOMM32.OCX) It isn't efficiency.
    Have any one Please let me your method and how to ?
    Thanks a lots.

    Parallel threads are easy in Labview.  You just create two loops where the output of either loop is not connected to the input of the other.  Without this data dependency, the two loops run in parallel.  See the attached vi, my producer-consumer template.  Replace the random number generator in the top loop with your serial port code.  Put your other processing code in the bottom loop.  Use the queue to pass info from one loop to the other.  You can signal the lower loop when the serial port receiving is done by putting something on the queue that signifies the completion (like a "done" string).  Your lower loop will constantly check the queue, looking for the "done" string.  You can use a boolean if you remove the string wires and replace them with boolean types.
    Bytes at Port will look at the serial port buffer and report the number of bytes sitting there waiting to be read.  Call it before you read, and pass the number from bytes at port to the read function.  Search the LV examples for serial port and you will see how bytes at port is used.
    Message Edited by tbob on 10-04-2005 03:51 PM
    - tbob
    Inventor of the WORM Global
    Attachments:
    ProducerConsumer.vi ‏40 KB

  • Labview needs 2 goes to start the serial port

    Hi,
    When I use Labview with the serial port handlers, beit VISA or the
    serial routines, I always have to run my external device
    (microcontroller based system connected through the serial port) and
    then run Labview but the first time I run it it never works. I then
    need to reset my microcontroller system and run my Labview program
    again and it runs fine, and every time after that.
    Has anybody else noticed this and what can I do to fix it?
    Ken

    Your statement "it never works" is kind of vague. How doesn't it work? Do you get an error, garbage data, no data, or what? Is this system always spitting out data that needs to be synchronized? When you have it working, stop the LabVIEW program and restart it right away, do you have the same problem or do you only see it after stopping the system and restarting it? Aside from recomending that you do a flush of the serial port buffer before sending and receiving data from LabVIEW, more details would help to provide some sort of solution.

  • Serial Port and MSC1200

    Hello, I´m tried connect the serail port at MSC1200 microcontroller. The program performed perfect, but no message is show in string variable.
    Anybody know works with any project like this?
    Attachments:
    programa.JPG ‏60 KB

    I guess it's not perfect if you don't get any data.
    You have an indicator for number of bytes read. Is it greater than 0? If it's not, then the reason the string is empty is because there was nothing in the serial port buffer to read. Is the micro constantly sending out data? Have you tried using Hyperterminal to read the micro. If it is constantly transmitting, then the Hyperterminal scree will just fill up as long as you are connected. If the micro requires you to first send a command to request data, then you need to do a VISA Write of that command before doing the read.

  • Polling serial port

    Hi friends,
    I am doing one program to read the serial port.I want to do that continuously until the program stops.It should read and store the data comes into the serial port buffer....
    code:
                       public void serialEvent(SerialPortEvent event) {          
                                                System.out.println("before serialEvent");          
                                                            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:     
                                                                          System.out.println("Data available:");     
                                                                   byte[] readBuffer = new byte[20];      
                                                                    try {               
                                                                              while (inputStream.available() > 0) {
                                                     System.out.println("inside inputstream reading");
                                                    int numBytes = inputStream.read(readBuffer);                                          System.out.println("Reading...");     
                                                     // if(readBuffer[readBuffer.length - 1] == 0x41)
                                            // System.exit(0);     
                                                           if (readBuffer[numBytes] == 0x41)
                             System.exit(0);          
                                                                   String str = new String(readBuffer);
                                                   System.out.print(str);          
                             } catch (IOException e) {     
                                                         System.out.println(e);     
                                                             System.out.println("after inputstream reading");               break;          }     }
    --------------------------------------------------------------------------------This is one i found while searching for event driven...But not understanding how it is reading and writing to file....
    Please anybody help me
    thanks

    Hi somnath,
    did you see the shipped examples (Basic and Advanced Serial Write and Read)? You can use a loop and read the "Bytes at port" property. There you can count how many bytes you already have received. After you have your data, you can leave the loop, depending on what you need then.
    Mike

Maybe you are looking for

  • 10.4.8: DVD Player & external drives

    I just posted this to another thread, and then realized that thread was marked "Answered." So I'm starting this new one. My problem began after I upgraded to 10.4.8 (via Software Update) this past weekend. For some reason, DVD Player will not work wi

  • Mms issue

    I can not send or receive pic text. I have checked settings. I have completed over the air activation and removed battery. I receive error message service not activated on network.. I have called in and went to the store.

  • Comments link not showing

    My comments link isn't showing on "Amanda's Blog" where it says "read more... 0 comments"? It does show in iWeb, but not on the published website? It's working fine on "Jon's Blog"?

  • Connecting UME to SQL DB.

    Hi All, We have to implement the following secnario. We want to replicate the UME roles in SQL database. An application A has certain number of iviews and this application is visible to all the users. Whenever the user logs in the portal, he receives

  • Is this cash sales?

    Hi Experts, If orders are placed on the internet and paid with credit card, followed by delivery confirmation and then the customer receives the goods delivered by DHL, is this considered cash sales? I mean unlike a convenient store using POS system,