LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FileToArray or readline to read a file and show the information in a textbox

Solved!
Go to solution

CVI I am a beginner and have some basic questions.
Currently I am using CVI 2009th

I want to open a file and transform it into another format. The most important information to be displayed on the GUI.

For text output, I use the textbox.

With readline everything has worked, but for my data rows rather is impractical.

That's why I tried the same with FileToArray. But the array does not display in the text box.

I just do not know exactly how the textbox works. Does the textbox made a formfeed after a certain number of characters? Or I can write text in succession away?

 

 Here are a few lines from my code.

 

 

// FileToArray 

 

FileToArray (pathname, &fcsLine, VAL_CHAR, fcsfile_numberofelements, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_ASCII); // What is the right way to diplay text with filetoarray? SetCtrlVal (tabPanelINFO, TABINFO_FCS_VERSION, fcsLine); InsertTextBoxLine(tabPanelFCS, TABFCS_FCSBOX, -1, fcsLine); 

 

// ReadLine

 

while (ReadLine (fcsfile_open, fcsLine, fcsfile_numberofelements) >= 0)
{

InsertTextBoxLine(tabPanelFCS, TABFCS_FCSBOX, -1, fcsLine);

 

 

 

0 Kudos
Message 1 of 13
(5,935 Views)

Hi Susay,

it's not clear to me why reading line by line is not practical for your needs and which difference do you expect by passing a textfile to a textbox.

 

Having said that,  a textbox is a rather rude control: it has no limit on the line lenght but rather on total text lenght in the control. It will wrap text dividing it on lines / rows / characters based on settings made in the UIR editor or set at runtime with SetCtrlAttribute (panelhandle, controlID, ATTR_WRAP_MODE, x); It does not automatically add any form / line feed to the text passed to it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 13
(5,931 Views)
Ah ok, the lines are therefore a purely visual thing. But it is possible for me to reach a certain point in the textbox when I know the byte address, or the index of the character?
0 Kudos
Message 3 of 13
(5,928 Views)

Well, lines are not merely "a purely visual thing": you can address and retrieve the text in the texbox using several functions among which some line-oriented functions can be found. Nevertheless, it's true that modifying the word-wrap attribute influences the aspect of the control: you can experiment it directly in the UIR editor by filling a textboxwith a long text and changing Wrap mode value.

 

Text can be located by GetTextBoxLineIndexFromOffset, GetTextBoxLineOffset or retrieved line-by-line with GetTextBoxLine or even deleted with DeleteTextBoxLine: these functions are fully described in the online help so you can study the characteristics of each of them.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 13
(5,924 Views)

With your help, I understood the problem. It works great with ReadLine. But now I see the file has also hex numbers. I read in the forum that hex can not read by ReadLine. Smiley Sad

Now I try again with ScanFile.

0 Kudos
Message 5 of 13
(5,895 Views)

What exactly do you mean by "hex can not read by ReadLine"? Which forum posts are you referring to?

 

If you can you post here a small sample file we can look at it and verify the best options for you to read it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 13
(5,892 Views)

I read this thead  How do you read hex digits from file? I want convert a fcs file into a csv file.

 

FCS code looks like this:

 

FCS2.0 266 1791 1792 235377 0 0 0 0 0 0 0 0 0 0 235378 239673 239674 239865 239866 243304 0 0 0 0 0 0 0 0 0 0 0 0|$PROJ|Project|$DATATYPE|I|$CELLS|CD8 |$TOT|6147|$SRC|Source|$MODE|L|$SMNO|5|$PAR|19| 0|o~ÿ/î3 C Pkdåt$€""¡ê³ Àõ­¾½øÏÿßÿïÿÿ?Ç/À3éBoP›c˜s$€"G¢ ² Àõ­¾½øÏÿßÿïÿÿ¯Ä|!º3¡B1Pdt$€" ,° Àõ­¾½øÏÿßÿïÿÿ°ä!4¿FvRInÚ{$€"äª,¸ Àõ­¾½øÏÿßÿïÿÿåö x1¨A‹P„cWq$€" ’³ Àõ­¾½øÏÿßÿïÿÿoZC!3ãA Pc„r$€" ³ Àõ­¾½øÏÿßÿïÿÿŸÛÿ/m3 DþPte³t$€"~¢×² Àõ­¾½øÏÿßÿïÿÿï^ÿ/ 4¼C PdeËt$€!%¢‹³

The first digits indicate where are the data position.
Then begins a data block in asci, and then followed by a block in hex.

 

With ReadLine I can read the data position and the first block. But now I do not know how I correct choice the hexadecimal numbers. I've even opened the file in ASCII code?

 

0 Kudos
Message 7 of 13
(5,889 Views)

Ok, so you are dealing with bynary data to read from the file. First of all, the post you linked refers to FileToArray () function, an I/O function which opens a file, reads its content in memory and closes it. It is basically different from ReadLine or ScanFile functions: ArrayToFile is useful to read files with numeric data only, which is not your case.

 

On the other hand, ReadLine actually reads file content into a string, without splitting it into data fields. On the data you have posted, ReadLine will read the entire field into a single string, since inside the data no linefeed is present. It will be up to you to extract from the string the values you need. It is possibly not the best approach...

 

Another option can be to read directly from binary format into memory, defining an appropriate datatype to read in file content. I don't know FDS file format (which of them is? Smiley Surprised ) so I made a rough trial to describe the data structure: knowing the exact data format you will be able to define the appropriate structure; the result will be something like that:

 

 

typedef struct {

   char   type[3];

   char   version[7];

   char   n1[32][8];

   char   header[95];
   char   data[291];

 }  fds_format;

fds_format s;


fH = fopen ("c:\\FCS file.fcs", "rb");
fread ((char *)&s, sizeof(fds_format), 1, fH);
fclose (fH);

 

 

My attempt correctly scans all (hypothetic Smiley Wink ) fields in text section, doing nothing in the binary section which is simply read int 'data' field.

 

I understand that this is not so simple to understand: I will be glad to clarify your doubts if any.

Message Edited by Roberto Bozzolo on 02-12-2010 05:31 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 8 of 13
(5,883 Views)

I mean Flow Cytometry Standard -> File format #5 .

Until now I have read the entire line into a string and then transmit the segments in separate strings. A structure is certainly the most elegant solution. But at the moment it works without structure fine. Is there a way to store the data word by word with ReadLine without the intermediate step with additional arrays, just as I currently do.

What difference does it make whether I  open the file with ASCCI or binary. My program works independently from this setting?!

The next steps for me are to show the segments with tables, to edit correctly the hexa sign,  and to store data in the new file format. 

Is still unclear how to deal with tables and, above all, dealing with the hexa data.

0 Kudos
Message 9 of 13
(5,849 Views)
Solution
Accepted by topic author susay

Ok I have found some documentation on your data format and it seems at a first glance not so diffucult to decode.

 

Some answers to your questions:

1. Opening a file in ASCII mode permits to the system to recognize and accomodate the correct new line character sequence (the one which lets ReadLine to terminate reading). Since you are dealing with binary data maybe ASCII option is not the best you can use

2. Using a data structure or scanning the single lines into meaningful variables is somewhat equivalent: in my opinion the structure is more immediate, it may not need any further data arrangement to have variables populated with correct vales (it depends on data packing and data format: little- or big-endian and so on)

3. As far as I have seen into the part of file you have posted, the hex bytes you are observing are not into the file: they are only a way your viewer uses to represent non-printable, binary data



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 10 of 13
(5,823 Views)