要实现这个需要用到 html js 和 后端 比如 flask ,这个看起来容易实际上是网页前端+后端+硬件通信几方面都要有的。
前端:
https://bitbucket.org/cxsys/fdb/src/6f4295cfb3defeacc3f4cdd1d183b18d519e4003/py_framework/static/index.html?at=cache大体流程是用 jquery 实现文本框里的按键事件触发一个 GET :
if (event.keyCode==40 || event.keyCode==39 ){
$('#output_state').val ("t");
OPT ();
return;
}
function _OPT (){
$.ajax ({
type: 'GET',
url: '/output',
data: {'board_num': $('#board_num').val (),'output_num': $('#output_num').val (),'output_state': $("#output_state").val ()},
success: function (_callback ){
$('#text').text (_callback );
board_controll_char=eval (_callback.replace ("\r","").replace ("\n",""));
drawM (board_controll_char );
}
});
}
就 GET 到了 flask 做的服务端:
https://bitbucket.org/cxsys/fdb/src/6f4295cfb3defeacc3f4cdd1d183b18d519e4003/py_framework/fdb_server.py?at=cache@
app.route ("/output",methods=['POST', 'GET'])
def doget ():
_o (int (request.args.get ("board_num","")),int (request.args.get ("output_num","")),request.args.get ("output_state",""))
return repr (_fdb.get_board_controll_char ())
调用了_o ()函数,就是硬件部分 fdb 类的输出函数 :_o=_fdb.output
https://bitbucket.org/cxsys/fdb/src/6f4295cfb3defeacc3f4cdd1d183b18d519e4003/py_framework/fdbfischer.py?at=cache def output (self,board_num,output_num,state=None ):
"""board_num is which board you want to choose ,for example 1 or 2 or 3 or 4
output_num is which output you want to choose ,for example 1 or 2 or 3 or 4,like the M1 to M4 on ficherBoard
state is the state you want,for example 'z' or 'y' or 't',they means antiClockwise (aw ) and clockwise and stop
"""
if type (board_num )==type ((1,2 )):
state=output_num
output_num=board_num[1]
board_num=board_num[0]
self.board_controll_char[board_num-1]=\
self._generate_state_char (self.board_controll_char[board_num-1],output_num,state )
print self.board_controll_char