【问题标题】:Two-way communication using expect使用expect的双向通信
【发布时间】:2011-08-27 22:34:41
【问题描述】:

我正在编写一个expect 脚本来自动化/dev/ttyUSB0 上的arduino 和本地telnet 端口6789 上的xine 实例之间的通信。如果在arduino 上检测到按键,它将通过它的串行发送一条线输出,button 01 pressedbutton 2 pressed 等等。现在,根据按下的按钮,我想告诉xine 开始播放某些电影。

到目前为止,两种通信都是独立工作的,但我需要使用 telnet 消息对 arduino 消息做出反应,就像这个例子:

User presses key 1.
arduino sends serial line "button 01 pressed"
expect sees this string on /dev/ttyUSB0 and sends "playlist delete all; mrl add movie01.mp4" to xine.
xine then plays this movie while I am asking it for it's status every second.
Once the movie is finished playing, I tell xine to start the "loop" movie and also the arduino to set every output to the idle state.

所以,基本上我要求两种spawn同时进行通信(一个串行,一个远程登录),expect在它们上使用不同的字符串并以编程方式对它们做出反应(而最后一部分,以编程方式反应,已经完成)。

感谢您的帮助,

Christian.

【问题讨论】:

    标签: linux expect


    【解决方案1】:

    您可以尝试使用 expect 和 -i 来指定您要与之通信的 spawn id,并设置一个小的超时值,然后您可以在两个进程之间进行预期。

    【讨论】:

    • 听起来很有趣 - 你能从其他地方找到一个我可以查看/阅读的小例子吗?
    猜你喜欢
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    相关资源
    最近更新 更多