python serial.write_Python serial.write方法代码示例

本文整理汇总了Python中serial.write方法的典型用法代码示例。如果您正苦于以下问题:Python serial.write方法的具体用法?Python serial.write怎么用?Python serial.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块serial的用法示例。

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

示例1: __checkType__

​点赞 5

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def __checkType__(self, serial):

byte = serial.read().decode("utf-8")

print(byte)

if byte == "1":

print("??? ???? ?? : " + serial.port)

serial.write(b'0')

self.threads["Sensor"] = SensorThread(serial)

return self.threads["Sensor"]

elif byte == "2" :

print("??? ???? ?? : " + serial.port)

serial.write(b'0')

self.threads["Control"] = ControlThread(serial)

return self.threads["Control"]

else :

print("? ? ?? ???? : " + serial.port)

serial.write(b'1')

return None

#?? ???

开发者ID:toy0605,项目名称:Hydroponics,代码行数:21,

示例2: write

​点赞 4

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def write(self, data):

"""\

Output the given byte string over the serial port. Can block if the

connection is blocked. May raise SerialException if the connection is

closed.

"""

if not self.is_open:

raise portNotOpenError

with self._write_lock:

try:

self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))

except socket.error as e:

raise SerialException("connection failed (socket error): %s" % (e,))

return len(data)

开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:16,

示例3: write

​点赞 3

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def write(self, value):

print(value)

if(value == 0):

serial.write('0')

elif(value == 1):

serial.write('1')

elif(value == 2):

serial.write('2')

elif(value == 3):

serial.write('3')

elif(value == 4):

serial.write('4')

# Disconnects the Arduino

开发者ID:ThermoNuclearPanda,项目名称:Project_Automail,代码行数:16,

示例4: showReady

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def showReady(self):

serial.write('6')

开发者ID:ThermoNuclearPanda,项目名称:Project_Automail,代码行数:4,

示例5: _internal_raw_write

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def _internal_raw_write(self, data):

"""internal socket write with no data escaping. used to send telnet stuff."""

with self._write_lock:

self._socket.sendall(data)

开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:6,

示例6: telnetSendOption

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def telnetSendOption(self, action, option):

"""Send DO, DONT, WILL, WONT."""

self.connection.write(to_bytes([IAC, action, option]))

开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:5,

示例7: rfc2217SendSubnegotiation

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def rfc2217SendSubnegotiation(self, option, value=b''):

"""Subnegotiation of RFC 2217 parameters."""

value = value.replace(IAC, IAC_DOUBLED)

self.connection.write(to_bytes([IAC, SB, COM_PORT_OPTION, option] + list(value) + [IAC, SE]))

# - check modem lines, needs to be called periodically from user to

# establish polling

开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:9,

示例8: write

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def write(self, data):

"""\

Output the given byte string over the serial port. Can block if the

connection is blocked. May raise SerialException if the connection is

closed.

"""

if not self.is_open:

raise portNotOpenError

with self._write_lock:

try:

self._socket.sendall(to_bytes(data).replace(IAC, IAC_DOUBLED))

except socket.error as e:

raise SerialException("connection failed (socket error): {}".format(e))

return len(data)

开发者ID:arpruss,项目名称:gcodeplot,代码行数:16,

示例9: telnet_send_option

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def telnet_send_option(self, action, option):

"""Send DO, DONT, WILL, WONT."""

self.connection.write(to_bytes([IAC, action, option]))

开发者ID:arpruss,项目名称:gcodeplot,代码行数:5,

示例10: rfc2217_send_subnegotiation

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def rfc2217_send_subnegotiation(self, option, value=b''):

"""Subnegotiation of RFC 2217 parameters."""

value = value.replace(IAC, IAC_DOUBLED)

self.connection.write(to_bytes([IAC, SB, COM_PORT_OPTION, option] + list(value) + [IAC, SE]))

# - check modem lines, needs to be called periodically from user to

# establish polling

开发者ID:arpruss,项目名称:gcodeplot,代码行数:9,

示例11: telnet_send_option

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def telnet_send_option(self, action, option):

"""Send DO, DONT, WILL, WONT."""

self.connection.write(IAC + action + option)

开发者ID:whaleygeek,项目名称:bitio,代码行数:5,

示例12: rfc2217_send_subnegotiation

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def rfc2217_send_subnegotiation(self, option, value=b''):

"""Subnegotiation of RFC 2217 parameters."""

value = value.replace(IAC, IAC_DOUBLED)

self.connection.write(IAC + SB + COM_PORT_OPTION + option + value + IAC + SE)

# - check modem lines, needs to be called periodically from user to

# establish polling

开发者ID:whaleygeek,项目名称:bitio,代码行数:9,

示例13: filter

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def filter(self, data):

