Unix设备文件仿真 [英] Unix Device File Emulation

查看:56
本文介绍了Unix设备文件仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,

所以我得到了一个快速查询建议。


我们有一个嵌入式设备,我们在其中显示LCD

设备位于/ dev / screen。这个设备不是很容易获得

,所以我需要编写一个模拟器。这将是

基本上只是监视一个文件,例如/ dev / screen,并将

命令写入TK或WxWindows画布。


所以发送''line 0 0 10 10''会在我的画布上画一条线,从(0,0)

到(10,10)。

我的问题:这个文件设置一个监视器(在python中)的最佳方式是什么?
这个文件?我是否只需打开文件进行阅读,检查

更改,获取更新的数据并清除文件?或者是否有一些

这样做的标准方式可以保证不重叠

或数据丢失?


示例用法: echo''line 0 0 10 10''/ dev / screen

在实际的嵌入式设备上,这是由内核模块处理的。我们

可以尽可能快地将命令吐入其中,内核模块可以跟上
。这是典型的unix设备文件行为。


任何建议或建议都会很精彩。谢谢!

Blaine

解决方案

blaine写道:


大家好,

所以我快速查询了一下建议。


我们有一个嵌入式设备,我们在其中显示一个LCD

位于/ dev / screen的设备。这个设备不是很容易获得

,所以我需要编写一个模拟器。这将是

基本上只是监视一个文件,例如/ dev / screen,并将

命令写入TK或WxWindows画布。


所以发送''line 0 0 10 10''会在我的画布上画一条线,从(0,0)

到(10,10)。

我的问题:这个文件设置一个监视器(在python中)的最佳方式是什么?
这个文件?我是否只需打开文件进行阅读,检查

更改,获取更新的数据并清除文件?或者是否有一些

这样做的标准方式可以保证不重叠

或数据丢失?


示例用法: echo''line 0 0 10 10''/ dev / screen

在实际的嵌入式设备上,这是由内核模块处理的。我们

可以尽可能快地将命令吐入其中,内核模块可以跟上
。这是典型的unix设备文件行为。


任何建议或建议都会很精彩。谢谢!

Blaine



看起来你需要类似Unix''tail -f''命令的东西。

或许这里有一些帮助

http://aspn.activestate.com/ASPN/Coo.../Recipe/414771
http://mail.python.org/pipermail/pyt...st/157510.html
http://pyinotify.sourceforge.net/

- -

Helmut Jarausch


Lehrstuhl fuer Numerische Mathematik

RWTH - 亚琛大学

D 52056亚琛,德国


blaine写道:


示例用法:echo''line 0 0 10 10''/开发/屏幕


关于实际的嵌入式d设备由内核模块处理。我们

可以尽可能快地将命令吐入其中,内核模块可以跟上
。这是典型的unix设备文件行为。


任何建议或建议都会很精彩。谢谢!



假设您使用的是unix,您是否考虑过FIFO',os.mkfifo()?


(让我们再试一次,实际上这次将它发送到列表中)


2008年4月23日星期三上午11:02,blaine< fr * **** @ gmail.com写道:


嘿大家,

所以我快速查询建议。 />

我们有一个嵌入式设备,我们在其中显示位于/ dev / screen的LCD

设备。这个设备不是很容易获得

,所以我需要编写一个模拟器。这将是

基本上只是监视一个文件,例如/ dev / screen,并将

命令写入TK或WxWindows画布。


所以发送''line 0 0 10 10''会在我的画布上画一条线,从(0,0)

到(10,10)。

我的问题:这个文件设置一个监视器(在python中)的最佳方式是什么?
这个文件?我是否只需打开文件进行阅读,检查

更改,获取更新的数据并清除文件?或者是否有一些

这样做的标准方式可以保证不重叠

或数据丢失?


示例用法: echo''line 0 0 10 10''/ dev / screen

在实际的嵌入式设备上,这是由内核模块处理的。我们

可以尽可能快地将命令吐入其中,内核模块可以跟上
。这是典型的unix设备文件行为。


任何建议或建议都会很精彩。谢谢!

Blaine

-
http://mail.python.org/mailman/listinfo/python-list



'只有'与来自python的设备文件进行交互,我只是从b
读取。我猜他们在技术上是在/ proc和/ sys,

而不是/ dev,尽管它们可能以相同的方式处理。无论如何,

在这种情况下,我的方法基本上是打开文件,读取它,关闭

它,做我需要对数据做的任何处理,为一些人睡觉

间隔...泡沫,冲洗,重复。在某些时间间隔内睡觉可能不适用或者b / b
可能不合适。我知道在/ proc

