在 Xcode 中,如何从不断更新的文本文件中读取数据?

发布于 2024-08-13 07:01:39 字数 343 浏览 4 评论 0原文

我正在使用 GPS 模块,该模块通过串行 RS232 至 USB 接口将数据传输到我的 Mac。我编写了一个 objC 程序,它获取原始数据并将其转换为有意义的信息。

使用名为 goSerial 的程序,我可以将所有传入数据记录到文本文件中。我已经能够让我的程序读取文本文件并逐行处理数据。

我希望这个过程实时发生,即一旦收到数据,它就会被记录到文本文件中,并且我的程序会读取它。第一部分是自动发生的,即文本文件不断附加(未打开时)。是否可以监视文本文件中的附加数据并仅读取新行?另外,这样做会影响新传入数据的保存能力吗?

谢谢!!!

(另外,如果有人知道如何将串行数据直接发送到 Xcode,请告诉我!)

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!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

饭团 2024-08-20 07:01:39

我不确定串行到 USB 如何影响事物,但传统上,unix 使用 设备文件机制 将来自设备的输入视为要读取的文件。您可以使用 NSFileHandle 从 Cocoa/Foundation 读取文件。您可能想检查 IORegistryExplorer 应用程序以查看您的设备如何显示。

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.

泪痕残 2024-08-20 07:01:39

您可以使用 kqueue (可能使用诸如 UKKQueue 之类的包装器)来监视文件的更改。

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

此岸叶落 2024-08-20 07:01:39

您应该能够创建一个 unix 域套接字,然后您可以打开 goSerial 应用程序(因为它看起来像 fs 上的普通文件),

然后从另一端在应用程序中逐行读取。这可能是最简单的方法,或者看看 GNU 的 coreutils 中的 tail 源代码,特别是它的 -f 函数(尽管想得更多,你可能想看看 FreeBSD 实现是如何工作的,因为我相信 GNU版本使用一些 linux 特定的回调)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文