本文整理汇总了Python中serial_manager.SerialManager类的典型用法代码示例。如果您正苦于以下问题:Python SerialManager类的具体用法?Python SerialManager怎么用?Python SerialManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerialManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_with_callback
def run_with_callback(host, port=4444, timeout=0.01):
""" Start a wsgiref server instance with control over the main loop.
This is a function that I derived from the bottle.py run()
"""
handler = default_app()
server = wsgiref.simple_server.make_server(host, port, handler)
server.timeout = timeout
print "-----------------------------------------------------------------------------"
print "Bottle server starting up ..."
print "Serial is set to %d bps" % BITSPERSECOND
print "Point your browser to: "
print "http://%s:%d/ (local)" % ('127.0.0.1', port)
if host == '':
print "http://%s:%d/ (public)" % (socket.gethostbyname(socket.gethostname()), port)
print "Use Ctrl-C to quit."
print "-----------------------------------------------------------------------------"
print
while 1:
try:
SerialManager.send_queue_as_ready()
server.handle_request()
except KeyboardInterrupt:
break
print "\nShutting down..."
SerialManager.close()
示例2: run_with_callback
def run_with_callback(host):
""" Start a wsgiref server instance with control over the main loop.
This is a function that I derived from the bottle.py run()
"""
handler = default_app()
server = wsgiref.simple_server.make_server(host, NETWORK_PORT, handler)
server.timeout = 0.01
server.quiet = True
print "-----------------------------------------------------------------------------"
print "Bottle server starting up ..."
print "Serial is set to %d bps" % BITSPERSECOND
print "Point your browser to: "
print "http://%s:%d/ (local)" % ("127.0.0.1", NETWORK_PORT)
if host == "":
print "http://%s:%d/ (public)" % (socket.gethostbyname(socket.gethostname()), NETWORK_PORT)
print "Use Ctrl-C to quit."
print "-----------------------------------------------------------------------------"
print
try:
webbrowser.open_new_tab("http://127.0.0.1:" + str(NETWORK_PORT))
except webbrowser.Error:
print "Cannot open Webbrowser, please do so manually."
sys.stdout.flush() # make sure everything gets flushed
while 1:
try:
SerialManager.send_queue_as_ready()
server.handle_request()
except KeyboardInterrupt:
break
print "\nShutting down..."
SerialManager.close()
示例3: job_submit_handler
def job_submit_handler():
job_data = request.forms.get('job_data')
if job_data and SerialManager.is_connected():
SerialManager.queue_gcode(job_data)
return "__ok__"
else:
return "serial disconnected"
示例4: gcode_handler
def gcode_handler(gcode_line):
if SerialManager.is_connected():
print gcode_line
SerialManager.queue_for_sending(gcode_line)
return "Queued for sending."
else:
return ""
示例5: checkErr
def checkErr(* flag):
for index in range(len(flag)):
if flag[index] != 0:
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('O000'+'\r'):
relayStatus=SerialManager.read_to('\r')
print 'relay status is:',relayStatus
示例6: serial_handler
def serial_handler(connect):
if connect == '1':
print 'js is asking to connect serial'
if not SerialManager.is_connected():
try:
global SERIAL_PORT, BITSPERSECOND
SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
ret = "Serial connected to %s:%d." % (SERIAL_PORT, BITSPERSECOND) + '<br>'
time.sleep(1.0) # allow some time to receive a prompt/welcome
SerialManager.flush_input()
SerialManager.flush_output()
return ret
except serial.SerialException:
print "Failed to connect to serial."
return ""
elif connect == '0':
print 'js is asking to close serial'
if SerialManager.is_connected():
if SerialManager.close(): return "1"
else: return ""
elif connect == "2":
print 'js is asking if serial connected'
if SerialManager.is_connected(): return "1"
else: return ""
else:
print 'ambigious connect request from js: ' + connect
return ""
示例7: flash_firmware_handler
def flash_firmware_handler():
if SerialManager.is_connected():
SerialManager.close()
global SERIAL_PORT, GUESS_PREFIX
if not SERIAL_PORT:
SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX)
flash_upload(SERIAL_PORT, resources_dir())
return '<h2>flashing finished!</h2> Check Log window for possible errors.<br><a href="/">return</a>'
示例8: sendCommand
def sendCommand(command):
#clear rx_buffer
SerialManager.read_existing()
if SerialManager.write(command + '\r'):
return SerialManager.read_to('\r')
else:
return 'error'
示例9: gcode_submit_handler
def gcode_submit_handler():
gcode_program = request.forms.get('gcode_program')
if gcode_program and SerialManager.is_connected():
lines = gcode_program.split('\n')
print "Adding to queue %s lines" % len(lines)
for line in lines:
SerialManager.queue_gcode_line(line)
return "__ok__"
else:
return "serial disconnected"
示例10: gcode_submit_handler
def gcode_submit_handler():
gcode_program = request.forms.get("gcode_program")
if gcode_program and SerialManager.is_connected():
lines = gcode_program.split("\n")
print "Adding to queue %s lines" % len(lines)
for line in lines:
SerialManager.queue_for_sending(line)
return "Queued for sending."
else:
return ""
示例11: job_submit_handler
def job_submit_handler():
job_data = request.forms.get('job_data')
if job_data and SerialManager.is_connected():
lines = job_data.split('\n')
print "Adding to queue %s lines" % len(lines)
for line in lines:
SerialManager.queue_gcode_line(line)
return "__ok__"
else:
return "serial disconnected"
示例12: get_status
def get_status():
if args.raspberrypi:
powertimer.reset()
status = copy.deepcopy(SerialManager.get_hardware_status())
status['serial_connected'] = SerialManager.is_connected()
print "Connected: %d" % SerialManager.is_connected()
status['lasaurapp_version'] = VERSION
global user_approved
global user_admin
global current_user
if args.disable_rfid:
return json.dumps(status)
card_id = reader.getid()
print "Card ID %s" % card_id
username = ''
global current_cardid
if len(card_id) == 0:
print "No card inserted"
username = 'No card inserted'
user_approved = False
if current_user != '':
logger.log(current_user, 'Card removed')
current_user = ''
elif len(card_id) == 12:
if not card_id in card_data:
print "Card not found"
username = 'Unknown card'
user_approved = False
if card_id != current_cardid:
logger.log(card_id, 'Unknown card')
else:
print "Card found"
data = card_data[card_id]
username = data['name']
if data['approved']:
user_approved = True
else:
user_approved = False
if data['admin']:
user_admin = True
else:
user_admin = False
if current_user == '':
logger.log(username, 'Card inserted')
current_user = username
print "Approved: %s" % user_approved
current_cardid = card_id
else:
print "Bad length: %d" % len(card_id)
status['username'] = username
global shutdown_msg
status['shutdown_msg'] = shutdown_msg
shutdown_msg = ''
return json.dumps(status)
示例13: job_submit_handler
def job_submit_handler():
job_data = request.forms.get('gcode_program')
if not job_data:
return HTTPResponse(status=400)
if SerialManager.is_connected():
lines = job_data.split('\n')
print "Adding to queue %s lines" % len(lines)
for line in lines:
SerialManager.queue_gcode_line(line)
return "__ok__"
else:
return HTTPResponse(status=502, body="serial disconnected")
示例14: job_submit_handler
def job_submit_handler():
job_data = request.forms.get('job_data')
global user_approved
global current_user
if not user_approved and job_data[0] != "!":
print 'User not approved'
return 'Access denied'
if job_data and SerialManager.is_connected():
SerialManager.queue_gcode(job_data)
logger.log(current_user, 'Run job: '+re.sub('[\s+]', ' ', job_data)[:50])
return "__ok__"
else:
return "serial disconnected"
示例15: flash_firmware_handler
def flash_firmware_handler(firmware_file=FIRMWARE):
global user_approved
global user_admin
if not user_approved and user_admin:
return 'Access denied'
logger.log(current_user, 'Flashing ATMEGA')
return_code = 1
if SerialManager.is_connected():
SerialManager.close()
# get serial port by url argument
# e.g: /flash_firmware?port=COM3
if 'port' in request.GET.keys():
serial_port = request.GET['port']
if serial_port[:3] == "COM" or serial_port[:4] == "tty.":
SERIAL_PORT = serial_port
# get serial port by enumeration method
# currenty this works on windows only for updating the firmware
if not SERIAL_PORT:
SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
# resort to brute force methode
# find available com ports and try them all
if not SERIAL_PORT:
comport_list = SerialManager.list_devices(BITSPERSECOND)
for port in comport_list:
print "Trying com port: " + port
return_code = flash_upload(port, resources_dir(), firmware_file, HARDWARE)
if return_code == 0:
print "Success with com port: " + port
SERIAL_PORT = port
break
else:
return_code = flash_upload(SERIAL_PORT, resources_dir(), firmware_file, HARDWARE)
ret = []
ret.append('Using com port: %s<br>' % (SERIAL_PORT))
ret.append('Using firmware: %s<br>' % (firmware_file))
if return_code == 0:
print "SUCCESS: Arduino appears to be flashed."
ret.append('<h2>Successfully Flashed!</h2><br>')
ret.append('<a href="/">return</a>')
return ''.join(ret)
else:
print "ERROR: Failed to flash Arduino."
ret.append('<h2>Flashing Failed!</h2> Check terminal window for possible errors. ')
ret.append('Most likely LasaurApp could not find the right serial port.')
ret.append('<br><a href="/flash_firmware/'+firmware_file+'">try again</a> or <a href="/">return</a><br><br>')
if os.name != 'posix':
ret. append('If you know the COM ports the Arduino is connected to you can specifically select it here:')
for i in range(1,13):
ret. append('<br><a href="/flash_firmware?port=COM%s">COM%s</a>' % (i, i))
return ''.join(ret)