Mac-虚拟串行端口 [英] Mac - Virtual Serial Port

查看:923
本文介绍了Mac-虚拟串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个Cocoa应用程序,该应用程序将创建可用于其他应用程序的虚拟串行端口,这意味着已在IO Kit注册表中注册.

I need to create a Cocoa app that will create a virtual serial port available to other apps, meaning registered in the IO Kit Registry.

应用要点:

  • 创建一个虚拟串行端口(在/dev中列出并在IOKit注册表中注册)
  • 启动与另一台计算机的TCP连接
  • 将虚拟串行端口上收到的所有内容代理到 网络,反之亦然.
  • Create a virtual serial port (listed in /dev and registered with the IOKit Registry)
  • Initiate a tcp connection out to another computer
  • Proxy everything received on the virtual serial port out to the network and vice versa.

与计算机上的串行端口通信的第三方应用程序将使用此应用程序,从而可以在网络上定位特定的串行设备.可可和网络部分没问题,我已经编写了一些通过网络交谈的应用程序.我的挂断是串行端口.

This app will be used by third party apps that talk to serial ports on the computer, allowing for the particular serial device to be located across the network. The Cocoa and network part is no problem, I've written several apps that talk over the network. My hangup is the serial port.

我已经用socat/netcat/minicom进行了测试,以验证它是否可以代理网络上的pty/tty流量,但是我使用的tty并未显示为可被随机应用程序使用,因为它未在其中注册IO Kit注册表.

I've done the test with socat/netcat/minicom to verify that it all works to proxy pty/tty traffic over the network but the tty I use doesn't show up as usable by random applications because it's not registered in the IO Kit Registry.

虽然我可以使用pty/tty主站/从站进行通信,但我需要此从站tty才能显示给Mac应用程序.非常方便的是一种在IO Kit注册表中注册tty的方法.

While I can use a pty/tty master/slave for the communication, I need this slave tty to show up to Mac applications. What would be very handy is a way to register a tty in the IO Kit Registry.

我真的需要创建在Cocoa应用运行时注册的自定义IOKit kext驱动程序吗?如果是这样,那么我的学习曲线就很大.我应该从哪里开始阅读?或者,我可以使用IOKit创建虚拟串行端口并将其注册为应用程序可用的串行端口,而不必加载任何内核扩展吗?

Do I really need to create a custom IOKit kext driver that gets registered at Cocoa app runtime? If so, I have a big learning curve ahead of me. Where should I start reading? Or, can I use IOKit to create a virtual serial port and register it as a usable serial port for applications without having to load any kernel extensions?

感谢您提供的任何帮助,
有状态的

Thank you for any help you can provide,
Stateful

推荐答案

首先,您是否检查过是否可以从

First of all, have you checked if you can borrow a solution from this app? It's not obvious from the website if they've managed to get their virtual serial ports fully integrated into the system.

如果有一种方法可以从用户空间执行此操作,则我不知道.用户空间IOKit API通常不允许您创建类实例,更不用说新的设备驱动程序类了.也许您可以以某种方式说服Cocoa库找到它,尽管它没有在内核中注册.

If there is a way to do it from user space, I'm not aware of it. The user-space IOKit API generally doesn't let you create class instances, let alone new device driver classes. Maybe you can somehow otherwise persuade the Cocoa libraries to find it despite not being registered in the kernel.

我不知道您是否可以在内核中创建虚拟"串行端口,然后将tty从您的用户空间守护程序移至/dev在/dev中的位置.也许这是一个选择.

I don't know if you could get away with creating a "dummy" serial port in the kernel and then move your tty into its place in /dev from your userspace daemon. Maybe that's an option.

如果您必须在内核中完成所有操作:

虚拟驱动程序本身至少不应花太多时间,尽管它需要一些时间来加快内核开发的速度.不幸的是,关于串行端口驱动程序的文档非常少-关键是IOSerialDriverSync抽象类的子类.我所看到的唯一描述是在Ole Henry Halvorsen的 OSX和iOS内核编程书中.它还提供了阅读和阅读示例的片段.写作操作. (公开:我是本书的技术审阅者之一;我没有动力推荐它-在这种情况下,这实际上是我所知道的唯一文档). Apple的USBCDC驱动程序是实际上代表串行端口节点的类.

The virtual driver itself shouldn't be too much work, at least, though it will require some time to get up to speed with kernel dev. Unfortunately, the documentation is pretty thin for serial port drivers - the key is subclassing the IOSerialDriverSync abstract class. Just about the only description I've seen is in Ole Henry Halvorsen's OSX and iOS Kernel Programming book. It also has a fragment of an example for the reading & writing operations. (disclosure: I was one of the tech reviewers for this book; I don't receive any incentives for recommending it - in this case it's literally the only documentation I know of) You can find the source for a complete serial port driver in Apple's USBCDC driver, AppleUSBCDCDMM is the class that actually represents the serial port node.

打开所谓的内核控件相对容易"内核中的套接字,单独的API 已记录这里;在用户空间中,您可以使用普通的BSD套接字send/recv API. (前面的书中也对此进行了描述)然后,您的守护程序可以连接到该守护程序,而您所需要做的就是在套接字和虚拟串行端口设备之间推送数据.当然,您需要正确处理断开连接事件.

It's relatively straightforward to open a so-called "kernel control" socket in the kernel, the individual APIs are documented here; from user space you use the normal BSD socket send/recv APIs. (this is also described in the aforementioned book) Your daemon can then connect to that, and all you'd need to do is push the data between the socket and the virtual serial port device. You'll need to handle disconnect events and such correctly of course.

不过,我认为这对于有经验的C程序员(使用某些C ++)作为第一个内核项目是可以实现的.

Still, I think this is achievable as a first kernel project for an experienced C programmer (with some C++).

希望对您有帮助!

这篇关于Mac-虚拟串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