Writing binary files in block mode?
I am sampling two channels in continuous mode using labview basic version. I would like to take the two arrays of values as I am sampling them and write them out in block mode to a binary file. What's the best way to do that?
Open or create a file for write before daq starts, then continuously write data to the file, and close it after the daq is stopped. Make sure each column of the data array is each channel, so an Array transpose might be needed.
-Joe
Attachments:
Snap8.gif 8 KB
Similar Messages
-
Problem writing binary files with LV 8.5. I have one VI that does all the interaction/file I/O and another VI for testing. I find when I run the subVI where all the data reading/writing is happening with break points and single stepping through the code all is OK, but when I run normally the files are much larger than they should be and as well when I close the files I get a error. Any insights?
WalterWaltz wrote:
I found the problem, I was actually trying to close the files twice.
I don't see how this could cause the symptoms you described in the first post.
(It only explains the error on close).
LabVIEW Champion . Do more with less code and in less time . -
Writing binary files & trouble with no unsigned byte type
I've got a fair amount of Java experience, enough to know what I'm doing most of the time but I do have a vast experience with C & C++ which helps my Java. I've stumbled across a problem when trying to write out files in binary.
If I was to write out a binary file, I would always choose C/C++ to do this because simply because I'm at ease with the implementation.
I've now written a Java program which needs to output a file in binary and I'm having real issues doing the most simple things because of no unsigned support.
I want to write out elements byte-by-byte and make use of the 8-bits provided in the byte type in Java.
Let's assume I've done my processing and I end up with an int. I know that this int is 0-255 in value. I now want to pack it into a byte and write it to my file. How do I go about assigning the byte without Java 'converting' it to a signed byte? I simply want to copy the lower 8-bits of the int and duplicate them into the byte variable - no conversion.
In C you would do something like this:
char mySignedChar = *( (char*)&(unsigned char)myInt ) );
What's the Java equivalent? Am I going about this the right way?Whether a byte is signed or unsigned only matters if one is doing arithmetic on it. If the int is 0-255 then you just cast to a byte using
byte theByte = (byte)theIntValue;When reading back you just use
int theByteAsAnInt = theByte & 0xff; -
Writing binary file - random places
Hi,
I want to write to random places inside a binary file using powershell.
something like a function write(position,value)
Original file content "0123456789"
write(1,2) -> file is now "0223456789"
write(6,2) -> file is now "0223452789"
write(end,12345) -> file is now "022345278912345"
Is something like this possible? And how? Does somebody have any linkes for me to follow.
With kind regards,
Maurice LucasThe example is text. You cannot write to a binary file using text.
We would open the file as a binary stream and use file seek methods.
A binary file has only 1s and 0s. They may look like hex in a binary editor.
See:
http://msdn.microsoft.com/en-us/library/d3wke8tz(v=vs.110).aspx
Binary is written to by byte position and buffer length.
¯\_(ツ)_/¯ -
Writing binary file for fixed amount of time
Hello, I'm trying to write a binary file of multiple channels for a fixed amount of time before I perform my analysis. Does anyone know the best way to accomplish this?
Here is an example of one way to do what I think you are trying to do. There may be a more elegant way of doing it, but this is pretty simple and straight-forward. It basically writes a 5-integer array for 5 seconds and then stops. Let me know if you have any questions.
Attachments:
timed write.vi 27 KB -
Writing Binary files from PL/SQL
Hi Group,
I wish to read tables in Oracle and write them in to Binary files in a predefined format, Can any one help me How to write binary data from within PL/SQL.
UTL_FILE package has support to .txt files only, is there any other way to deal with this problem.You can write ActiveX COM components and use Oracle COM Automation too. I plan to do some experiments later in the summer.
-
Writing binary .raw file
Hi
I am facing problem with writing binary file as .raw file. I have attached my VI please let me know whether I am mistaking with creating and writing files. I will appreciate your help.
Thanks
Attachments:
writing_binary file.vi 67 KBYour actual writing of the file looks fine to me. If you wanted to make it a little simpler, you could actually not use the File Open and the File Close functions. You can wire the path straight into the Write Binary File and if you don't wire the file reference out, it will close the file. Were you having problems with something?
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Binary file import and export in lab windows cvi
Hello,
I have some standard binary file format (.sie) that has been written in origin IDE. The sie type extension file format is a public format, but not defined by Origin. In origin IDE, i can be able to import these files and also be able to export it to excel as csv type. Now, i want to do the same thing in lab windows cvi. i need to import .sie type file and be able to read and export it to excel in lab windows cvi. Is this possible? Please help me to work on this project. Thanks in advance.
Regards,
Jayakumar.VReading and writing binary file is indeed possible in CVI, the problem normally lien in the definition of the file format you want to access.
I never found .SIE extension during my activity; a fast search on google returned this page with a link to the document explaining one file structure: it's a format dedicated to accounting so it's possibly not your case, but could they be your files?
Before finding the complete description of the file format you cannot think of any operation on the file itself, unless it is so self evident that you need little effort to access file content (this normally happens only on text files).
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Writing waveforms from Ch. 0 of niSCOPE to binary file in a multi-record setup?
Hello,
I am not very experienced with niSCOPE and writing waveform records, so I need some expert help here.
Here is my application:
I am generating a pulse train using a 6602 counter/timer. Each rising edge of this pulse train triggers an niFGEN to generate a single sawtooth waveform output to another device and, at the same time, acquiring data from Ch. 0 of an niSCOPE. I am fetching one record per rising edge of the pulse train for the niSCOPE (multi-record setup).
The attached VI is where I am at thus far. All triggering and reading/fetching of the waveforms seems to be working just fine when testing with an oscilloscope. I now need to save each waveform record along with the timestamp of its rising edge trigger to a binary file. The bottom of the VI is where my attempt is at saving the waveforms to a binary file, so the attention should be there when looking at it.
I am running LabVIEW from a computer connected to the NI PXI-Chassis using a cross-over cable.
Questions:
1.) Do I need to convert the data coming in on Ch. 0 of the niSCOPE to digital? Does it come in as analog from an oscilloscope? If I need to do this, how can I accomplish this?
2.) When I try to run an example VI to write a waveform to a binary file by choosing "My Computer" in the bottom left of the VI window, it works it saves the file just fine. When I change this to run on "PXI2", a file is not even created and I get an error on File Dialog (code# 7, I think) each time the file is attempted to be closed. This may be a stupid question, but why can I not save data to a file on my computer if running the VI on "PXI2"?
3.) Assuming the saving of each waveform to a binary file is working (read: (2) is successfully addressed), how can I also write the timestamp of the starting trigger for the waveform along with the waveform in the binary file? An example VI of how I can accomplish this would be fantastic, but I haven't been able to find one thus far.
4.) When I was messing around and trying to accomplish this, it seemed that doing this writing may slow down the entire process too much. I need to record data to the extent of the sawtooth waveform generated by the niFGEN AWG for each trigger. Is there any changes I should make to my acquisition process in the niSCOPE section so that I can read each waveform, along with keeping the timestamp for each, and write this information to a binary file?
I need to get this working quickly, so any help on this is greatly appreciated. Thanks in advance.
Attachments:
5124_update.vi 157 KBThank you so much for your reply, David. Let me try and explain my
situation and setup a little better, as well as discuss the points you
made in your reply. Beware, you may want to refill your coffee as this
post is long .
I am using an embedded controller in a PXI-1044 chassis. I now have the
chassis hooked up to our local network, and I am deploying my project
to the chassis over the network as I am also connected to the local
network. I have an oscilloscope next to me that takes as input the
pulse train for a trigger and the generated sawtooth from the niFGEN
for each trigger (rising edge of the pulse train from the 6602
counter). Just to make sure synchronization is taking place, the
sawtooth is also fed as input to the niSCOPE for acquisition.
"PXI2" is what shows up when I choose to run a VI on the PXI chassis
rather than "My Computer"; not sure why the 2 is there either, but that
is what it says. I may have tracked down the issue I was having with
writing, but more about that a little later...
The attached VI is an update, although not much has changed. My
application design is like this (keep in mind that some values for VI's
are still constants in the block diagram while others are controls on
the front panel): I am using the 6602 to generate a 1 KHz pulse train
and routing this pulse train to PXI_Trigger0/RTSI0. I am also using the
PXI_Clock (10) as a sample clock for this, and also using this same
clock as the reference clock for both the 5422 and the 5124 (as per the
synchronization help file mentioned for synchronizing multiple
devices). Both the 5422 and the 5124 are triggered by a digital rising
edge (from the pulse train) on PXI_Trigger0/RTSI0 (as it was routed
there). For each trigger, the niFGEN generates a sawtooth waveform
using a stepped trigger mode and outputs it. For each trigger, the
niSCOPE acquires data. They are both synchronous, which is tough to see
since one has its trigger source on the front panel and the other has
its trigger source on the block diagram. All devices use PXI_Clock so
they are synchronized.
The expected behavior is to only generate a single sawtooth waveform
per trigger with a certain number of sample points. I want to acquire
the same number of samples using the niSCOPE, which is what I meant by
"the extent of the waveform" in my previous post. So, should I change
the 8192 to 1000 for the number of samples for the niSCOPE? What would
you recommend for the sampling rate? I have been using 5 MHz for the
niFGEN and 5 MHz for the niSCOPE...this is how it should be done,
correct? If it is different in the VI, please let me know. For some
reason, I have to adjust all of the values each time I open it since
the default values are not the ones I want.
I want to generate and acquire one waveform per trigger (one waveform
per record). However, I want to be able to record a large number of
records so I have enabled the circular buffer-like treatment of the
acquired waveforms. The 100 or 1000 records is actually just a number I
am giving it for now to make sure it is working before recording many
more records.
As for saving the niSCOPE data, I would like to save all data in a
single file that is NOT ascii (to save space). I have been looking at
the HWS file format, and would like to use it. I think the attached VI
includes this at the bottom of the while loop. For each trigger, I
would like to save the time (as accurate as possible) that the trigger
occurred for the record/waveform, which appears to be (absoluteInitialX
- relativeInitialX) as you said in your post (thanks!). I just need to
store as much information about the waveform and time information for
it as possible with the waveform in the file. So it looks like I will
need to use the wfm info for that information, providing portions of it
as waveform attributes in the HWS VI's?
What format of data do you recommend I fetch, and will I be fetching a
"Single waveform" or "Multiple waveforms"? Should I use I32, DBL, WDT,
or other for the format? A balance between good precision in values and
time it takes to fetch/record would be best.
Given all of the above, I am having one troube with saving data to a
file. As a reminder, I am deploying the project to the chassis over the
network. When I choose a location and/or file to save the HWS data to,
I only get choices that are on the PC's hard disk (such as C:\Documents
and Settings\cgifford\...) NOT the chassis's hard disk. When I choose
something other than "C:\" I get an error that the file could not be
opened. However, when I choose "C:\" everything goes fine. The saved
data is nowhere to be found on my PC though, so I am assuming that it
is being stored on the internal 60G hard disk in the chassis that must
be named "C" by default or something!?
I have been told by phone support that I should be able to make a
direct connection with the chassis just like another PC, and should be
able to access the information on its internal hard disk in a drag and
drop fashion. I however cannot directly connect to the PXI chassis to
get the data that has been saved on the hard disk. We are running
Windows XP on the PC. We did some poking around and noticed that the
chassis is not running Windows file sharing, and only has ftp and http
running. We tried to access it using ftp, but we didn't have a username
and password to supply it. So, how can we enable Windows file sharing
on the chassis? How can I connect to it to do drag and drop to get
saved waveform data off of it? This is the main problem I am now
facing. Eventually we would like to store data to an external hard disk
connected to the chassis, which assumes that I can have access to the
internal storage to tell it to save files to the external hard disk.
For now saving it to the internal hard disk is just fine until
everything is proven to work, but I would like to get the data off of
the internal hard drive to put on another computer.
Any answers/suggestions on my above questions are greatly appreciated.
I also want to thank you for reading this long post . I eagerly await
a reply. Thanks again in advance.
Chris
Attachments:
5124_update.vi 143 KB -
Writing binary data to a file without carriage returns every 512 bytes
Is there a VI for writing binary data to a file without carriage returns being inserted every 512 bytes?
ThanksHi Momolxg,
I could be way off on this. I tried to simulate what you've done by
making a for loop that would run a set number of times. For my example I
used 1025. I wired the iteration terminal to a 'Write to SGL File.vi'
outside the loop with indexing enabled. It wrote the SGL data from 0 to
1024 to the file. I then read the file with a 'Read Characters from
File.vi' and searched the output for a carriage return (0D hex). It was
found five times. The reason why was the SGL number it was reading had a
13 (0D hex) in it. Perhaps you're running into a similar problem?
I tried it again, this time using the 'Write to I16 File.vi'. The
carriage return was found five times: the 28th character the first time
then on the 512th character four consecutive time
s after that. I suppose
that makes sense that you'd find a 0D in the numbers at equal spacings if
they're incrementing this way... In this case the carriage returns you're
seeing are actually numbers from your data.
One big difference is that I'm using a set pattern of numbers. This
doesn't appear to be your case. Is there a better way we can duplicate
your problem? It sounds interesting. Again my simulation could be way
off. (I'm also running this on LV60 for Linux so my results could be
different)
- Kevin
In article <[email protected]>,
"momolxg" wrote:
> Is there a VI for writing binary data to a file without carriage returns
> being inserted every 512 bytes? Thanks -
Binary file data plugin : append block values to channel
I need to create a data plugin for a unique binary file structure, which you can see in the attached graphic.
With these objects
Dim sBlock : Set sBlock = sFile.GetBinaryBlock()
sBlock.Position = ? 'value in bytes
sBlock.BlockWidth = ? 'value in bytes
sBlock.BlockLength = ? 'value in bits
I have the possiblity to read chunks from my binary file. At the end, I want to have each signal in a respective channel. I could manage to extract signals 1 and 2, as they only have one value in each block with a known byte-distance in between. How can I extract the other channels, that have 480 successive values in each block? I could probably write a loop and read the specific signal part in each block, but how can I append these parts to the relevant channels? I tried by creating a new channel and then merging them, but unfortunately functions like ChnConcat are not working in a data plugin. Any ideas?
/Phex
PS. Of course I could create a hideous plugin with running GetNextBinaryValue() throught the whole file, but that doesn't seem to be a smart idea for a 2 GB file size.
Attachments:
KRE_DataPlugin_schematic.JPG 84 KBPhex wrote:
@usac:
Your workaround seems to work at least for part of the file. If I loop it through the whole 1.5 GB file I am getting the DLL error "The application is out of memory". There is enough dedicated RAM available, but I guess this is x86 related.
Hello Phex,
Have you tried running this Script in the DIAdem 64-bit preview version (which gets you access to more than 2 GB or RAM for your application) that can be found at http://www.ni.com/beta and can be installed in parallel to the 32-bit version.
It might get you around the "out of memory" issue ...
Otmar
Otmar D. Foehner
Business Development Manager
DIAdem and Test Data Management
National Instruments
Austin, TX - USA
"For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary." -
Hi,
I have trouble when writing a binary file. Here is what I do:
I have some VI's collecting various data for a fixed period of time. I put all the data into 1D arrays at a fixed frequency (they all have the same size). Once it is done I merge all the arrays into one 2D array and I write that to a binary file. If I wait about 10 seconds after writing the file and I repeat the whole thing, everything is fine and the timing is correct. If I wait for a shorter period of time (say a sec, and this is the maximum I can wait to have a usable application) then the timing is wrong in the first part of the loop (the time-critical data-acquisition one). Of course, if I don't write the file, everything is fine (I have to wait about 250 msec between two runs, but that's ok). Any advice ?
I also tried several things like streaming the data to disk during the time-critical period and this works fine only if the file allready exists. If not I experience jitters again. I don't really want to stream the data in real time, but it could work if I can get rid of the jitters. Again, any advice ?
I'm using LV7.1 and the real time module running on a PC (ETS).
Another, sort of related, topic: I noticed that when using 2D arrays within time critical loops all the process are slowdown whereas if I use several 1D arrays everything is fine... Any idea why ?
Thanks,
LaurentHello,
File I/O transfer rates during streaming to disk depends on several factors: CPU speed and load, hard drive technology (IDA / Serial ATA / SCSI ...), quality of programming. High jitter is always due to bad programming. File I/O operations are not deterministic. So, file I/O VI's must not be called in the critical task. Data must be saved in the normal priority VI's in order to keep jitter as low as possible. This is the reason why an application in RT is based on RT FIFO to transfer data from the critical loop and the normal priority VI.
You will find a lot of tutorials detailing the key concepts for RT programming at the link below:
* Real-Time Module
http://zone.ni.com/devzone/devzone.nsf/webcategories/C25F8C664230613A862567DF006ABB06
Moreover, memory allocation in LabVIEW is implicit. You must use large set of data carefully because some function reallocate new buffers for their outputs instead of reusing the input buffers (like the function "build an array"). You will find an example of how we can decrease the memory use with array in LabVIEW in the tutorials linked above.
If you need more specific advices, you can post a sample code that reproduce the behavior that you does not understand. I will try to look at this and give you my feedback.
Sincerely.
Matthieu Gourssies, NIF. -
Binary file write cancatenat​ion during writing
Hi,
I'm trying to write a 2D array into a binary file and save the whole complete array in 2D. As shown in the picture, data is written and appended to the binary file during each loop. However, each loop would generate a 5x800 2D array (5 rows, 800 elements in each row). Right now I have to use another vi to process the binary file I saved to concatenate all the arrays in the binary file to finally obtaion a 5 x 800n (n is the number of loops) array. Is there a way to save the data into binary file in that format during each loop instead of writing into different segments and I have to concatenate different segments together after that?
On the other hand, if there's a way to do that, would that increase the loop cycle time because it's more computationally expensive? Thank you very much for your help.
Thank you,
Charles
Attachments:
picture2.png 37 KBSee the attached examples.
If you have the file open you can basically just write data to it whenever you have it available, just do not include the length. It can cost a bit to write single elements so the row option is more commonly used, but it depends on how large each row is (if they are huge then it will cost to much to keep them in memory and you write parts of each row instead...).
I have not covered cases where you need to close the file and add data later, but the difference then is just that you need to set the write position after you have re-opened the file.
MTO
Attachments:
Write and read 2D array.vi 26 KB -
Writing binary to file with 24 or 32-bit numbers
I am using an NI4472 DAQ to sample some analog data at 24-bits and I want to write the data to disk. However LabView only has a VI to write 16-bit data to disk. Is there a way to write 24 or 32 bit binary numbers to a file?
The VI you are looking at is probably one of the "Easy VIs" that is setup for a specific application. You can create more general programs to write a binary file with any data type you desire. I would recommend taking a look at the Write Binary File example that ships with LabVIEW. It shows a more general approach to writing data to a binary file. In this example they write double precision numbers but you could easily replace the data with I32s.
-
ORA-01114: IO error writing block to file %s (block # %s)
One of my large query (has a large amount of sort) fails with the following error.
ORA-01114: IO error writing block to file %s (block # %s).
Uses Oracle 9.2 on windows 2000 server. The size of the TEMPORARY file increases and stops at 4.2 GB. This was the default TEMP file created by oracle at the time of installation. I have another 10GB of free space available on this drive (where the TEMP file exists). Information in DBA_TEMP_FILES table is given below.
Thanks in advance for helps.
Paul.
FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS RELATIVE_FNO AUT MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
1 TEMP 4294967296 524288 AVAILABLE 1 YES 34359721984 4194302 1 4293918720 524160Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sda2 4127108 200124 3717336 6% /
/dev/sda1 46636 14166 30062 33% /boot
none 513884 0 513884 0% /dev/shm
/dev/sda3 11052880 5697800 4793612 55% /usr
/dev/sda6 256667 37742 205673 16% /var
/dev/sdb1 35001508 33223516 0 100% /u01
/dev/sdc1 35001508 137340 33086176 1% /u02
/dev/sdd1 35001508 19748484 13475032 60% /u03
/dev/sde1 35001508 32844 33190672 1% /u04
In the /u01 are temp01.dbf (11.039.416.320) and undotbs01.dbf (2.422.218.752) located. Can I delete or truncate the temp01 file to make space on the device or not?
Maybe you are looking for
-
Error copying from one external drive to another
Hi - I am trying to transfer three large iMovie files from an external Firewire hard drive to an external USB 2.0 hard drive. I have the USB drive connected to my 1GHz TiBook through a PCMCIA card. I have the Firewire drive connected at the TiBook's
-
How do I ask iPhoto to stop sharing select photos with Flickr ?
I have selected some 200 photos to "share" with Flickr, unknowing it meant synching, not just uploading. Now I want to remove some of those photos from Flckr but want to keep the local copies on iPhoto (9.5.1) in my Mac intact. I hear removing on Fl
-
Status profile at header and item level
27.11.2007 Hi friends, I have created a status profile at the header with option like CRTD and APPRD. The transaction control is Forbid billing when CRTD and Allow Billing when APPRD. I have attached this profile to the Sales document header. At the
-
Data packets not updated in PSA
Dear Friends, Can anybody help me on this topic. A process chain is in error and the error message is "Data records were marked as incorrect in the PSA" how can i maintenance the PSA to upload the relevant data packet or is there any other way to ed
-
ME51N Error in Document No.
Dear All When i am working with ME51N (RFQ) entring document no it is giving a message "Document Number not within Defined Interval. Kindly Help me. Regards Alok