本文整理汇总了Python中serial.close函数的典型用法代码示例。如果您正苦于以下问题:Python close函数的具体用法?Python close怎么用?Python close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serializeFromSerial
def serializeFromSerial():
serial.open()
data = serial.readline() # Read the next line from serial
serial.close()
print(data) # Print the data to terminal for debugging purposes
j = json.loads(data) # Load the raw string as JSON
return j # Return the JSON
示例2: summary
def summary():
trace("SUMMARY:",log_trace)
trace("Errors : " + str(s_error),log_trace)
if s_error==0:
trace("Result : No errors occurred.",log_trace)
else:
trace("Self Test FAILED",log_trace)
if online==1:
print "Saving results on remote server"
url = 'http://plm.fabtotum.com/reports/add_report.php'
files = {'file': open(log_trace, 'rb')}
info={'ID':controller_serial_id, 'result':s_error}
try:
r = requests.post(url,info, files=files)
trace("Self Test results saved online",log_trace)
except:
#print "Response: " + r.text
trace("Could not contact remote support server, is Internet connectivity available?",log_trace)
if s_error>0:
#clean the buffer and leave
#shutdown temps
serial.write("M104 S0\r\n") #shutdown extruder (fast)
serial.write("M140 S0\r\n") #shudown bed (fast)
serial.flush()
serial.close()
write_json('1', status_json)
call (['sudo php /var/www/fabui/script/finalize.php '+str(task_id)+" self_test"], shell=True)
sys.exit()
示例3: test_serial
def test_serial():
try:
serial = open_serial()
serial.open()
serial.close()
except:
syslog.syslog(syslog.LOG_CRIT, "Failed to open serial device")
sys.exit(os.EX_UNAVAILABLE)
示例4: sendGPSData
def sendGPSData(serial, queue):
# print("serial: %s" % serial)
soc = queue.get()
count = 1
while True:
try:
# print('s: %s' % s)
msg = serial.readline().decode()
if( count%150 == 0 ):
print('gps msg: %s' % msg)
count += 1
nmea_msg = pynmea2.parse(msg)
# print("%s\n" % nmea_msg)
# nmea_msg = pynmea2.parse(s.readline().decode())
# nmea_msg = pynmea2.parse(s.readline().decode())
# print('nmea_msg: %s' % nmea_msg)
# print('nmea_msg.sentence_type: %s' % nmea_msg.sentence_type)
if nmea_msg.sentence_type == "RMC":
# print("%s\n" %nmea_msg)
# print('Latitude: %d, %s' % (nmea_msg.latitude, nmea_msg.lat_dir))
# print('Longitude: %d, %s' % (nmea_msg.longitude, nmea_msg.lon_dir))
# print('GPS Heading: %d' % nmea_msg.true_course)
# print('Date/Time: %s\n' % datetime.datetime.combine(nmea_msg.datestamp, nmea_msg.timestamp).isoformat())
soc.sendall(msg.encode())
# soc.send(nmea_msg.encode('utf-8'))
time.sleep(0.1)
else:
print('wrong msg: %s' % nmea_msg)
except pynmea2.nmea.ChecksumError as ce:
# print("ChecksumError: %s" % ce)
pass
except pynmea2.nmea.ParseError as pe:
# print("ParseError: %s" % pe)
pass
except UnicodeDecodeError as ud:
print("UnicodeDecodeError: %s" % ud)
pass
except AttributeError as ae:
# print("AttributeError: %s" % ae)
pass
except ValueError as ve:
print("ValueError: %s" % ve)
pass
except TypeError as te:
print("TypeError: %s" % te)
pass
except:
traceback.print_exc(file=sys.stdout)
print("closing serial port")
soc.close()
serial.close()
break
示例5: require
def require(message,timeout=1):
try:
print('tx:'+message)
line_received_event.clear()
serial.write(message+'\r\n')
except IOError as e:
print(e)
serial.close()
stop_event.set()
if not line_received_event.wait(timeout):
print('no response')
return None
return serial_received_line
示例6: run_graph
def run_graph(ns):
graph = GraphClass()
while(1):
time.sleep(0.1)
graph.set_angle(ns.yaw)
if ns.ping == 1:
ns.ping = 0;
graph.set_g3(ns.total,ns.yaw)
graph.set_g1(ns.raw_arr, "r")
graph.set_g1(ns.smth_arr, "g")
graph.set_g1(ns.vel_arr, "b")
serial.close()
示例7: tagRead
def tagRead():
import serial
try:
serial= serial.Serial("/dev/ttyACM0", baudrate=9600)
n=0
serial.flushInput()
serial.flushOutput()
while True:
data=serial.readline()
n=n+1
if data[0:3]=="ISO" and n>3:
myString1=data.find('[')+1
myString2=data.find(',')
serial.flush()
serial.close()
return data[myString1:myString2]
except Exception as e:
return 0
示例8: receive
def receive(count_ok,count_ng):
print("ready to receive command...")
while not stop_event.is_set():
try:
line=serial.readline()
if line:
print("rx: "+line)
if line.startswith('start'):
target_flash_start()
if line.startswith('end'):
target_flash_end()
else:
serial_received_line=line
line_received_event.set()
except IOError as e:
print(e)
serial.close()
stop_event.set()
示例9: change_vol
def change_vol(command):
if command == "vol_down":
serial.write(b"5")
serial.close()
elif command == "vol_up":
serial.write(b"4")
serial.close()
elif command == "vol_mute":
serial.write(b"3")
serial.close()
else:
syslog.syslog(syslog.LOG_ERR, "Invalid data sent to server")
示例10: raspistill
raspistill(id_string) #snap a pic for current slice
percent=100 * float(i)/float(slices)
printlog(percent,i)
pos+=deg #increase current pos + deg.
i+=1
#end of level
j+=1 #level +1
#END of SCAN
serial.flush()
serial.close() #close serial
print "Scan Completed."
print "Check for skipped images..."
if(len(SKIPPED_IMAGES)):
print "CI SONO IMMAGINI NON TRASFERITE"
for image in SKIPPED_IMAGES:
print "Resending: " + image
manage(CREATE, image)
manage(FINISH, '')
示例11: _closeSerial
def _closeSerial(self, serial):
serial.close()
示例12: change_input
def change_input(command):
if command == "in_nxt":
serial.write(b"1")
serial.close()
elif command == "in_prev":
serial.write(b"2")
serial.close()
elif command == "in_usb":
serial.write(b"a")
serial.close()
elif command == "in_opt1":
serial.write(b"d")
serial.close()
elif command == "in_opt2":
serial.write(b"e")
serial.close()
elif command == "in_coax1":
serial.write(b"b")
serial.close()
elif command == "in_coax2":
serial.write(b"c")
serial.close()
else:
syslog.syslog(syslog.LOG_ERR, "Invalid data sent to server")
示例13: change_power
def change_power(command):
if command == "pwr_event":
serial.write(b"6")
serial.close()
else:
syslog.syslog(syslog.LOG_ERR, "Invalid data sent to server")
示例14: misc_commands
def misc_commands(command):
if command == "gain_sel":
serial.write(b"f")
serial.close()
else:
syslog.syslog(syslog.LOG_ERR, "Invalid data sent to server")
示例15: GET
def GET(self):
serial.open()
serial.write("d")
serial.close()
return