本文整理汇总了Python中serial_manager.SerialManager.is_connected方法的典型用法代码示例。如果您正苦于以下问题:Python SerialManager.is_connected方法的具体用法?Python SerialManager.is_connected怎么用?Python SerialManager.is_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类serial_manager.SerialManager
的用法示例。
在下文中一共展示了SerialManager.is_connected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serial_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
def serial_handler(connect):
if connect == '1':
# print 'js is asking to connect serial'
if not SerialManager.is_connected():
try:
global SERIAL_PORT, BITSPERSECOND, GUESS_PREFIX
if not SERIAL_PORT:
SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, 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:
SERIAL_PORT = None
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 ""
示例2: get_status
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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)
示例3: job_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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: flash_firmware_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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>'
示例6: gcode_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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 ""
示例7: gcode_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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"
示例8: job_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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"
示例9: job_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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")
示例10: job_submit_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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"
示例11: flash_firmware_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
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)
示例12: get_status
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
def get_status():
status = copy.deepcopy(SerialManager.get_hardware_status())
status['serial_connected'] = SerialManager.is_connected()
if HARDWARE == 'raspberrypi':
status['power'] = RPiPowerControl.get_power_status()
status['assist_air'] = RPiPowerControl.get_assist_air_status()
RPiPowerControl.set_process_status(status['serial_connected'] and not status['ready'])
else:
status['power'] = 1;
status['assist_air'] = 1;
status['lasaurapp_version'] = VERSION
status['admin'] = admin_check()
status['user'] = accessUser
status['accounts'] = accountsTable
status['statistics'] = statistics
return status
示例13: flash_firmware_handler
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
def flash_firmware_handler():
global SERIAL_PORT, GUESS_PREFIX
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())
if return_code == 0:
print "Success with com port: " + port
SERIAL_PORT = port
break
else:
return_code = flash_upload(SERIAL_PORT, resources_dir())
ret = []
ret.append("Using com port: %s<br>" % (SERIAL_PORT))
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:
SERIAL_PORT = None
print "ERROR: Failed to flash Arduino."
ret.append("<h2>Flashing Failed!</h2> Check Log window for possible errors. ")
ret.append('Most likely LasaurApp could not find the right serial port.<br><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)
示例14: get_status
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
def get_status():
status = copy.deepcopy(SerialManager.get_hardware_status())
status['serial_connected'] = SerialManager.is_connected()
status['lasaurapp_version'] = VERSION
return json.dumps(status)
示例15: get_status
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import is_connected [as 别名]
def get_status():
status = copy.deepcopy(SerialManager.get_hardware_status())
status["serial_connected"] = SerialManager.is_connected()
return json.dumps(status)