文件和/ sys文件的情况下,文件是由内核按需生成的,并且相关的内核结构基本上打印成一个字符串,

复制到用户程序可以访问的内存页面中。 AFAIK,

你可以通过他们来回寻找,但我不知道页面中的

数据是否在搜索中更新,所以你可能有关闭和

重复打开文件迭代,看看有什么变化。


HTH,

-dan


Hey everyone,
So I''ve got a quick query for advice.

We have an embedded device in which we are displaying to an LCD
device that sits at /dev/screen. This device is not readily available
all the time, so I am needing to write an emulator. This will
basically just monitor a file, /dev/screen for example, and write the
commands to a TK or WxWindows canvas.

So sending ''line 0 0 10 10'' will draw a line on my canvas from (0,0)
to (10,10).

My question: Whats the best way to set up a monitor (in python) of
this file? Would I simply open up the file for read, check for
changes, get any updated data, and clear the file? Or is there some
standard way of doing something like this that guarantees no overlap
or data loss?

example usage: echo ''line 0 0 10 10'' /dev/screen

On the actual embedded device this is handled by a kernel module. We
can spit commands into it as fast as we can and the kernel module can
keep up. This is typical unix device file behavior.

Any suggestions or advice would be splendid. Thanks!
Blaine

解决方案

blaine wrote:

Hey everyone,
So I''ve got a quick query for advice.

We have an embedded device in which we are displaying to an LCD
device that sits at /dev/screen. This device is not readily available
all the time, so I am needing to write an emulator. This will
basically just monitor a file, /dev/screen for example, and write the
commands to a TK or WxWindows canvas.

So sending ''line 0 0 10 10'' will draw a line on my canvas from (0,0)
to (10,10).

My question: Whats the best way to set up a monitor (in python) of
this file? Would I simply open up the file for read, check for
changes, get any updated data, and clear the file? Or is there some
standard way of doing something like this that guarantees no overlap
or data loss?

example usage: echo ''line 0 0 10 10'' /dev/screen

On the actual embedded device this is handled by a kernel module. We
can spit commands into it as fast as we can and the kernel module can
keep up. This is typical unix device file behavior.

Any suggestions or advice would be splendid. Thanks!
Blaine

It looks as if you need something like the Unix ''tail -f'' command.
Perhaps here is some help

http://aspn.activestate.com/ASPN/Coo.../Recipe/414771
http://mail.python.org/pipermail/pyt...st/157510.html
http://pyinotify.sourceforge.net/
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany


blaine wrote:

example usage: echo ''line 0 0 10 10'' /dev/screen

On the actual embedded device this is handled by a kernel module. We
can spit commands into it as fast as we can and the kernel module can
keep up. This is typical unix device file behavior.

Any suggestions or advice would be splendid. Thanks!

Assuming you are on unix, have you considered FIFO''s, os.mkfifo()?


(let''s try this again, and actually send it to the list this time)

On Wed, Apr 23, 2008 at 11:02 AM, blaine <fr*****@gmail.comwrote:

Hey everyone,
So I''ve got a quick query for advice.

We have an embedded device in which we are displaying to an LCD
device that sits at /dev/screen. This device is not readily available
all the time, so I am needing to write an emulator. This will
basically just monitor a file, /dev/screen for example, and write the
commands to a TK or WxWindows canvas.

So sending ''line 0 0 10 10'' will draw a line on my canvas from (0,0)
to (10,10).

My question: Whats the best way to set up a monitor (in python) of
this file? Would I simply open up the file for read, check for
changes, get any updated data, and clear the file? Or is there some
standard way of doing something like this that guarantees no overlap
or data loss?

example usage: echo ''line 0 0 10 10'' /dev/screen

On the actual embedded device this is handled by a kernel module. We
can spit commands into it as fast as we can and the kernel module can
keep up. This is typical unix device file behavior.

Any suggestions or advice would be splendid. Thanks!
Blaine
--
http://mail.python.org/mailman/listinfo/python-list

''ve only interacted with device files from python that I was only
reading from. And I guess technically they were under /proc and /sys,
rather than /dev, although they may be handled the same way. Anyway,
in that case my method was basically to open the file, read it, close
it, do whatever processing I needed to do on the data, sleep for some
interval...lather, rinse, repeat. Sleeping for some interval may or
may not be appropriate in your case. I know in the case of /proc
files and /sys files, the files are generated on demand by the kernel
and relevant kernel structures are basically printed to a string and
copied into a page in memory that the user program can access. AFAIK,
you can seek back and forth through them, but I don''t know whether the
data in the page is updated on a seek, so you may have to close and
reopen the file ever iteration to see what''s changed.

HTH,
-dan


这篇关于Unix设备文件仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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