• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python serial.flushInput函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中serial.flushInput函数的典型用法代码示例。如果您正苦于以下问题:Python flushInput函数的具体用法?Python flushInput怎么用?Python flushInput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了flushInput函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: probe

def probe(x,y):
	global points_on_plane
	serial_reply=""
	serial.flushInput()		   #clean buffer
	probe_point= "G30\r\n" #probing comand
	serial.write(probe_point)
	time.sleep(0.5) #give it some to to start  
	probe_start_time = time.time()
	while not serial_reply[:22]=="echo:endstops hit:  Z:":
	
		#issue G30 Xnn Ynn and waits reply.
		#Expected reply
		#endstops hit:  Z: 0.0000	
		#couldn't probe point: = 
		if (time.time() - probe_start_time>10):
			#10 seconds passed, no contact
			trace_msg="Could not probe "+str(x)+ "," +str(y) + " / " + str(deg) + " degrees"			
			trace(trace_msg)
			#change safe-Z
			return False #leave the function,keep probing
		
		serial_reply=serial.readline().rstrip()
		#add safety timeout, exception management
		time.sleep(0.1) #wait
		pass
		
	#get the z position
	#print serial_reply
	z=float(serial_reply.split("Z:")[1].strip())
	
	new_point = [x,y,z,1]
	points_on_plane = np.vstack([points_on_plane, new_point]) #append new point to the cloud.
	
	trace("Probed "+str(x)+ "," +str(y) + " / " + str(deg) + " degrees = " + str(z))
	return True
开发者ID:HrRossi,项目名称:FAB-UI,代码行数:35,代码来源:p_scan.py


示例2: probe

def probe(x,y):
	global points_on_plane
	serial_reply=""

	serial.flushInput()
	serial.write("G30\r\n")
	
	probe_start_time = time.time()
	while not serial_reply[:22]=="echo:endstops hit:  Z:":
		serial_reply=serial.readline().rstrip()	
		#issue G30 Xnn Ynn and waits reply.
		if (time.time() - probe_start_time>90):  
			#timeout management
			trace("Could not probe this point")
			return False
			break	
		pass
		
	#get the z position
	z=float(serial_reply.split("Z:")[1].strip())
	
	new_point = [x,y,z,1]
	points_on_plane = np.vstack([points_on_plane, new_point]) #append new point to the cloud.
	
	trace("Probed "+str(x)+ "," +str(y) + " / " + str(deg) + " degrees = " + str(z))
	return True
开发者ID:AungWinnHtut,项目名称:FAB-UI,代码行数:26,代码来源:p_scan.py


示例3: macro

def macro(code,expected_reply,timeout,error_msg,delay_after,warning=False,verbose=True):
	global s_error
	global s_warning
	global s_skipped
	serial.flushInput()
	if s_error==0:
		serial_reply=""
		macro_start_time = time.time()
		serial.write(code+"\r\n")
		if verbose:
			trace(error_msg)
		time.sleep(0.3) #give it some tome to start
		while not (serial_reply==expected_reply or serial_reply[:4]==expected_reply):
			#Expected reply
			#no reply:
			if (time.time()>=macro_start_time+timeout+5):
				if serial_reply=="":
					serial_reply="<nothing>"
				if not warning:
					s_error+=1
					trace(error_msg + ": Failed (" +serial_reply +")")
				else:
					s_warning+=1
					trace(error_msg + ": Warning! ")
				return False #leave the function
			serial_reply=serial.readline().rstrip()
			#add safety timeout
			time.sleep(0.2) #no hammering
			pass
		time.sleep(delay_after) #wait the desired amount
	else:
		trace(error_msg + ": Skipped")
		s_skipped+=1
		return False
	return serial_reply
开发者ID:AungWinnHtut,项目名称:colibri-fabui,代码行数:35,代码来源:manual_bed_lev.py


示例4: safety_callback

def safety_callback(channel):
    
    try:
        code=""
        type=""
        
        if(GPIO.input(2) == GPIO.LOW):
            #todo
            type="emergency"
            serial.flushInput()
            serial.write("M730\r\n")
            reply=serial.readline()
            
            try:
                code=float(reply.split("ERROR : ")[1].rstrip())
            except:
                code=100
            
        
        if(GPIO.input(2) == GPIO.HIGH):
            #to do
            type=""
            code=""
                
        message = {'type': str(type), 'code': str(code)}
        ws.send(json.dumps(message))
        write_emergency(json.dumps(message))
        
    except Exception, e:
        logging.info(str(e))
开发者ID:cecilden,项目名称:FAB-UI,代码行数:30,代码来源:monitor.py


示例5: modem_terminal

def modem_terminal(serial,string,timeout):
	serial.flushInput()
	serial.write(string)
	while timeout>0:
		if serial.inWaiting()>0:
			sys.stdout.write(serial.read(serial.inWaiting()))
		time.sleep(0.001)
		timeout=timeout-1
	print ""
开发者ID:Tambralinga,项目名称:playground,代码行数:9,代码来源:terra.py


