12-21-2009 02:02 AM
在Labwindows/cvi中怎样把一个TXT文件显示出来让我们可以看到其中的内容,同时还可以在程序里往TXT文件添加数据,并可以实时看到添加的数据?
期待高人指点。
Solved! Go to Solution.
12-23-2009 09:41 PM
你好,
获取文件的方法可以作如下参考:
FILE *fp;
char line [256];
fp = fopen ("TextFile.txt", "rt");
while (fgets (line, 256, fp))
SetCtrlVal (panel, PANEL_TEXTBOX, line);
fclose (fp);
写入数据的参考:
OpenFile (source, open for reading in ascii mode)
OpenFile (destination, open for writing in ascii mode)
while (1) {
result = ReadLine (from source)
if (result == -2) break // End-of-file reached
Scan the buffer
Create the new buffer with selected fields using sprintf or Fmt functions
WriteLine (to destination)
}
CloseFile (source)
CloseFile (destination)
如果需要看到是什么数据的话,将待写入的数据同时显示在控件中就可以了。
希望能帮上忙
01-05-2010 09:11 PM
感谢晓建的详细解答。
后来发现创建了TXT文件后,在CVI中可以用LaunchExecutable ("notepad.exe datalog");(datalog为我创建的文本文件名)显示;
但是实时显示程序中写入TXT文件的数据还是做不到。
LaunchExecutable ("notepad.exe datalog");只会显示在调该指令前已写入datalog的数据;调用后写入的显示不出来。
01-06-2010 07:29 PM
这个问题很有意思,调用LaunchExecutable ("notepad.exe datalog");之后,相当于你在WINDOWS文件夹里面对着这个TXT文件双击打开。这样就有一个问题,在Windows中,是不允许你写入一个正在被打开的文件的,你试试看WORD等就知道。但是TXT特殊,WINDOWS只是打开了他的一个副本,也就是说将该文件的所有内容读到内存里面来就关掉该文件了。
你可以试试看,在打开一个TXT文件后,你可以将这个文件删除掉,而其格式的文件可不行。
那么,如果这样的话,你要刷新就再调用该语句一次,再打开一个副本就刷新了。
01-06-2010 07:58 PM - edited 01-06-2010 07:59 PM
Hi!
Windows notepad is not designed to do what you've asked for.
You should use standard I/O window to display what you're writing to
the txt file simultaneously for that purpose.
Alternatively, download the real-time text/log viewer like
"Tail for Win32" http://tailforwin32.sourceforge.net/
or "Tail XP" http://www.freedownloadmanager.org/downloads/Tail_XP_23837_p/
for your application.
01-06-2010 08:05 PM - edited 01-06-2010 08:07 PM
That is right. dcl9000's reply is closer to what you want!