"""\

Handle a bunch of incoming bytes. This is a generator. It will yield

all characters not of interest for Telnet/RFC 2217.

The idea is that the reader thread pushes data from the socket through

this filter:

for byte in filter(socket.recv(1024)):

# do things like CR/LF conversion/whatever

# and write data to the serial port

serial.write(byte)

(socket error handling code left as exercise for the reader)

"""

for byte in iterbytes(data):

if self.mode == M_NORMAL:

# interpret as command or as data

if byte == IAC:

self.mode = M_IAC_SEEN

else:

# store data in sub option buffer or pass it to our

# consumer depending on state

if self.suboption is not None:

self.suboption += byte

else:

yield byte

elif self.mode == M_IAC_SEEN:

if byte == IAC:

# interpret as command doubled -> insert character

# itself

if self.suboption is not None:

self.suboption += byte

else:

yield byte

self.mode = M_NORMAL

elif byte == SB:

# sub option start

self.suboption = bytearray()

self.mode = M_NORMAL

elif byte == SE:

# sub option end -> process it now

self._telnetProcessSubnegotiation(bytes(self.suboption))

self.suboption = None

self.mode = M_NORMAL

elif byte in (DO, DONT, WILL, WONT):

# negotiation

self.telnet_command = byte

self.mode = M_NEGOTIATE

else:

# other telnet commands

self._telnetProcessCommand(byte)

self.mode = M_NORMAL

elif self.mode == M_NEGOTIATE: # DO, DONT, WILL, WONT was received, option now following

self._telnetNegotiateOption(self.telnet_command, byte)

self.mode = M_NORMAL

# - incoming telnet commands and options

开发者ID:sketchpunk,项目名称:android3dblendermouse,代码行数:60,

示例14: filter

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def filter(self, data):

"""\

Handle a bunch of incoming bytes. This is a generator. It will yield

all characters not of interest for Telnet/RFC 2217.

The idea is that the reader thread pushes data from the socket through

this filter:

for byte in filter(socket.recv(1024)):

# do things like CR/LF conversion/whatever

# and write data to the serial port

serial.write(byte)

(socket error handling code left as exercise for the reader)

"""

for byte in iterbytes(data):

if self.mode == M_NORMAL:

# interpret as command or as data

if byte == IAC:

self.mode = M_IAC_SEEN

else:

# store data in sub option buffer or pass it to our

# consumer depending on state

if self.suboption is not None:

self.suboption += byte

else:

yield byte

elif self.mode == M_IAC_SEEN:

if byte == IAC:

# interpret as command doubled -> insert character

# itself

if self.suboption is not None:

self.suboption += byte

else:

yield byte

self.mode = M_NORMAL

elif byte == SB:

# sub option start

self.suboption = bytearray()

self.mode = M_NORMAL

elif byte == SE:

# sub option end -> process it now

self._telnet_process_subnegotiation(bytes(self.suboption))

self.suboption = None

self.mode = M_NORMAL

elif byte in (DO, DONT, WILL, WONT):

# negotiation

self.telnet_command = byte

self.mode = M_NEGOTIATE

else:

# other telnet commands

self._telnet_process_command(byte)

self.mode = M_NORMAL

elif self.mode == M_NEGOTIATE: # DO, DONT, WILL, WONT was received, option now following

self._telnet_negotiate_option(self.telnet_command, byte)

self.mode = M_NORMAL

# - incoming telnet commands and options

开发者ID:arpruss,项目名称:gcodeplot,代码行数:60,

示例15: run

​点赞 2

# 需要导入模块: import serial [as 别名]

# 或者: from serial import write [as 别名]

def run(self):

if self.log.fan_out == True :

jsonString = json.dumps({ "Comm" : "onFan" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

else :

jsonString = json.dumps({ "Comm" : "offFan" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

self.serial.write(b'\n')

byte = self.serial.read().decode("utf-8")

print(byte)

if byte == "0" :

print("?? ?? ??")

else :

print("?? ?? ??")

if self.log.humidifier == True :

jsonString = json.dumps({ "Comm" : "onHumidifier" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

else :

jsonString = json.dumps({ "Comm" : "offHumidifier" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

self.serial.write(b'\n')

byte = self.serial.read().decode("utf-8")

print(byte)

if byte == "0" :

print("?? ?? ??")

else :

print("?? ?? ??")

if self.log.peltier == True :

jsonString = json.dumps({ "Comm" : "onPeltier" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

else :

jsonString = json.dumps({ "Comm" : "offPeltier" })

self.serial.write(bytes(jsonString, encoding="utf-8"))

self.serial.write(b'\n')

byte = self.serial.read().decode("utf-8")

print(byte)

if byte == "0" :

print("?? ?? ??")

else :

print("?? ?? ??")

开发者ID:toy0605,项目名称:Hydroponics,代码行数:48,

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值