示例6: read_serial

def read_serial(gcode):
	serial.flushInput()
	serial.write(gcode + "\r\n")

	response=""
	while (response==""):
		response=serial.readline().rstrip
		if response!="":
			return response
开发者ID:tjankovic,项目名称:FAB-UI,代码行数:9,代码来源:manual_bed_lev.py


示例7: read_serial

def read_serial(gcode):
	serial.flushInput()
	serial.write(gcode + "\r\n")
	time.sleep(0.1)
	
	#return serial.readline().rstrip()
	response=serial.readline().rstrip()
	
	if response=="":
		return "NONE"
	else:
		return response
开发者ID:AungWinnHtut,项目名称:colibri-fabui,代码行数:12,代码来源:manual_bed_lev.py


示例8: jogToBedCorner

def jogToBedCorner(corner, height, feedrate):
	serial.flushInput()
	macro("M402","ok",2,"Retracting Probe (safety)",1, verbose=False)
	corner = corner.upper()
	if (corner=="LU"):
		macro("G0 X"+str(minXPhys)+" Y"+str(minYPhys)+" Z "+str(height)+" F"+str(feedrate),"ok",2,"Moving to left down corner point",0.1)
	if (corner=="LO"):
		macro("G0 X"+str(minXPhys)+" Y"+str(maxYPhys)+" Z "+str(height)+" F"+str(feedrate),"ok",2,"Moving to left upper corner point",0.1)
	if (corner=="RU"):
		macro("G0 X"+str(maxXPhys)+" Y"+str(minYPhys)+" Z "+str(height)+" F"+str(feedrate),"ok",2,"Moving to right lower corner point",0.1)
	if (corner=="RO"):
		macro("G0 X"+str(maxXPhys)+" Y"+str(maxYPhys)+" Z "+str(height)+" F"+str(feedrate),"ok",2,"Moving to right upper corner point",0.1)
开发者ID:FAB-UI-plugins,项目名称:advancedbedcalibration,代码行数:12,代码来源:jogTo.py


示例9: recv

	def recv(self,serial):
		buffer = ''
		aux = ''
		while len(str(aux.encode('hex'))) == 0:
			aux = serial.read()
		while len(str(aux.encode('hex'))) > 0:
			buffer += aux
			aux = serial.read()
		serial.flushInput()
		print "    ENCODED: %s" % buffer
		buffer = b64decode ( buffer )
		print "    ENCRYPTED: %s" % buffer.encode('hex')
		return buffer
开发者ID:sch3m4,项目名称:SerialCrypt,代码行数:13,代码来源:SerialCrypt.py


示例10: recieve_message

	def recieve_message(self):
		readMsg = ''
		serial.flushInput()
		time.sleep(4)
		orig_time = time.time()
		while((time.time()-orig_time) < 5 ):
			readMsg = serial.read(serial.inWaiting())
			#print("test")
			time.sleep(1)
			if readMsg != '':
				break
			else:
				raise("problem in recieving message")
		self.logger("Recieving package %s" % readMsg)
		return readMsg
开发者ID:Aycn0,项目名称:CMPE195_Code,代码行数:15,代码来源:mainhub.py


示例11: read_hex_from_ee

def read_hex_from_ee(address):
	serial.flushOutput()
	serial.flushInput()
	msg = '\x02'
	msg += dec2hex(address)
	if serial.isOpen():
		serial.write(msg)
	else:
		print 'Error, the serial port is not open.'
		return
	value = serial.readline()
	if value == '':
		print 'Error, did not receive response from the Micro Controller.'
		return None
	value = value.strip()
	return value
开发者ID:AuburnSPaRC,项目名称:southeastcon-2009,代码行数:16,代码来源:EEPROM.py


示例12: 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
开发者ID:rener2,项目名称:BuildIT,代码行数:18,代码来源:Simple_reader.py


示例13: probe

def probe(x,y):
    serial_reply=""
    serial.flushInput()
    serial.write("G30\r\n")
    probe_start_time = time.time()
    while not serial_reply[:22]=="echo:endstops hit:  Z:":
        serial_reply=serial.readline().rstrip()    
        #issue G30 Xnn Ynn and waits reply.
        if (time.time() - probe_start_time>90):  
            #timeout management
            trace("Could not probe this point")
            return False
            break    
        pass
    #get the z position
    z=float(serial_reply.split("Z:")[1].strip())
    
    new_point = [x,y,z,1]
    
    trace("Probed "+str(x)+ "," +str(y))
    return True
开发者ID:tjankovic,项目名称:FAB-UI,代码行数:21,代码来源:test_bed_area.py


示例14: measurePointHeight

