"Read From Binary File" function Help ambiguity

I must be getting tired, but for some reason a doubt crept in my mind as I was designing a new piece of code this morning:
"is the "Read From Binary File" using the last file position or is it starting from the beginning of the file?"
"That's a stupid question", I told myself.
"I used this function a million times and have always assumed it is reusing the last file position. Moreover, there is no file offset input to that function, so WTH am I afraid of?"
So, for kicks, I fired up the Help window and read the following description (*):
Reads binary data from a file and returns it in data. How the data is read depends on the format of the specified file. This function does not work for files inside an LLB.
(*) BTW, has anybody ever complained that you can't select and copy anything from the floating Help Window?
Not much there. I particularly admire the phrasing of the second sentence... What about: "This function can do a lot of things, but it would much to complex to describe this is extensive details, so if you are asking, you probably can't afford using it"?
Anyhow, I clicked on the "Detailed Help" and got this (among other things):
Use the Set File Position function if you need to perform random access.
WHAT? I am pretty darn sure I DO NOT USE the Set File Position when I read a file in successive and contiguous chunks. I just pass the file refnum into a shift register and back to the function and that's it.
Now, the description of the "Refnum Out" ouput says: If file is a refnum or if you wire refnum out to another function, LabVIEW assumes that the file is still in use until you close it. Translated in plain English, is that supposed to mean that if the file is not closed it is open, or is that implying that it contains more info that just "the file is open and can be found here"?
I started searching around and finally ended up with the entry for "refnums, file I/O". Down the bottom of the (long) article, I found this under the heading "References to Objects or Applications" (but nothing specific to files, BTW):
...LabVIEW creates a refnum associated with that file, device, or network connection...
[...]  LabVIEW remembers information associated with each refnum, such as the current location for reading from or writing to the object and the degree of user access, so you can perform concurrent but independent operations on a single object. If a VI opens an object multiple times, each open operation returns a different refnum. LabVIEW automatically closes refnums for you when a VI finishes running, but it is a good programming practice to close refnums as soon as you are finished with them to most efficiently use memory and other resources.
So it seems that my recollection was correct. I do not know what the "degree of user access" for a file is, but that's not the topic of today's post. 
So, my point is: the Help File for this function is incomplete or ambiguous at best. Please correct it. And provide a link to the "refnum, file I/O" Help entry in its detailed Help. It would H E L P...
Thanks for reading.

