OS X 与 Linux - 串行端口处理

发布于 2024-09-15 10:22:12 字数 917 浏览 1 评论 0原文

我正在尝试将纯 Linux 应用程序移植(或者更确切地说自定义)到 OS X Snow Leopard (10.6.4)。它是一个通过串行端口将二进制文件发送到目标硬件的应用程序。该应用程序几乎正在运行,但我在串行端口写入方面遇到了一个有趣的问题。

使用与 Linux 相同的设置(115.2k 是波特率),OS X 串行数据发送似乎比 Linux 慢 10 倍或更多。在 Linux 中需要 3 秒的事情,需要 30-40 秒,到那时接收端的目标固件就会超时:)。

深入研究串行端口写入函数,我发现它正在使用 select() 系统调用来查找设备(或者更确切地说文件描述符)是否准备好写入数据。每个 write 系统调用在 OS X 中写入 1024 字节的数据,在 Linux 中写入 1087 字节的数据(这就是 write 的返回值)。对于第一级二进制文件,我的数据大小约为 50KB(它是一个小型引导加载程序,可以在下一级加载更大的二进制文件)。

伪代码

    select() configuration with 1s time out and observing the serial port file descriptor for write ready.
while(true)
{
rc=select(...)
if(rc>0){write(...) and other logic to get out of while if done}
if(rc==0){//try again}
if(rc<0){//error}
}

我观察到,在linux中,写入总是一个接一个地发生。一系列的写入,很快就从函数中出来了。但是,在 OS X 中,就像 3 次写入,然后选择两次返回零(2 秒消失),再次进行几次写入和选择超时等,使得该函数速度慢很多。

有什么线索吗?

笔记: 该应用程序使用 termios lib API 来控制串行端口。

I am trying to port (or rather customize) a pure Linux application to OS X Snow Leopard (10.6.4). It is an application that sends a binary to a target hardware over the serial port. The app is almost running but i am hit with an interesting problem with the serial port writes.

With all the same settings as Linux (115.2k is the baudrate) OS X serial data send seems to be some 10 times or more slower compared to Linux. What takes 3 secs in Linux , takes 30-40 secs and by that time the target firmware at the receiving end times out :).

Digging in to the serial port write function, i see that it is using select() system call to find if the device (or rather the file descriptor) is ready to write data to. Each write system call writes 1024 bytes of data in OS X and 1087 bytes of data in Linux (Thats what the return value of write is). My data size is some 50KB for a first level binary (it is a small bootloader which can load a bigger binary in the next level).

Pseudo code

    select() configuration with 1s time out and observing the serial port file descriptor for write ready.
while(true)
{
rc=select(...)
if(rc>0){write(...) and other logic to get out of while if done}
if(rc==0){//try again}
if(rc<0){//error}
}

I observed that in linux, writes happen all the time one after another . A sequence of writes and it comes out of the function in a jiffy. But, in OS X, it is like 3 writes and then select returns zero twice (2 seconds gone) again a few writes and select time out etc etc making the function a lot slower.

Any clues?

Notes:
The app is using termios lib API to control the serial port.

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

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

发布评论

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

评论(1

野生奥特曼 2024-09-22 10:22:12

我可以通过更改多产的芯片设备驱动程序来解决这个问题。默认情况下,它使用非标准开源驱动程序,我从多产网站下载了 OS X 驱动程序,它工作正常。
感谢尼尔斯和其他人的支持!

I could fix this by changing the prolific chip device driver. By default it was using a non-standard open source driver, I downloaded the OS X driver from the prolific website and it works ok.
Thanks to Nils and others for the support!

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