def measurePointHeight(x, y, initialHeight, feedrate):
	macro("M402","ok",2,"Retracting Probe (safety)",1, verbose=False)
	macro("G0 Z60 F5000","ok",5,"Moving to start Z height",10) #mandatory!
	
	
	macro("G0 X"+str(x)+" Y"+str(y)+" Z "+str(initialHeight)+" F10000","ok",2,"Moving to left down corner point",10)
	macro("M401","ok",2,"Lowering Probe",1, warning=True, verbose=False)
	serial.flushInput()
	serial_reply = ""
	probe_start_time=time.time()
	serial.write("G30 U"+str(feedrate)+"\r\n")
	
	while not serial_reply[:22]=="echo:endstops hit:  Z:":
		serial_reply=serial.readline().rstrip()
	if (time.time() - probe_start_time>80): #timeout management
		z = initialHeight 
		serial.flushInput()
		return z
	pass
	if serial_reply!="":
		z=serial_reply.split("Z:")[1].strip()
	serial_reply=""
	serial.flushInput()
	macro("G0 X"+str(x)+" Y"+str(y)+" Z "+str(initialHeight)+" F10000","ok",2,"Moving to left down corner point",10)
	macro("M402","ok",2,"Raising Probe",1, warning=True, verbose=False)	
	return z
开发者ID:FAB-UI-plugins,项目名称:advancedbedcalibration,代码行数:26,代码来源:manualCalibration.py


示例15: writeToTape

def writeToTape(serial, array, maxvalue):
    print("Writing")
    print(array)
    data = ""
    if array[0] > 1e1:
        for x in array:
            towrite = [0, 0, 0]               #rgb
            towrite[0] = x
            towrite[1] = 60
            towrite[2] = 254 - x
                
            for x in towrite:
                capped = int(min(254,max(0,x)))
                data += chr(capped)
    else:
#        cleartape(serial)
        return

    # write control
    serial.write(data)
    serial.write(CONTROL)
    serial.flushInput()
    serial.flush()
开发者ID:Narfinger,项目名称:blinkysound,代码行数:23,代码来源:visual.py


示例16: trace

	trace("Probed "+str(x)+ "," +str(y) + " / " + str(deg) + " degrees = " + str(z))
	return True

printlog(0,0) #create log vuoto

trace("\n ---------- Initializing ---------- \n")

'''#### SERIAL PORT COMMUNICATION ####'''
serial_port = config.get('serial', 'port')
serial_baud = config.get('serial', 'baud')
serial = serial.Serial(serial_port, serial_baud, timeout=0.5)

#initialize serial
#serial = serial.Serial(port, baud, timeout=0.6)
time.sleep(0.5) 						#sleep a while
serial.flushInput()						#clean buffer
	
trace('PROBE MODULE STARTING')
print 'scanning from' + str(x)+ "," +str(y)+ " to " +str(x1)+ "," +str(y1); 
print 'Total points    : ', tot_probes	
print 'Probing density : ', probe_density , " points/mm"
print 'Num of planes   : ', slices
print 'Start/End       : ', begin ,' to ', end, 'deg'

#ESTIMATED SCAN TIME ESTIMATION
estimated=(slices*tot_probes*3)/60
if(estimated<1):
    estimated*=60
    unit= "Seconds"
else:
    unit= "Minutes"
开发者ID:AungWinnHtut,项目名称:FAB-UI,代码行数:31,代码来源:p_scan.py


示例17:

##
import sys
import serial


try:
    code_to_execute=str(sys.argv[1])
except:
    print "Warning - parameter <CODE> is required"
    sys.exit()

if code_to_execute != "" :
    port = '/dev/ttyAMA0'
    baud = 115200
    serial = serial.Serial(port, baud, timeout=0)
    serial.flushInput()
    serial.flushInput()
    serial.write(code_to_execute)
    data=serial.read(8)
    print data
    
开发者ID:Fensterbank,项目名称:FAB-UI,代码行数:20,代码来源:mdi.py


示例18: open

}
print "Reading file..."
f = open("helpers.txt", "r+")
for line in f:
    line = line.replace("\n", "")
    data = line.split(", ")
    helpers.append([data[0], data[1]])
f.close()
print "Done. Ready to scan."
while True:
    if serial.inWaiting() > 0:
        read_result = serial.read(12)
        rfid = format(read_result.decode(encoding="utf-8"))
        if len(rfid) == 12:
            rfid = rfid[1:11]
            print("Read card " + rfid)
            for student in helpers:
                if(rfid == student[0]):
                    print "You are " + student[1]
                    send_data["id"] = student[1]
                    send["data"] = json.dumps(send_data)
                    print requests.post(url, data=send).text
        else:
            print("Misread card")
        print("Please wait for 1 second...");
        time.sleep(1)
        serial.flushInput() # ignore errors, no data
    else:
        time.sleep(0.1)

开发者ID:pennmanor,项目名称:ClientSignin,代码行数:29,代码来源:signin.py


示例19: rfidFlush

def rfidFlush(serial):
	serial.read(serial.inWaiting())
	serial.flushInput()
开发者ID:andrewjpiro,项目名称:Logmaster,代码行数:3,代码来源:RFID.py



注:本文中的serial.flushInput函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python serial.read函数代码示例发布时间:2022-05-27
下一篇:
Python serial.flush函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap