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

Similar Messages

  • 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

  • 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...

  • 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.

  • Reading/writing to serial port w/ VISA in Labview

    I'm writing a Labview program to control and to read data from a Varian vacuum pump controller. It is connected to the serial port in my computer, and I have been trying to open a VISA session to communicate with the instrument. So far, however, the computer cannot see the instrument--I get the same error messages reading and writing to the instrument as I do to an empty serial port. Does anyone have any suggestions on what the problem might be? Thank you.

    There are a lot of possiblities. Is the cable correct? You probably need a crossover cable (TX and RX) swapped. You also need to check and make sure the serial ports on both ends are set the same (i.e. baud rate, handshaking, stop bits, etc.). Make sure that the port is enabled. I've seen people try to use a comm port only to find that a modem card installation caused the port to be disabled. You could also try using hyperterminal to talk to the instrument. If you can communicate there, you can eliminate any hardware problem.

  • 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.

  • 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

  • Erreur 63 : Serial Port receive buffer overflow

    Hello
    J'ai un problème avec les blocs get.vi dans mon programme
    Je fais une boucle for qui compte les heures et après environ 200-300 fois j'ai une erreur qui survient (erreur 63 : Serial Port receive buffer overflow)
    A l'intérieur de la boucle j'exécute la commande get.vi plusieurs fois pour différents cas à chaque incrémentation de 1h.
    Merci d'avance
    En annexe, mon vi principal
    Pièces jointes :
    regulation.vi ‏462 KB

    Du fait de certains vi manquants je ne peux pas executer votre code, Parmis le nombre important de vi GET HTTP, savez-vous lequel est responsable de l'erreur ?, et est-ce toujours le même ?
    L'erreur renvoyée concerne le port série, quelle est la configuration de ses buffers d'entrée / sortie (visible dans le gestionnaire de périphérique)
    Cordialement,
    Vincent.O
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    Été de LabVIEW 2014
    12 présentations en ligne, du 30 juin au 18 juillet

  • I want to write and read a hex file from the flash buffer of the microcontroller through the USB serial port

    hello sir,
    I am developing a GUI screen from that i want to write and read a hex file from the flash buffer of the microcontroller through the USB serial port. the driver i am using is FTDID2XX driver.if anyone having examples of loading file through serial port.Please reply me .
    Thanks

    Looks like you should post your request in the LabVIEW forum, this one here preferentially is for LabWindows/CVI...

  • Warning 1073676424 from VISA Set I/O Buffer Size.vi on a serial port

    I am porting an application from LabVIEW 6.1 on Windows to LabVIEW 7 on OS X (Mac). It was very painless except some GUI modifications.
    The application involves 30 KB data from a instrument through a RS232 serial port. I found the application misses data whenever the computer is busy. The problem came down to the unchanged buffer size.
    Attempt to change the buffer size of a serial port with "VISA Set I/O Buffer Size.vi" fails with a warning of 1073676424 (The specified I/O buffer is not supported). Even the example vi from NI web site "Advanced _Serial_Write_and_Read.vi" has the same warning.
    I wonder what I am missing.

    Under the hood VISA is using the POSIX serial interface for Mac OS X (same as for Linux and Solaris). This interface does not support changing the buffer size. Hence, the buffer size is fixed to the internal OS buffer size. The only thing that changing the buffer size will do (for the out buffer) is to have VISA not flush the data after every write. This is a limitation in the serial API for Mac OS X. Therefore, VISA reports a warning.

  • Problem in using serial port.

    I am using serial port to get data from a fusion splicer. The number of bytes at the port is 4096 but the read buffer of VISA read is empty. I am reading the same number of bytes. Can any one tell me what is the maximum size of VISA Read buffer? I am trying to put the contents of the buffer in a file. I am using labVIEW 6.1 on linux.I am also attaching the VI.
    I also noticed this problem...If I read the number of bytes in the serial buffer many times, sometimes it reads it as 0 and I have to keep trying until it reads this 4096 bytes.
    Thanx for any help.
    S.Vijayalakshmi
    Attachments:
    serail_comm.vi ‏52 KB

    Hey Viji,
    In your application it looks like you are just checking to see how many bytes are at the serial port. Is it possible that your application is check for the serial data at the port before the data actually gets there. If you are looping this code as a subVI or just running it over and over it is possible that one of the iterations could occur faster than your device can write the information to the bus. In this instance you are checking the number of bytes at the port and there might not be any there yet. In this case the port reads 0 as you have designed it.
    If you want the read function to wait and always read 4096 then don't wire the bytes at port to the read function. Just wire a constant/control equal to 4096 to the read function instead o
    f the bytes at port. In this case, if there are not any bytes at the port the read function will wait for the bytes to show up or until the timeout period is reached.
    I would also, suggest lowering your time to something more reasonable, because if your instrument quits transmitting your application is going to wait for 33 minutes. That is a long time for a program to hang.
    I hope this helps out.
    JoshuaP
    National Instruments

  • Writing to serial port

    I currently send ASCII characters to a serial port. I have not errors reported back. Everything appears to be error free, except that the device that I am trying to control does nothing. The device being controlled does not send anything back to the pc. The connection is strictly a one way connection. Do you have to send a carriage return or something to get the ASCII characters to "push" out of the buffer? - Sorry I don't have access to my code at the moment.

    A portion of my code is below. What does the 'flush'
    do? I thought it just emptied out the buffer.
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier)
    tIdentifier) portList.nextElement();
    if (portId.getPortType() ==
    ortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1"))
    .equals("COM1")) {
    try {
    serialPort = (SerialPort)
    portId.open("SimpleWriteApp",
    d.open("SimpleWriteApp", 2000);
    } catch (PortInUseException e)
    ortInUseException e) {}People get life for this crime!
    try {
    outputStream =
    outputStream =
    tStream = serialPort.getOutputStream();
    } catch (IOException e) {}So you now have two life sentences to serve.
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch
    } catch
    } catch (UnsupportedCommOperationException e) {}Sorry, three life sentences to serve.
    try {
    outputStream.write(rightString.getBytes());
    } catch (IOException e) {}You get the prize! Four life sentences from a short bit of code.
    }P.S. You should really use the COMM api for writing to serial ports.

  • Serial Port Overrun

    Hello All,
    I am developing Teststand sequences which run Labview code. I use 1 labview vi to configure and drive the serial port, the first call configures the serial port. The second call writes a message and reads the response, the last call releases the resource. When running the call write&read I intermittently receive the error shown in the attached jpg, this causes my whole sequence to lockup till I return to restart the test. I need to run this repeatedly overnight so its a problem. I have a feeling this isnt so much a serial port overrun problem as a hardware clash ( i also configure and run a camera ).
    I have spotted a number of posts a on this same topic but I havent yet found a soultion only advice, which I have already tried.
    Help greatly appreciated
    Regards Chris
    Attachments:
    Serial Port Error.jpg ‏63 KB

    Are you familiar with handshaking?  There were several posts on this subject recently.  The end device is sending data faster than your computer and Labview program can handle.  You need to implement handshaking.  There are two types of handshaking, software and hardware:
    Software, also called XON/XOFF.  With this setup, when the computer serial port incoming buffer gets nearly full, it automatically sends an XOFF command (don't worry about what it is since it is automatic).  The XOFF command tells the endpoint device to stop sending data.  When the buffer gets near empty, the computer sends an XON command.  The endpoint device then starts sending data again.  For this protocol, the endpoint device must be able to support this, and must be configured to use this type of handshaking.  You would have to read the manual to find out how to set it up.  For the computer end, you can set it up with an option for the configure serial port function on the input labeled "Flow Control".  Right click on this terminal and select Create - Constant.  A text ring will be created.  Select XON/XOFF in the text ring.
    Hardware, also called RTS/CTS.  Same principle in that the computer signals the endpoint when to stop sending data and when to start again.  However, instead of sending a command, the computer drops the CTS line (Clear To Send).  Actually, the endpoint device raises the RTS (Request To Send) when it wants to send data, and the computer responds with raising CTS if it is ready to receive data.  When the buffers get full, the computer drops CTS which tells the endpoint to stop sending data.  When the computer is ready to start receiving again, it raises CTS.  Again, both sides must be configured for this.  The text ring has an RTS/CTS selection.
    You will have to read the manual on your endpoint device to see what it supports and how to configure it.  Warning:  If sending binary data, DO NOT use XON/XOFF.  The binary data may just happen to form a pattern that looks like XOFF, and everything will lock up because XON will never be sent.  So if binary data is being transferred, use RTS/CTS.  If normal ASCII characters are being sent, you can use either protocol.
    - tbob
    Inventor of the WORM Global

  • Serial port init frequency

    I currently use LV to dialog with an RS232 device via the serial port.
    How often does I have to re-init he serial port?
    For the moment, I do it each time I want to send a string to the device.

    perform a "dummy" read of the serial port and throw away the data before
    sending the serial command.
    that way you know the buffer is empty before you expect data.
    Stu
    "Zen" wrote in message
    news:[email protected]..
    >
    >
    > Johannes Niess a écrit :
    >
    > >
    > > In theory: Once. It depends on whether you have an initialisation
    > > phase or want to avoid it. If you don't need high speeds, you can
    > > leave it the way it is.
    >
    > I send a string everery two seconds, and raed the reponse from the
    > device. I just don't know if the serial buffer is emptied before
    > receiving the response string. If not, there might be left old caracters
    > causing a wrong response string.
    Stu McFarlane
    Viewpoint Systems, Inc.

  • A problem about reading from serial port

    Hi,
       I just sent '0x03' from MCU to PC continuously, and then sent  '/n' as a stop character after every '0x03'. I use labview to read the data. The problem is when it get two '03' it get a '0', another two '03' and another a '0'. I don't know where is the '0' from?
      PS: Hyper terminal can display natrually.
       Thank you! 
    帖子被hengfo在08-08-2007 10:14 PM时编辑过了
    Attachments:
    serial read.vi ‏36 KB

    I think the problem may be the loop reading the serial port is running too fast.  There is no timing delay in the loop, so you are reading it as fast as you can, and probably faster than the device is sending data.  So sometimes the buffer is empty, and then the empty string gets converted to a numeric zero.  The way to know for sure is to put an indicator on the error wire coming out of the serial port read.  I bet you will see errors about the read buffer being empty.
    Put a wait timer in the loop to slow down the execution just slightly.  This is a good idea so that LV doesn't eat up all the CPU resources.  Look at the example for Basic Serial Write and Read.  You may want to have a loop ahead of the read that waits until there are a certain number of bytes at the port before it reads the serial port.  You may want to put a loop around the serial port that waits until a valid number is read in before it exits the loop and goes to the numeric conversion.
    Message Edited by Ravens Fan on 08-09-2007 08:50 AM

Maybe you are looking for

  • Name of the file to be sent to the field in RFC

    Hello Experts, I am doing a File - RFC scenario. I need the scenario in such a way that the name of the sender file should be placed in one field of RFC What should I map with the field of RFC to hold filename in MM? how do I achieve this? Regards, N

  • CALL_TRANSACTION in Background

    Hi. We want to execute CALL_TRANSACTION SP12 in background job. And we did Migration from 46B to ERP2005. Before Migration we could do it normaly, but now we can't do it. In addition, we can do it on foreground, but we can't do it in background,----

  • Instead of text cursor to edit, I keep getting a "delete" box.

    Ever since the last update, and whenever I try to edit a text, I touch the screen at an approximate point in the text from where I want to start positioning the cursor from, a "delete" box appears instead of the blue cursor triangle. This is not what

  • Want to transfer data to another cpu

    got a new computer, want to transfer data from this computer to the new one i proceeded to sync up - created an account (on this computer not the new one) the new computer is asking for the code number from this computer but i am not able to find tha

  • Message Mapping - Dump

    I got the following dump, when I executed the Message Mapping. Eventhough I have fixed the problem, I am not quite sure to read the dump, i.e by reading the dump I was not sure which FIELD has caused the Dump. could some one help me , how I can read