English 中文(简体)
From Xcode, how do I read data from a text file that is constantly being updated?
原标题:

I m working with a GPS module that is transferring data to my mac over a serial RS232-to-USB interface. I ve written a objC program that takes the raw data and converts it into meaningful information.

Using a program called goSerial, I m able to log all incoming data into a text file. I have been able to make my program read the text file and process data line by line.

I would like this procedure to happen in real time i.e. as soon as the data is received, it gets logged into the text file and my program reads it. The first part of this happens automatically that is the text file is being constantly appended (when not open). Is it possible to monitor a text file for appended data and only read new lines? Also, will doing this affect the ability of new incoming data to be saved?

Thanks!!!

(Also, if anyone knows how I may send serial data directly to Xcode, please let me know!)

最佳回答

I m not sure how the serial-to-USB affects things but traditionally, unix accesses serial devices using the Device-File Mechanism which treats the input from the device as a file to be read. You would use NSFileHandle to read the file from Cocoa/Foundation. You probably want to checkout the IORegistryExplorer app to see how your device shows up.

问题回答

You can use a kqueue (perhaps with a wrapper such as UKKQueue) to watch the file for changes.

You should be able to create a unix domain socket, which you can then have your goSerial application open (as it looks like a normal file on the fs)

And then read from the other end, linewise in your application. This is probably the easiest way, or alternately have a look at the source of tail in GNU s coreutils, specifically it s -f function (although thinking more you ll probably want to look at how the FreeBSD implementation works, as I believe that the GNU version uses some linux specific callback)





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签