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

Python serial.close函数代码示例

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

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



在下文中一共展示了close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:flamingspaz,项目名称:1281-greenhouse-frontend,代码行数:7,代码来源:serializer.py


示例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()
开发者ID:Fensterbank,项目名称:FAB-UI,代码行数:33,代码来源:self_test.py


示例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)
开发者ID:brendanhoran,项目名称:ir-blower,代码行数:8,代码来源:ir-blower-server.py


示例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
开发者ID:mdsousa,项目名称:pi_video,代码行数:52,代码来源:gps_read.py


示例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
开发者ID:tangyunzhu,项目名称:Rephone_Firmware_update_Jlink,代码行数:13,代码来源:Program.py


示例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()
开发者ID:easyNav,项目名称:easyNav-gears,代码行数:14,代码来源:Mp.py


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


示例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()
开发者ID:tangyunzhu,项目名称:Rephone_Firmware_update_Jlink,代码行数:19,代码来源:Program.py


示例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")
开发者ID:brendanhoran,项目名称:ir-blower,代码行数:12,代码来源:ir-blower-server.py


示例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, '')
开发者ID:AungWinnHtut,项目名称:FAB-UI,代码行数:31,代码来源:pg_scan.py


示例11: _closeSerial

 def _closeSerial(self, serial):
     serial.close()
开发者ID:glibersat,项目名称:pomarduino,代码行数:2,代码来源:__init__.py


示例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")
开发者ID:brendanhoran,项目名称:ir-blower,代码行数:24,代码来源:ir-blower-server.py


示例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")
开发者ID:brendanhoran,项目名称:ir-blower,代码行数:6,代码来源:ir-blower-server.py


示例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")
开发者ID:brendanhoran,项目名称:ir-blower,代码行数:6,代码来源:ir-blower-server.py


示例15: GET

 def GET(self):
     serial.open()
     serial.write("d")
     serial.close()
     return
开发者ID:flamingspaz,项目名称:1281-greenhouse-frontend,代码行数:5,代码来源:serializer.py


示例16:

''' SERIAL FLUSH INPUT & OUTPUT BUFFER '''
import serial
import ConfigParser

config = ConfigParser.ConfigParser()
config.read('/var/www/lib/serial.ini')

serial_port = config.get('serial', 'port')
serial_baud = config.get('serial', 'baud')

serial = serial.Serial(serial_port, serial_baud, timeout=0.5)
serial.flushInput()
serial.flushOutput()
serial.flush()
serial.close()
开发者ID:christopherwit,项目名称:FAB-UI,代码行数:15,代码来源:flush.py


示例17: close_HMIPort

def	close_HMIPort( serial ):
	serial.close()
开发者ID:cristian69,项目名称:KernotekV3,代码行数:2,代码来源:modbus.py


示例18: set_attenuation_fix_value

