本文整理汇总了Python中PyMata.pymata.PyMata.analog_mapping_query方法的典型用法代码示例。如果您正苦于以下问题:Python PyMata.analog_mapping_query方法的具体用法?Python PyMata.analog_mapping_query怎么用?Python PyMata.analog_mapping_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyMata.pymata.PyMata
的用法示例。
在下文中一共展示了PyMata.analog_mapping_query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import analog_mapping_query [as 别名]
class s2a_fm:
"""
This is the "main" function of the program.
It will instantiate PyMata for communication with an Arduino micro-controller
and the command handlers class.
It will the start the HTTP server to communicate with Scratch 2.0
@return : This is the main loop and should never return
"""
def __init__(self):
subprocess.Popen("scratch2")
# total number of pins on arduino board
self.total_pins_discovered = 0
# number of pins that are analog
self.number_of_analog_pins_discovered = 0
# COM-Port
self.com_port = "COM1"
#firmata
#self.firmata ="-
# make sure we have a log directory and if not, create it.
if not os.path.exists('log'):
os.makedirs('log')
# turn on logging
logging.basicConfig(filename='./log/s2a_fm_debugging.log', filemode='w', level=logging.DEBUG)
logging.info('s2a_fm version 1.5 Copyright(C) 2013-14 Alan Yorinks All Rights Reserved ')
print 's2a_fm version 1.5 Copyright(C) 2013-14 Alan Yorinks All Rights Reserved '
# get the com_port from the command line or default if none given
# if user specified the com port on the command line, use that when invoking PyMata,
# else use '/dev/ttyACM0'
def search_port(self):
#returns all serial COM-Ports
possible_ports = serial_ports()
print
for com_port in possible_ports:
logging.info('com port = %s' % com_port)
try:
# instantiate PyMata
self.firmata = PyMata(com_port) # pragma: no cover
self.com_port = com_port
return 1
except Exception:
print('Could not instantiate PyMata - is your Arduino plugged in?')
logging.exception('Could not instantiate PyMata on Port %s' % com_port)
return 0
#TODO: Ask if User Wants to flash Arduino on this Port
def discover_arduino(self):
# determine the total number of pins and the number of analog pins for the Arduino
# get the arduino analog pin map
# it will contain an entry for all the pins with non-analog set to self.firmata.IGNORE
self.firmata.analog_mapping_query()
self.capability_map = self.firmata.get_analog_mapping_request_results()
self.firmata.capability_query()
print("Please wait for Total Arduino Pin Discovery to complete. This can take up to 30 additional seconds.")
# count the pins
for pin in self.capability_map:
self.total_pins_discovered += 1
# non analog pins will be marked as IGNORE
if pin != self.firmata.IGNORE:
self.number_of_analog_pins_discovered += 1
# log the number of pins found
logging.info('%d Total Pins and %d Analog Pins Found' % (self.total_pins_discovered, self.number_of_analog_pins_discovered))
# instantiate the command handler
self.scratch_command_handler = ScratchCommandHandlers(self.firmata, self.com_port, self.total_pins_discovered,
self.number_of_analog_pins_discovered)
# wait for a maximum of 30 seconds to retrieve the Arduino capability query
start_time = time.time()
pin_capability = self.firmata.get_capability_query_results()
while not pin_capability:
if time.time() - start_time > 30:
print "Could not determine pin capability - exiting."
self.firmata.close()
# keep sending out a capability query until there is a response
pin_capability = self.firmata.get_capability_query_results()
time.sleep(.1)
# we've got the capability, now build a dictionary with pin as the key and a list of all the capabilities
# for the pin as the key's value
pin_list = []
total_pins_discovered = 0
for entry in pin_capability:
# bump up pin counter each time IGNORE is found
if entry == self.firmata.IGNORE:
self.scratch_command_handler.pin_map[total_pins_discovered] = pin_list
total_pins_discovered += 1
pin_list = []
else:
#.........这里部分代码省略.........
示例2: s2a_fm
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import analog_mapping_query [as 别名]
def s2a_fm():
"""
This is the "main" function of the program.
It will instantiate PyMata for communication with an Arduino micro-controller
and the command handlers class.
It will the start the HTTP server to communicate with Scratch 2.0
@return : This is the main loop and should never return
"""
# total number of pins on arduino board
total_pins_discovered = 0
# number of pins that are analog
number_of_analog_pins_discovered = 0
# make sure we have a log directory and if not, create it.
if not os.path.exists('log'):
os.makedirs('log')
# turn on logging
logging.basicConfig(filename='./log/s2a_fm_debugging.log', filemode='w', level=logging.DEBUG)
logging.info('s2a_fm version 1.5 Copyright(C) 2013-14 Alan Yorinks All Rights Reserved ')
print 's2a_fm version 1.5 Copyright(C) 2013-14 Alan Yorinks All Rights Reserved '
# get the com_port from the command line or default if none given
# if user specified the com port on the command line, use that when invoking PyMata,
# else use '/dev/ttyACM0'
if len(sys.argv) == 2:
com_port = str(sys.argv[1])
else:
com_port = '/dev/ttyACM0'
logging.info('com port = %s' % com_port)
try:
# instantiate PyMata
firmata = PyMata(com_port) # pragma: no cover
except Exception:
print 'Could not instantiate PyMata - is your Arduino plugged in?'
logging.exception('Could not instantiate PyMata - is your Arduino plugged in?')
logging.debug("Exiting s2a_fm")
return
# determine the total number of pins and the number of analog pins for the Arduino
# get the arduino analog pin map
# it will contain an entry for all the pins with non-analog set to firmata.IGNORE
firmata.analog_mapping_query()
capability_map = firmata.get_analog_mapping_request_results()
firmata.capability_query()
print "Please wait for Total Arduino Pin Discovery to complete. This can take up to 30 additional seconds."
# count the pins
for pin in capability_map:
total_pins_discovered += 1
# non analog pins will be marked as IGNORE
if pin != firmata.IGNORE:
number_of_analog_pins_discovered += 1
# log the number of pins found
logging.info('%d Total Pins and %d Analog Pins Found' % (total_pins_discovered, number_of_analog_pins_discovered))
# instantiate the command handler
scratch_command_handler = ScratchCommandHandlers(firmata, com_port, total_pins_discovered,
number_of_analog_pins_discovered)
# wait for a maximum of 30 seconds to retrieve the Arduino capability query
start_time = time.time()
pin_capability = firmata.get_capability_query_results()
while not pin_capability:
if time.time() - start_time > 30:
print ''
print "Could not determine pin capability - exiting."
firmata.close()
# keep sending out a capability query until there is a response
pin_capability = firmata.get_capability_query_results()
time.sleep(.1)
# we've got the capability, now build a dictionary with pin as the key and a list of all the capabilities
# for the pin as the key's value
pin_list = []
total_pins_discovered = 0
for entry in pin_capability:
# bump up pin counter each time IGNORE is found
if entry == firmata.IGNORE:
scratch_command_handler.pin_map[total_pins_discovered] = pin_list
total_pins_discovered += 1
pin_list = []
else:
pin_list.append(entry)
print "Arduino Total Pin Discovery completed in %d seconds" % (int(time.time() - start_time))
try:
# start the server passing it the handle to PyMata and the command handler.
scratch_http_server.start_server(firmata, scratch_command_handler)
except Exception:
logging.debug('Exception in s2a_fm.py %s' % str(Exception))
firmata.close()
#.........这里部分代码省略.........
示例3: s2a_fm
# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import analog_mapping_query [as 别名]
def s2a_fm():
"""
This is the "main" function of the program.
It will instantiate PyMata for communication with an Arduino micro-controller
and the command handlers class.
It will the start the HTTP server to communicate with Scratch 2.0
@return : This is the main loop and should never return
"""
# total number of pins on arduino board
total_pins_discovered = 0
# number of pins that are analog
number_of_analog_pins_discovered = 0
# make sure we have a log directory and if not, create it.
if not os.path.exists('log'):
os.makedirs('log')
# turn on logging
logging.basicConfig(filename='./log/s2a_fm_debugging.log', filemode='w', level=logging.DEBUG)
logging.info('s2a_fm version 1.0 Copyright(C) 2013 Alan Yorinks All Rights Reserved ')
print 's2a_fm version 1.0 Copyright(C) 2013 Alan Yorinks All Rights Reserved '
# get the com_port from the command line or default if none given
# if user specified the com port on the command line, use that when invoking PyMata,
# else use '/dev/ttyACM0'
if len(sys.argv) == 2:
com_port= str(sys.argv[1])
else:
com_port = '/dev/ttyACM0'
logging.info('com port = %s' % com_port)
try:
# instantiate PyMata
firmata = PyMata(com_port) # pragma: no cover
except:
Exception
print 'Could not instantiate PyMata - is your Arduino plugged in?'
logging.exception('Could not instantiate PyMata - is your Arduino plugged in?')
logging.debug("Exiting s2a_fm")
return
# determine the total number of pins and the number of analog pins for the Arduino
# get the arduino analog pin map
# it will contain an entry for all the pins with non-analog set to firmata.IGNORE
firmata.analog_mapping_query()
capability_map = firmata.get_analog_mapping_request_results()
# count the pins
for pin in capability_map:
total_pins_discovered += 1
# non analog pins will be marked as IGNORE
if pin != firmata.IGNORE:
number_of_analog_pins_discovered += 1
# log the number of pins found
logging.info('%d Total Pins and %d Analog Pins Found' % (total_pins_discovered,
number_of_analog_pins_discovered))
# instantiate the command handler
scratch_command_handler = ScratchCommandHandlers(firmata, com_port, total_pins_discovered,
number_of_analog_pins_discovered)
try:
# start the server passing it the handle to PyMata and the command handler.
scratch_http_server.start_server(firmata, scratch_command_handler)
except Exception:
logging.debug('Exception in s2a_fm.py %s' % str(Exception))
firmata.close()
return
except KeyboardInterrupt:
# give control back to the shell that started us
logging.info('s2a_fm.py: keyboard interrupt exception')
firmata.close()
return