Reading in succesive chunks is *NOT* random access. An open file always has
a current position, which is updated with each read or write operation.
You only need to set the file position if you want to start elsewhere.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Read from Text File Detailed Help need Clean-up

    This is probably well known and nobody has bothered fixing it but the detailed Help of the "Read from Text File" function is sort of ambiguous:
    -  statement 1: refnum out is the refnum of the file that the function read. You can wire this output to another file function, depending on what you want to do with the file. The default is to close the file if it is referenced by a file path or selected from the file dialog box. If file is a refnum or if you wire refnum out to another function, LabVIEW assumes that the file is still in use until you close it.
    - statement 2: If you wire a path to file, the function opens the file before reading from it and closes it afterwards.
    I have found statement 1 to be correct, which makes statement 2 incomplete (and sort of tautological in the sense that 1) you expect LabVIEW to open the file before reading from it if you provide a path instead of a refnum... and 2) if you use a path input to file AND use the refnum out for some other function, the file is NOT closed, as correctly stated in statement 1).
    Just sayin' ...

    X,
    It deeply concerns me that you would take my response to mean indifference. I certainly had no intention to belittle what you had to say. On the contrary, I took this up with the concerned team, and had a small discussion. If you say that what someone says on this forum is of lesser or no value to National Instruments, you could not be more wrong. It defeats the whole purpose of this public forum.
    My point was not that it is not an issue, it certainly seems to be. Please be rest assured that even if it does not look like it from the outside, each comment however big or small is taken back to our workplaces and some thoughts poured over it. 
    On the whole, I recognise that I had a role to play in this misunderstanding of tone, and I sincerely apologise.
    Warm Regards,
    Prashanth N
    National Instruments

  • "Read from Binary File" and efficiency

    For the first time I have tried using Read from Binary File on sizable data files, and I'm seeing some real performance problems. To prevent possible data loss, I write data as I receive them from DAQ, 10 times per second. What I write is a 2-D array of double, 1000 data points x 2-4 channels. When reading in the file, I wish I could read it as a 3-D array, all at once. That doesn't seem supported, so I repeatedly do reads of 2-D array, and use a shift register with Build Array to assemble the 3-D array that I really need. But it's incredibly slow! It seems that I can only read a few hundred of these 2-D items per second.
    It also occurred to me that the Build Array being used in a shift register to keep adding on to the array, could be a quadratic-time operation depending on how it is implemented. Continually and repeatedly allocating bigger and bigger chunks of memory, and copying the growing array at every step.
    So I'm looking for suggestions on how to efficiently store, efficiently read, and efficiently reassemble my data into the 3-D array that I need. Perhaps I could simplify life if I had  "write raw data" and "read raw data" operations that write and read only the numbers and no metadata.then I could write the file and read it back in any size chunks I please -- and read it with other programs besides. But I don't see them in the menus.
    Suggestions?
    Ken
    Solved!
    Go to Solution.

    I quote the detailed help from Read from Binary File:
    data type sets the type of data the function uses to read from
    the binary file. The function interprets the data starting at the current file
    position to be count instances of data type.
    If the type is an array, string, or cluster containing an array or string, the
    function assumes that each instance of that data type contains size information.
    If an instance does not include size information, the function misinterprets the
    data. If LabVIEW determines that the data does not match the type, it sets data
    to the default for the specified type and returns an error.
    So I see how I could write data without any array metadata by turning off "prepend array or string size information", but I don't see any way to read it back in such bare form. If I did, I'd have to tell it how long an array to read, and I don't see where to do that. If I could overcome this, I could indeed read in much larger chunks.
    I'll try the auto-indexing tunnel anyway. I didn't tell you the whole truth, the 3-D array is actually further sliced up based on metadata that I carry, and ends up as a 4-D array of "runs". But I can do that after the fact instead of trying to do it with shift registers as I'm reading.
    Thanks,
    Ken

  • Read an avi file using "Read from binary file" vi

    My question is how to read an avi file using "Read from binary file" vi .
    My objective is to create a series of small avi files by using IMAQ AVI write frame with mpeg-4 codec of 2 second long (so 40 frames in each file with 20 fps ) and then send them one by one so as to create a stream of video. The image are grabbed from USB camera. If I read those frames using IMAQ AVI read frame then compression advantage would be lost so I want to read the whole file itself.
    I read the avi file using "Read from binary file" with unsigned 8 bit data format and then sent to remote end and save it and then display it, however it didnt work. I later found that if I read an image file using "Read from binary file" with unsigned 8 bit data format and save it in local computer itself , the format would be changed and it would be unrecognizable. Am I doing wrong by reading the file in unsined 8 bit integer format or should I have used any other data types.
    I am using Labview 8.5 and Labview vision development module and vision acquisition module 8.5
    Your help would be highly appreciated.
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    read avi file in other data format.JPG ‏26 KB

    Hello,
    Check out the (full) help message for "write to binary file"
    The "prepend array or string size" input defaults to true, so in your example the data written to the file will have array size information added at the beginning and your output file will be (four bytes) longer than your input file. Wire a False constant to "prepend array or string size" to prevent this happening.
    Rod.
    Message Edited by Rod on 10-14-2008 02:43 PM

  • Read From Binary File doesn´t work on MCB2400 in LV2009 Embedded ARM

    Hello,
    I try to read a Binary File from SD-Card on my MCB2400 Board with LV2009 Embedded for ARM.
    But the output is always 0, if I use my VI on the MCB2400. If use the same VI on the PC it works fine with the same binary file.
    The
    access to the SD-Card on the MCB2400 works in other cases finde, if I
    try to read from a text-file it works without any problems.
    Are thre any constraints for the "Read From Binary File"-Node in Embedded in comparison to the same node on PC ?
      I have noticed that there is also a problem
    with the reading of textfiles. If the sice of the file is about 100Byte
    it doesn´t work anymore, too. I can´t understand it, because I read
    always just one Byte. And even if the implementation in Labview is so
    bad that it allways reads the total file in the ram it sould work. The
    MCB2400 has 32MegaByte RAM, so 100Byte or even a few MegaByte should
    work.
    But this doesn´t seem to be the Problem for the Binary-Problem. Because even a 50byte Binary-File doesn´t work.
    bye & thanks
    amin
    Solved!
    Go to Solution.
    Attachments:
    SD_Card_Read-test.vi ‏12 KB

    Hello,
    thank you for your Help.
    But I just want to read a Binary File, which is build by another program. And this is coded with 8Bit (like a normal Binary File) and not just with 7Bit (ASCII). So the workaround doesn't work in my case.
    I posted the Test-VI in my first post (here once again as picture). And it works fine on the PC, but if I try it on my MCB2400 the "Read Form Binary File" Node doesn't work.
    And it is also possible to open the Bin file with the "Read Text File" Node and see the cryptic content of the Bin-File. So the Problem seems to be in the "Read Form Binary File" Node.
    bye & thanks again
    amin
    Message Edited by aminat on 09-30-2009 03:28 AM

  • How to open saved files using 'read from text file' function

    Hi everyone, I am having a hard time trying to solve the this particular problem ( probably because I am a newb to lanbview ). Anyway , I am able to save the acquired waveforms by using the 'Write to text file' icon. I did manually modify the block diagram of the 'Write to text file' icon and create the correct number of connector so as to make my program work. But now I have no idea on how to modify the block diagram of the 'Read from text file' block diagram to make my program 'open' my saved waveforms. Or i do not have to modify anything from the block diagram of the 'Read from text file'? Can anyone teach/help me connect up? Do i need the build array on the "open" page?
    Here are some screenshots on part of my program  
    let me know if you guys would need more information / screenshots thank you!
    Attachments:
    ss_save.jpg ‏94 KB
    ss_open.jpg ‏94 KB
    modified_writetotextfile.jpg ‏99 KB

    Ohmy, thanks altenbach. oh yeah i forgot about those sub VIs. will upload them now. Was rather demoralized after reading the comments and really struck me on how weak i'm at on labview really hope to get this done. But of course i have to study through and see how it works. Actually i am going to replace those 'signal generators sub vi' with ThoughtTechonology's sample code so i can obtain data waveforms real-time using Electrocardiography (ECG) ,Electromyography (EMG ) and Electroencephalography (EEG) hopefully i can find out how to connect the sample code.
    ( ps . cant connect it now unless my program is working otherwise labview will crash ) 
    ( p.s.s the encoder of my biofeedback trainer already acts as an DAQ so i wont need to place an DAQ assistant in my block diagram i suppose )
    The sample code of ThoughtTechnology is named as attachment.ashx.vi. too bad i cant use it and present it as my project
    Attachments:
    frequency detactor.vi ‏53 KB
    signal generator.vi ‏13 KB
    attachment.ashx.vi ‏40 KB

  • Read from text file, pls help!!

    hi, I am new to java.
    i made a scribble applet and saved the painting out as a text file.
    Now I want to read the 'paint' lines from the text files back to the applet, so that they appear on the canvas.
    Does any one konow how to paint the lines back to an applet without signing it.
    I really need to know this. It would be great if anybody could help me.
    Thanks Michele

    the coordinats, brush sizes and colors of the "painted lines" ar ein a comandbuffer. To save them I have a socket conection and an other script listening to the port.
    save- code:
    void NetworkTransfer()
         String adr=getCodeBase().getHost();
         Socket s;
         PrintWriter writer;
         try
              s=new Socket(adr,34177);
              writer=new PrintWriter(s.getOutputStream());
         catch(IOException e)
              return;
         //User&Filename �bertragen
         writer.println(unamestr);
         writer.println(fnamestr);
         //cmdbuf �bertragen
         writer.print(cmdbuf);
         writer.flush();
         try
              s.close();
         catch(IOException e2)
    the txt file loos than something like this:
    P,497,422,3,ffd51e1e
    P,498,422,3,ffd51e1e
    P,499,422,3,ffd51e1e
    P,500,422,3,ffd51e1e
    P is the typ of line
    497,422 the coordinates
    3 the brush size and
    ffd51e1e the color
    I thought it might be possible to read the txt file line by line so that the picture apears on the canvas like an "animation". But I have not figured out how to do this
    Thanks Michele

  • Reading a binary file using the type cast function is not working

    Hello
    I am trying to read a binary file.  Using the Read from binary file and type cast functions I can actually get the information from the file.
    I set an indicator in the “Normal” option in Properties. I can read the header and footer but not the body of the file; For the body of the file all I can see is characters of the type
    “C¾ Ü Qþ  X@ “. One of the other options, Password, seems to provide an output of just the characters that were originally written, but then again, I can not read the characters because it is only asterisks and I can not copy them onto a word processor either.
    I tried setting the indicator in Hexadecimal mode, then creating a local variable that acts as a control and use the type cast function again to see if  could convert the Hexadecimal string to readable ASCII characters; unfortunately, this did not work either.
    I don’t know what else I should try or if there is something that I may not be doing right and for that reason I am not getting the desired results. I hope someone has an idea about this issue.
    Regards,
    Roberto

    Thank you for your reply,
    Well, actually I don’t have any information about this file. I will try to obtain information about it though.
    This is a file that contains velocity information; there are 65 channels that form a velocity profile in a pipe. Also, there are 4096 velocity profiles. I don’t know what is the format of these values.
    The software that creates the file provides a text file. Using this text file the velocity information can be processed and then plotted.
    I want to avoid all these intermediate steps and read, process and plot everything using only LabView. BTW, I am using LabView 8.2
    Roberto

  • For Mike Porter: Read from Spreadsheet File.vi" function

    On 2/17/03 you answered my question about reading and viewing a test done last week back into Labview. I can open the "Read from Spreadsheet File.VI" in Labview and read the file "data.txt" into the VI. The data comes back into the rows & cells on the VI screen but I don't know how to open the graph to see the data as curves. I can see about a 3 x 4 array of cells at a time and the correct data is there but I want to plot it. Do I need to create a new block diagram and VI? I apologize for the vagueness of my question - I'm new at Labview.
    Attachments:
    DATA2.TXT ‏183 KB

    Create a VI with a Waveform Graph on the front panel. On the block diagram, insert a Read From Spreadsheet File function. Connect the All Rows output to the Waveform Graph.
    Attachments:
    Graph.jpg ‏3 KB

  • Problems reading from a file

    Hey,
    I have this file that I need to read so i can handle the contents. It was created in MSDOS and as I have very little experience in that topic, I wondered if anyone can point me in the right direction. I tried reading it as a ascii and binary file but neither work, I'm really just guessing though.
    The file has no extension. Hence I can't upload it to the forum. Its made up of mostly meaningless strings of characters.
    Any help is appreciated,
    Regards,
    Rkll

    Rkll wrote:
    Ya you're exactly right, its parsing the data that is the problem. I have done what you said and attached it as a .txt file. My inital thought was that it was a collection of binary digits but I was unable to read them with the built in Labview read binary file VI. Although maybe I had a setting wrong or something.
    This has nothing to do with the Read From Binary File VI, or any setting. That functions does not magically know the format of a file, just like any binary file read for any other programming language. Thus, you have to tell it how to interpret the data. You can tell it to read the file as a series of bytes, and it will dutifully return to you an array of U8 integers. Or, you tell it to read it as a series of 16-bit integers and it will dutifully return to you an array of I16. It will give you what you tell it to give you. 
    Looking at the file I can see some header information, though it's not clear what all the spaces are being used for. I can't tell whether they're padding for a section, or what. As I noted, do you have any idea as to the format of the file?  You said you're updating an old computer system. Any documentation?

  • Read from .txt file and output the content as two arrays

    I am using the contoured move to control the x-y stage. The trajectory datas for x and y axis are generated using my interpolation program and it is stored in a .txt file as two columns. What I want to do is read .txt file and output the content of this file as two arrays. Is there anyone has any ideas? Thanks, the .txt file is attached.
    Attachments:
    R.75.txt ‏172 KB

    Hi Awen,
    This is quite easy to do, you can merely use the "read from spreadsheet file" function to get a 2D array (2 columns and n rows) and then use the index array function to get whatever row/colums you want..
    Hope the attached VI helps you
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    read sprdsheet file.vi ‏27 KB

  • Read from I16 file

    Dear,
    I used to use Read from I16 file.VI, but since I'm using LabView 2009, I'd like to use "Read from binary file.VI".
    I've looked at the previous posting and tried the suggestions, but I still got a problem.
    Could you help me to figure this out? By the way, I'm using LabView 2009 Spring (Professional version). The VI I'm trying to replace is shown below.
    Thanks,
    Jay

    In order for it to work the way you have it displayed there, you will need to wire a 2D array constant (make sure the representation is I16) to the data type input of the read from binary file.vi
    National Instruments
    Applications Engineer

  • Set a timeout for "read from text file"

    I Need to read from a text file on a remote pc and use the read from text file function to do this. It wotks but sometimes this pc is down causing long wait times in my vi.
    Is there a way to set a timeout for the read from text file function, or is there an other solution?
    Thank you

    You could check that the path is valid first before you attempt to read the file.  hen put the file read in a True-False case structure based on the results of the check.  You can use the function "Check if File or Folder Exists"  It checks whether a file or folder exists on disk at a specified path. This VI works with standard files and folders as well as files in LLB files.   The function is found in the File I/O --> Advanced File Functions palette.
    Tom

  • Format precision apparently ignored when using read from spreadsheet file

    I hope there is ridiculously simple solution to this problem but so far I can't find it. Using the Read from Spreadsheet File function in LabVIEW7.1, I can't get the floating point format (%f) to work; the decimal (%d) seems to work fine. For example, the first value in the attached file is 399.5853. When I read it in using %.2f format I would think I should get 399.58 but instead I get 399.58529663... Oddly if I use %d as the format, I get an as expected value of 399. Can anyone see what I am missing?
    Attachments:
    ReadFileTEST.vi ‏23 KB
    test.txt ‏1 KB

    The solution to the problem is the internal representation of floating point numbers: with a limited number of bytes only a limited number of the (infinitely many) real numbers can be represented. The nearest representable number to 399.5853 is 399.58529663 if the so-called single precision representation (abbr. SGL in Labview) is used.
    It seems that (ridiculously!) NI has chosen to use SGL as the data format in the Read from Spreadsheet VI which causes the unexpected behaviour you observed.
    You can change the representation from SGL (which uses 4 bytes) to DBL (double precision, using 8 bytes) in the Read from Spreadsheet VI and you will observe a better approximation then, but still not 'exact' since the number now reads 399.585300000000018. (With t
    he EXT representation, 10 bytes, you could go to even higher precision)
    I hope someone from NI reads this and they fix the unnecessary limitation of the precision in the Read from Spreadsheet VI.

  • Read from Text File - Help Bug?

    Hi - I am currently working on LV8 and I think that there is some misunderstanding potential in the help file. To be more exact in the help to the "Read From Text File" VI.
    The description for "count":
    " ... If count is <0, the function reads the entire file. The
    default is –1, which indicates to read a single line if you placed a checkmark
    next to the Read Lines shortcut menu item and to read the
    entire file if you removed the checkmark next to the item. "
    If count is lower than zero, the function reads the entire file. That sounds clear to me.
    The default is -1, which indicates to read a single line if you placed a checkmark next to the "Read Lines" shortcut menu item. Now what? Does it read a single line or the whole file?
    .. and to read the entire file if you removed the checkmark next to the item. I thought it reads the whole file if I use -1 ?
    the VI itself behaves as I'd expect it to:
    * If I place a checkmark next to Read Lines and put -1, I get an array containing the lines
    * If I remove the checkmark, I get only a single string item.
    Now where is the error? Is the VI not working properly or only the description a little bit ... strange ?

    ?hein??
    ?what?
    Both you guys lost me..
    And I drink coffee without sugar (being sweet enough, already) 
    Here is what I get from Context Help on the Read From Text File:
    Read from Text File
    Reads a specified number of characters or lines from a byte stream file. By default, this function reads all characters from the text file. Wire an integer value to count to specify how many individual characters you want to read starting with the first character. Right-click the function and place a checkmark next to the Read Lines option in the shortcut menu to read individual lines from the text file. When you select the Read Lines option in the shortcut menu, wire an integer value to the count input to specify how many individual lines you want to read from the file starting with the first line. Enter a value of -1 in count to read all characters and lines from the text file.
    Humm.
    New feature (again)..  If you select checkmark the Read Lines option, it will not send the text to a sting indicator, as shown in the attached image.  If selected, then it's expecting to write lines to an array of strings...  WHY???  I don't know..  I'll ask..
    Strange...  LV8 is full of mysteries... 
    RayR
    Attachments:
    bad write file.JPG ‏33 KB
    more bad write file.JPG ‏12 KB

Maybe you are looking for