def set_attenuation_fix_value(vendor_channel_info, channel_value):
    """This keyword can change attenuation value once, with different kind of PA equipment

    | Input Parameters       | Man. | Description |
    | vendor_channel_info    | Yes  | vendor, connection type, and channels |
    | channel_value          | Yes  | the attenuation value you want to set, scope is 0~127 |

    Example
    For HuaXiang PA(serial port)
    | Set Attenuation Fix Value | HX:Com2 | 3 |
    For HuaXiang PA(Eth port)
    | Set Attenuation Fix Value | HX:192.168.1.18:2 | 3 |
    For HaoJing PA(Eth port)
    | Set Attenuation Fix Value | HJ:192.168.1.18,10001:2 | 3 |
    For HaoJing PA(serial port)
    | Set Attenuation Fix Value | HJ:COM2:2 | 3 |
    For JieXi PA (socket)
    | Set Attenuation Fix Value | JX:192.168.1.18,80:2 | 3 |
    """
    if vendor_channel_info == "":
        print "*INFO* There is no attenuator on you test bed, Return!"
        return
    channel_value = int(channel_value)

    tmp = vendor_channel_info.split(':')
    vendor = tmp[0]
    conn_type = tmp[1]

    if vendor == "HX" and not re.match('^\d+.\d+.\d+.\d+$', conn_type):
        serial = _serial_open(conn_type)
        try:
            if serial:
                set_value = _set_HX_channel_command(channel_value)
                ReadBackValue = _serial_write_and_read_HX(serial, set_value, 6)
                if hex(channel_value) == ReadBackValue[3] and \
                              hex(32) == ReadBackValue[2]:
                    print "Set channel_value %d Ok" % channel_value
                else:
                    raise Exception, "set_value Fail"
        finally:
            serial.close()

    elif vendor == 'HX' and re.match('^\d+.\d+.\d+.\d+$', conn_type):
        if channel_value < 0 or channel_value > 126:
            raise Exception, "Channel value most be in 0dB to 126dB, '%d' is invalid !" % channel_value
        ip = conn_type
        channel = int(tmp[2])
        value = channel_value * 2
        num = _dec2hex(channel)
        if value == 0:
            val = '0'
        else:
            val = _dec2hex(value)
        if channel < 16 and value < 16:
            inf = ['$HX,C,','0',num,'0',val,'*']
            cmd = ''
            cmd = ''.join(inf)
        if channel < 16 and value >= 16:
            inf = ['$HX,C,''0',num,val,'*']
            cmd = ''
            cmd = ''.join(inf)
        if channel >= 16 and value < 16:
            inf = ['$HX,C,',num,'0',val,'*']
            cmd = ''
            cmd = ''.join(inf)
        if channel >= 16 and value >= 16:
            inf = ['$HX,C,',num,val,'*']
            cmd = ''
            cmd = ''.join(inf)
        crc = _CRC8(0, cmd)
        crc = crc[2:4].upper()
        if len(crc) == 1:
            crc = '0' + crc
        cmd = cmd + crc
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((ip, 4001))
            sock.send(cmd)
            print "Cmd: ", cmd
            res=sock.recv(1024)
            print ">>>" , res
        finally:
            sock.close()

    elif vendor == 'HJ':
        channel = tmp[2]
        if conn_type.startswith('COM'):
            serial = _serial_open(conn_type)
            try:
                if serial:
                    read_back_msg = _serial_write_and_read_HJ(serial, \
                                     "ATT %s %d\r\n" % (channel, channel_value))
                    print read_back_msg
            finally:
                serial.close()
        else:
            sock = _socket_open(conn_type)
            try:
                if sock:
                    read_back_msg = _socket_write_and_read_HJ(sock, \
#.........这里部分代码省略.........
开发者ID:jufei,项目名称:BtsShell,代码行数:101,代码来源:attenuation_control.py


示例19: close_uart

 def close_uart(self):
     """
     Close the uart connnection.
     """
     serial.close()
开发者ID:Matla,项目名称:RaspberryPiUart_Python,代码行数:5,代码来源:uart.py


示例20: change_attenuation_value_period

def change_attenuation_value_period(vendor_channel_info, min_value, max_value, step, delay = '1'):
    """This keyword can change attenuation value period, with different kind of PA equipment

    | Input Parameters      | Man. | Description |
    | vendor_channel_info   | Yes  | vendor, connection type, and channels |
    | min_value              | Yes  | the min value you want to set(0~127) |
    | max_value              | Yes  | the max value you want to set(0~127) |
    | step                  | Yes  | att. value change step, if step > zero |
    |                       |      | the value change from low to high, |
    |                       |      | otherwise change from high to low |
    | delay                 | No   | attenuation value change delay time, unit: s |

    Example
    For HuaXiang PA(serial port)
    | Change Attenuation Value Period | HX:Com116 | 3 | 20 | 3 | 2 |
    For HuaXiang PA(Eth port)
    | Change Attenuation Value Period | HX:192.168.1.18:2 | 3 | 20 | 3 | 2 |
    For HaoJing PA(Eth port)
    | Change Attenuation Value Period | HJ:192.168.1.18,10001:2 | 3 | 33  | 2 | 2 |
    For HaoJing PA(serial port)
    | Change Attenuation Value Period | HJ:COM1:2 | 3 | 33  | -2  | 1 |
    For JieXi PA (socket)
    | Change Attenuation Value Period | JX:192.168.0.80,10001:2 | 3 | 33  | 2 | 2 |

    """
    if vendor_channel_info == "":
        print "*INFO* There is no attenuator on you test bed, Return!"
        return
    step = int(step)
    min_value = int(min_value)
    max_value = int(max_value)
    delay = int(delay)

    if 0 == step:
        raise Exception, "The step should be non-zero, pls modify it!"

    if min_value > max_value:
        raise Exception, "Pls exchange value of min_value and max_value"

    if 0 < step:
        i = min_value
    else:
        i = max_value

    tmp = vendor_channel_info.split(':')
    vendor = tmp[0]
    conn_type = tmp[1]

    if vendor == "HX" and not re.match('^\d+.\d+.\d+.\d+$', conn_type):
        serial = _serial_open(conn_type)
        try:
            if serial:
                while(min_value <= i and  max_value >= i):
                    set_value = _set_HX_channel_command(i)
                    read_value = _serial_write_and_read_HX(serial, set_value, 6)

                    if  hex(i) == read_value[3] and hex(32) == read_value[2]:
                        print "Attenuation set value %d Ok" % i
                    else:
                        raise Exception, "Attenuation set value Failed!"
                    i += step
                    time.sleep(delay - 0.2)

        finally:
            serial.close()

    elif vendor == "HX" and re.match('^\d+.\d+.\d+.\d+$', conn_type):
        if min_value < 0 or max_value > 126:
            raise Exception, "Channel value most be in 0dB to 126dB !"
        ip = conn_type
        channel = int(tmp[2])
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((ip, 4001))
            while(min_value <= i and  max_value >= i):
                value = i * 2
                num = _dec2hex(channel)
                if value == 0:
                    val = '0'
                else:
                    val = _dec2hex(value)
                if channel < 16 and value < 16:
                    inf = ['$HX,C,','0',num,'0',val,'*']
                    cmd = ''
                    cmd = ''.join(inf)
                if channel < 16 and value >= 16:
                    inf = ['$HX,C,''0',num,val,'*']
                    cmd = ''
                    cmd = ''.join(inf)
                if channel >= 16 and value < 16:
                    inf = ['$HX,C,',num,'0',val,'*']
                    cmd = ''
                    cmd = ''.join(inf)
                if channel >= 16 and value >= 16:
                    inf = ['$HX,C,',num,val,'*']
                    cmd = ''
                    cmd = ''.join(inf)
                crc = _CRC8(0, cmd)
                crc = crc[2:4].upper()
                if len(crc) == 1:
#.........这里部分代码省略.........
开发者ID:jufei,项目名称:BtsShell,代码行数:101,代码来源:attenuation_control.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python serial.flush函数代码示例发布时间:2022-05-27
下一篇:
Python model.RuleSet类代码示例发布时间: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