LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

realtime update of a txt file

Hi,
I want to update a text file in realtime with the data i obtain at my COM port. I want to run the executable, keep it open and update the data.
I tried the following sequence
1- LaunchExecutable (notepad.exe)
2- Read the Data at COM port
3- Write to the file
Repeat the steps 2 & 3 till i press Stop.

Can we keep the file open and update data online.The data should scroll and keep updating as it happens in DOS.

Regards,
siddu
0 Kudos
Message 1 of 10
(4,503 Views)
Hello

Are you trying to display the COM port data as its coming in using notepad?
If you just need to make sure that the text file is as up to date as possible, you can just use the file i/o functions to write to the text file and keep on flushing the text data buffer as often as possible. This will ensure that its actaully written to the disk and not in an intermediate buffer.
But if you want to actaully see the text data as if its getting typed out ( like hyper term for example), you could just use the CVI text box control and append the text string data each time you acquire something new.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 10
(4,502 Views)
Hi,
Will there be any delay issues for updating the text box. Any idea of how much time it will take in updating a byte to text box.

Regards,
Siddu
0 Kudos
Message 3 of 10
(4,502 Views)
I would think that the effects would be negligible with respect to how fast the data is coming in from the COM port. If you are concerned about the speed, you could have a seperate thread aquiring the data and writing it into a thread safe queue ( part of the CVI multi threading library) and then in your UI thread, you could read from the queue. THis way, your aquisition would never have to slow down on account of any UI delays.

Bilal
Bilal Durrani
NI
0 Kudos
Message 4 of 10
(4,502 Views)
Siddu,

When a program like CVI or notepad opens a file for reading or writing, it is read from or written to in the program's memory. The actual file on disk does not change until the file is saved (notepad) or closed (CVI). The easiest thing to do is write all the text twice: use printf statements to print to the console (just like DOS) which will be done in realtime, and use either the CVI File I/O functions (OpenFile, WriteFile, etc.) or the C stdio functions (fopen, fprintf, fclose, etc.) to write to a log file. This way you can monitor the output of your program as it runs, and you will also have a log file to examine more closely.

Hope that helps.
Mert
0 Kudos
Message 5 of 10
(4,502 Views)
Hi,
Thanks for the information. That helped me a lot.

Regards,
Siddu
0 Kudos
Message 6 of 10
(4,502 Views)
Hi,
Actually i changed my application from your inputs.
I should keep reading the bytes at the 2 COM ports.
So i have a multi thread applictaion using timers. The sequence of operation is as follows.
1-enable Timer1 and Timer2 at 1ms ticktime
2-read the bytes at Port under the timer tick event
3-updation of text box under the timer tick event
4-continue the events 2 & 3 till i Press 'STOP' command button which disables the timers.

This application works but it's using 98% of CPU thereby slowing down this application and the other applications.

Is this because of updation of Text Box under the same Timer.
Can you give me some suggestion to reduce the CPU usage to normal.

Regards,
Siddu
0 Kudos
Message 7 of 10
(4,502 Views)
Are you using async timers? Because UI timers run in the UI (single) thread. This is happening because of the 1ms timer. Try increasing the timer interval and check to see whether you actaully need to update it that fast.

You can find examples of the async timer under ..\samples\toolbox\asyncdem.cws. These are timer callbacks that are multi-threaded.

Bilal
Bilal Durrani
NI
0 Kudos
Message 8 of 10
(4,502 Views)
Will there be any difference in using two UI timers with 100ms timer and using async timers.Which one should i prefer in running my application of reading bytes at 2 COM ports.
Regards,
Siddu
0 Kudos
Message 9 of 10
(4,502 Views)
In terms of CPU usage, there shouldnt be much different. UI timer callbacks run in the same thread as the UI thread, where as the asyn timer callbacks happen in another thread.

Bilal
Bilal Durrani
NI
0 Kudos
Message 10 of 10
(4,502 Views)