TCP Read undifined number of bytes

Hello LabVIEW RT users
I'm trying to convert a java application to my LabVIEW RT Smart Camera
In my camera I have a working TCP server which reads and writes some data to/from a robot. My problem is that in LabVIEW i have to specify who many bytes I'm reciving to get it to work. But in my Java application the BufferedReader took care of this. I can't control what the robot is sending but it could be things like these strings
GET X
SET R 1
SET X 443
SET X 11
GET START
Somone who knows how I best handle this problem? I have tried to change the mode of the TCP read to CRLF but without succes

If you have 1MB if random binary data, is highly likely that there will be a CRLF embedded somewhere by chance, so that won't work. None of your vague comments and suggestions make any sense so far. This is most likely a very simple problem that you are way overthinking and trying to overengineer. Billions of bytes of variable lenght data are transmitted every second across the world and nobody else seems to have these problems.
Please be more specific about your application:
Where is the data coming from?
Is it also LabVIEW and do you have control over the sending program?
How easy is it to tell if it is binary or formatted?
Can you tell from the data pattern once an entire set is received?
how long are the pauses between datasets?
What happens to the data after it is received? (stream to disk, scan, parse, etc.)
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Reading unknown number of bytes !

    Hi all !
    I am trying to read unknown number of bytes from the socket.Meanwhile I need to process the bytes depending on the message type in the header.I get messages like this header,body,header,body header,body header,body.....the message type is specified in the header.Each message type has different body size.So depending on that I have to read the next few bytes from the socket....say 300 or 600 depending the on the message type in the header.I get the bytes continioulsy like this.Since I cannot read byte by byte due performance reason is there any other way to do that.....any help will appreciated
    sash

    A simple workaround is to use a java.io.PushbackInputStream
    Read enough bytes to get the header, parse the header bytes, and push the remainder back into the stream to be read as the body.

  • Reading unkown number of bytes

    Hi all !
    I am trying to read unknown number of bytes from the socket.Meanwhile I need to process the bytes depending on the message type in the header.I get messages like this header,body,header,body header,body header,body.....the message type is specified in the header.Each message type has different body size.So depending on that I have to read the next few bytes from the socket....say 300 or 600 depending the on the message type in the header.I get the bytes continioulsy like this.Since I cannot read byte by byte due performance reason is there any other way to do that.....any help will appreciated
    sash

    Assuming you have a consistent header size and format, you can just read that in one call. I prefer sticking the size of body in the header. That way I can pluck that value out of the header and use it for the next read.

  • How to get the number of bytes at TCP port

    Hi all,
    How to get the number of bytes to read at the TCp port...as someone had suggested in some forum we do read the number of bytes first and then pass this...
    but we get a problem when we have FF data in this...because then it sends 2 FF data...and cause of this we skip the last data...is there any solution for the same?

    Hi
    In LabVIEW you don't have the same property as in serail port.
    You havn't "Byte at TCPIP port".
    if you developp a protocol, one soltion, is to send the size to read.
    Ingénieur d'Application / Développeur LabVIEW Certifié (CLD)
    Application Engineer / LabVIEW Certified Developer (CLD)

  • TCP Read w/ #bytes=4 returns wrong data.

    On an initial TCP Read to a just-open connection, I can read any number of bytes, always getting the first n bytes from the arriving data. Except when I try to read 4 bytes! Then I get 4 bytes, but they're the seventh through ninth bytes, not the first four. Haven't found any other number that gives problems - 1,2,3,5,6,7,8,16,40,1020,etc. all work fine. Ideas?

    You may want to try runnig the Data Client and Data Server example VIs which ship with LabVIEW and see if they work on your system. The Client example actually reads in 4 bytes every time. I ran it and it works fine, so if yours exhibits the behavior you've been seeing, then the problem could be with your connection. Otherwise, if the example does work, then it could be somewhere in your code. Let us know what you find.
    J.R. Allen

  • TCP/IP Read - How do I find the number of bytes available

    It appears that this is not directly possible. I am trying to get around
    this by doing a tcp/ip buffered read with a very short timeout (0 or 1ms).
    In theory it seems like I should be able to keep making the read call until
    the exact number of bytes (4 in this case) pops out. It mostly works but
    every so often hangs for some period of time and then resumes getting the 4
    byte packets. Anybody have any idea what is going on?

    The first thing I'm thinking of is that your delay is too short. Also, try to increase the packet length or use Immediate Mode (even CRLF MODE if you're transmitting text).
    Another idea (if your application really needs that and you have LV / Windows) is to use MS Winsock Control (wait for DataArrival event and read BytesReceived).
    Anyway, tune in your communication (packets and delays) taking in account details about your network or modem.
    Good luck!

  • How to get the number of bytes at ethernt port using tcp/ip?

    I have data with variable sizes.I am getting the data from another sytem using software C.
    How can I get the exact number of bytes coming at the port before using the read command so that the no. of bytes at port has to be given as the input to the tcp read vi?

    Philippe_RSA wrote:
    So may responses saying your question is wrong..... typical of this site, and no decent answer after 5 years !
    The answer I have used is to use a call library function:
    short int ioctlsocket(unsigned long socket, unsigned long fionread, unsigned long *len);    
    where fionread is a windows defined constant =  4004667F
    The socket can be obtained from using the       TCP Get RAW NET OBJECT.vi   which comes with Labview (even as far back as version 7).
    Good luck.
    A protocol requiring such a hack is IMHO very poorly designed. You should always have some way on the wire to determine the data stream size. If the data is fixed size that would be inherent to the protocol, if it's variable sized there should be a fixed size header or a known message termination indication that can be used to determine how to read the rest of the message.
    As a side node, I do consider the existence of VISA Bytes at Serial Port a big error, and that is most likely where this question originally came from. Use of "bytes at port" to decode a protocol will ALWAYS lead to protocol errors sooner or later, and code that is unneccessarily complicated to force the routine to deal with the asynchonous reading of the "bytes at port" into the protocol decoding.
    If a protocol can't be decoded with fixed size reads, fixed size reads with following variable size reads determined from information in the header, or a specific message termination indication, then it is very badly flawed.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Easily read strings while tracking the number of bytes read?

    Hi all,
    I'm after a way to easily parse and read strings from a file, while also being able to check (at any point) how many bytes have currently been read from that file.
    I currently use the following for the string processing:
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String str = null;
    while ((str = in.readLine()) != null)
      // process the string
    }That's all fine, but the files I'm reading can be very large (multi GB) so obviously it can take a while to read them. During this time I pop up a progress bar, and attempt to track the progress of the read. The files I'm working with just now come with a header on the first line that states how many "somethings" (that I happen to be looking for) will appear in the file. I can use that number to set the maximum value for the progress bar, and update its current value as I find them.
    However... I'm also about to start working with files that don't contain this information. I've thought of two ways of knowing how much work has to be done in advance of the read so the maximum value for the progress bar can be set:
    1) Quickly count the number of lines in the file without doing any processing. This works, but can still take some time for large files, even with more efficient reading algorithms.
    2) Use File.length() to set the maximum to be the number of bytes that will read.
    I'd like to use 2), but can't work out a way to use simple String based file parsing (as in the code above), but also be able to know how many bytes have been read so far. Using this code means I don't have to worry about end of line terminators, charset encoding, etc - the Reader does it for me.
    Any suggestions?
    Thanks

    import javax.swing.*;
    Component parent; // might be null, or your JFrame
    String message; // message to display in the progress bar
    BufferedReader br = new BufferedReader(new InputStreamReader(new ProgressMonitorInputStream(parent, message, new FileInputStream(file)), charset));

  • How do I write and read a specified number of bytes using C++?

    I need to send one byte commands followed by 1 or 2 byte data as well as read 1 or 2 byte commands from a RS232 device. How do I ensure that only 1 byte is sent for the commands or 2 bytes of data using VISA?

    Hey BMas05,
    Using VISA in C++ you can strings or bytes depending on which polymorphic version of the write you are using. One of the parameters for the VISA Write is the byte array and the number of bytes. This is if you are using the VISA classes for C++. You might have to have Measurement Studio to get these classes.
    There is a really good example that installs on your computer at C:\Program Files\National Instruments\MeasurementStudio\VC\Examples\Io\Visa\Serial Visa.
    This example shows how you can write just bytes or strings and you can select how many bytes to read back.
    I hope this helps out.
    JoshuaP
    National Instruments

  • ORA-27063: number of bytes read/written is incorrect

    Hello -
    I am getting this error because my filesytem is at 100%:
    ORA-01114: IO error writing block to file 202 (block # 423324)
    ORA-27063: number of bytes read/written is incorrect
    However, when I query the dba_data_files, and v$datafile views, I do not see a reference to file 202. Where can I get this information?
    Thanks,
    Mike

    Mike,
    Looks like you got a solution, however, just FYI, tempfiles are numbered starting w/ db_files+1, so, likely, your value of db_files is 200, the error occurred on your number 2 tempfile.
    -Mark

  • Length specified in network packet payload did not match number of bytes read; the connection has been closed.

     Hello every one
    I am getting this in my event log from time to time . not sure what is that ?
    Is this a hacker trying to send rubbish data to SQL through the port ?
    Any help is appreciated .
    Length specified in network packet payload did not match number of bytes read; the connection has been closed. Please contact the vendor of the client library. [CLIENT: someip]

    Thank you all for the reply  , 
    my server is on port  1533 . Port  1433  is closed  on my server .
    All the requests are coming from my own ip , i feel this is funny . 
    Is my server hacked then ? 
    Or could be my ISP doing any routine tests ? 
    Also is this is hack attempt , what does this hacker think he will benefit from this ? Could this bring the SQL  server down  ?  
    I was thinking about chaning port to something else ,  1344 or something , u think this can be better  ?

  • Error 56 in TCP Read

    Hi,
    I have TCP Read in a loop  expecting data from some Micropchip boards connected to it. The problem I have is the boards do not send data all the time, hence I cannot wire in a specific constant to the number of bytes to read in, in the TCP read block.
    Am I right in saying the only option is to clear the error 56 when it occurs?
    Thanks,
    Harshil

    That should solve the problem.  See this post...
    There is a VI that you can use to clear this error.  look fo rexamples\comm\UDP.llb\no timeout error.vi
    The VI is located in an LLB named UDP, but the function only checks the error code, it has nothing to do with the connection.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Modbus tcp read holding registers not returning requested quantity

    Background:  I have a customer using an ELAU motion system - they are recording data to Holding Registers that they want to be able to read on a cRIO to match up with some analog data from FPGA (I have digital handshaking happening for that).
    LabVIEW 2010 SP1
    cRIO 9074
    Using the NI MOdbus.llb VI Library to communicate with the other system.  I can open the TCP communication no problem, and actually get SOME registers, just not ALL of the register data I want to read. 
    What I want to do is read 330 individual holding registers U16 values.  I know how the data is being split to represent various lengths (i.e. most data items are using 2 registers to represent one 32 bit number).  I just want to read all the individual registers and parse the data in another VI to convert it to the other data types.
    I provide the MB Ethernet Master Query (poly).vi with the starting address for the first register and then the quantity of 330.  The polymorphic instance selected the is "Read Holding Registers".  The array returned from this VI via "Holding Registers" is only 74 elements and not 330 requested.  I get no exception codes and no LV errors.  Is there some inherent limit on the number of Holding Registers that can be read?
    I am not using the MBAP Header input (not sure if that is needed).
    Thank you.
    Ryan Vallieu
    Automation System Architect
    Solved!
    Go to Solution.

    Simple solution once I dug into the MODBUS Serial protocol/TCP protocol documentation available out there via Google.
    Serial based modbus history is the limitation that carried over to TCP - the maximum amount of bytes in one data pack can only be 256 bytes.  Thus I was limited to around ~125 registers at once.
    256 bytes = 2048 bits.  Using 16 bit registers that gives 128 registers maximum.  I went with 125 to make keeping track of totals easier.
    Ryan Vallieu
    Automation System Architect

  • Output says "The number of bytes in the file are 0" but the file has bytes

    Dear Java People,
    Why would an output say a file has 0 bytes when upon doing a search for the file in Windows Explorer it say the file has 1 -4 kbytes ?
    for example part of my output was :
    "the number of bytes in TryFile3.java are 0"
    caused by the following lines of code:
    System.out.println("\n" + contents[i] + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());
    thank you in advance
    below are the two program classes
    Norman
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class TryFile3
       public static void main(String[] args)
           //create an object that is a directory
             File myDir =
            new File("C:\\Documents and Settings\\Gateway User\\jbproject\\stan_ch9p369");
              File myFile = new File(myDir, "TryFile3.java");
            System.out.println("\n" + myDir + (myDir.isDirectory() ? " is" : " is not")
            + " a directory.");
             System.out.println( myDir.getAbsolutePath() +
             (myDir.isDirectory() ? " is" : " is not") + " a directory.");
              System.out.println("The parent of " + myDir.getName() + " is " +
              myDir.getParent());
               //Define a filter for java source files Beginning with the letter 'F'
               FilenameFilter select = new FileListFilter("F", "java");
               //get the contents of the directory
               File[] contents = myDir.listFiles(select);
                //list the contents of the directory
             if(contents != null)
                 System.out.println("\nThe " + contents.length  +
                 " matching item(s) in the directory " + myDir.getName() + " are:\n " );
                 for(int i = 0; i < contents.length; i++)
                   System.out.println("\n" +  contents[i] + " is a " +
                   (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile3.java are " + myFile.length());
    else {
    System.out.println(myDir.getName() + " is not a directory");
    System.exit(0);
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class FileListFilter implements FilenameFilter
    private String name; // file name filter
    private String extension; // File extension filter
    public FileListFilter(String name, String extension)
    this.name = name;
    this.extension = extension;
    // static boolean firstTime = true;
    public boolean accept(File diretory, String filename)
    //the following line of code can be inserted in order to find out who called the method
    // if(firstTime)
    // new Throwable("starting the accept() method").printStackTrace();
    boolean fileOK = true;
    //if there is a name filter specified, check the file name
    if(name != null)
    fileOK &= filename.startsWith(name);
    //if there is an extension filter, check the file extension
    if(extension != null)
    fileOK &= filename.endsWith('.' + extension);
    return fileOK;

    System.out.println("\n" + contents + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents.lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());I haven't read any of your italicized code, but perhaps there is a good reason why you have "myFile.length()" and not "contents.length()" in this line of code?

  • How to reduce the number of bytes for a picture

    I want to reduce the number of bytes used for a picture to be sent to a site like Ebay or craigslist. I son't see any options in Iphoto for this purpose.

    You can do it in Preview.
    Open the image in Preview. Under Tools, click Adjust Size.
    Scale it down to the smallest acceptable size (the website should give a suggested resolution).
    Then go to File -> Export, save it as a Jpeg.
    Smaller size image means smaller file size.

Maybe you are looking for

  • Mapping an XML from an input element to Target

    Hi , I have an XML coming in source Element as below : <?xml version="1.0" encoding="UTF-8"?> <ResponsePayload>    <RespString><?xml version="1.0" encoding="UTF-8"?> <Devices>    <Device>1</Device>    <Name>1</Name> </Devices></RespString> </Response

  • RF Grouping not showing

    I have configured 2 controllers with the same RF Group name in the CONTROLLERS-->GENERAL page. However, when I go to WIRELESS-->802.11A or B/G and look at RF Grouping I only see the indivdual controller I am on in the grouping. I do not see the other

  • BW Merger

    Hi , We have 2 BW systems  at present and i am working on a projet to merge these 2 systems .Example BW            B1                 B2 R/3            R1                 R2 After merge BW            B1 R/3       R1         R2 I hope somebody in the

  • Client copy (export/import) from ECC to BW

    It is technically feasible to import a client exported from a NW system installed as ECC 6.0 into a NW ABAP Stack (designed to be a BW system)?

  • IBook/Powerbook superdrive used for macbook pro replacement part?

    Can I use a superdrive from an ibook or powerbook as a replacement part for my macbook pro?