读书人

关于串口发丧命令读取数据的业务逻辑实

发布时间: 2012-11-04 10:42:41 作者: rapoo

关于串口发送命令读取数据的业务逻辑实现
本人在写串口程序时遇到难题,请各位一下:
想要完成的功能阐述如下:
1.写一个类ClassA,通过ClassA.methodA,发送信息给串口,
2.ClassA实现监听接口,实现监听方法methodB,当有信息从串口返回时,将触发监听事件,调用此方法methodB()
3.接收到上一条命令的返回结果后,接着再发送命令给串口.就这样循环N次,有N个命令需要发送给串口,
4.约束条件:发送一条命令后,需要等待返回结果,才能发送下一条命令

本人大致的想法是发送一条命令调用方法methodA()后,在methodA()里调用wait(),同时设置是否已经接收的判断条件变量为receive=false,
当有返回事件,将触发监听事件,调用方法methodB(),在方法methodB()中接收返回结果,同时将receive=true和调用notify(),
如果用单线程,不能实现接收结果后再将流程转向发送再一次信息,如果使用多线程,则无法直接调用methodB(),因为methodB需要传递event参数.
以上可能写得有点罗嗦,简述一下是这样,发送A命令,等待返回结果,返回A结果,发送B命令,,等待返回结果,返回B结果,....
如何实现,我想了几天,想不通,请各位一下,万分感谢! div').each(function(comment){// comment var post_id = comment.id.substr(2); $$("#"+comment.id+" pre[name=code]").each(function(pre, index){ var location = window.location; source_url = location.protocol + "//" + location.host + location.pathname + location.search; source_url += "#" + comment.id; pre.writeAttribute('codeable_id', post_id); pre.writeAttribute('codeable_type', "BlogComment"); pre.writeAttribute('source_url', source_url); pre.writeAttribute('pre_index', index); pre.writeAttribute('title', '关于串口发送命令读取数据的业务逻辑实现'); }); }); code_favorites_init(); fix_image_size($$('div.blog_content img'), 700); function quote_comment(id) { new Ajax.Request('/editor/quote', { parameters: {'id':id, 'type':'BlogComment'}, onSuccess:function(response){editor.bbcode_editor.textarea.insertAfterSelection(response.responseText); Element.scrollTo(editor.bbcode_editor.textarea.element);} }); } new WeiboShare({share_buttons: $('share_weibo'), img_scope: $('blog_content')}); shaoxiongwang#21cn.com

读书人网 >软件架构设计

热点推荐