Changes between Version 7 and Version 8 of UsingSensors

Changes between Version 7 and Version 8 of UsingSensors

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 7 and Version 8 of UsingSensors

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 7 and Version 8 of UsingSensors

Show
Ignore:
Timestamp:
07/27/12 14:28:32 (7 years ago)
Author:
albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingSensors

    v7 v8  
    1515'''Note: it is completely fine for a sensor to hide calls it does not want to be called by general clients.'''   In other words, if you have a call that performs a potentially disruptive act, you need not list it.   Keep in mind that this is not a security mechanism.   It is just to prevent a simple and general client from calling it without understanding what it does. 
    1616 
    17 It is also *recommended* that you provide the call {{{system.methodHelp}}}.   This is not required and clients *must not* rely on their existence. 
     17It is also '''recommended''' that you provide the call {{{system.methodHelp}}}.   This is not required and clients '''must not''' rely on their existence. 
    1818 
    1919== Example Use == 
     
    5858    return "Hello World!" 
    5959  elif language == 'German': 
    60     return "Hallo Weld!" 
     60    return "Hallo Welt!" 
    6161  elif language == 'Mandarin': 
    6262    return "Ni Hao!" 
     
    6464    raise Exception("Unsupported language") 
    6565 
    66 # NOTE: the system.* calls are defined by the !SimpleXMLRPCServer in Python by calling the following.   Your library's use may vary. 
     66# NOTE: the system.* calls are defined by the SimpleXMLRPCServer in Python by calling the following.   Your library's use may vary. 
    6767server.register_introspection_functions() 
    6868 
     
    8383Repy sensor reading code: 
    8484{{{ 
    85 import xmlrpclib 
    86 import sys 
     85include xmlrpc_client.repy 
    8786 
    88 for sensorport in [63095, 63096, 63097, 63098, 63099, 63090, 63091, 63092, 63093, 63094]: 
    89   try: 
    90     s = xmlrpclib.ServerProxy('http://localhost:'+str(sensorport)) 
    91   except socket.error: 
    92     print 'port:',sensorport,'failed.   Trying backup port...'  
    93     continue 
    94   print "Connected to port",sensorport 
    95   break 
    96 else: 
    97   print 'Could not locate a port!' 
    98   sys.exit(1) 
     87if callfunc=="initialize": 
     88  for sensorport in [63095, 63096, 63097, 63098, 63099, 63090,  
     89    63091, 63092, 63093, 63094]: 
     90    try: 
     91      s = xmlrpc_client_Client('http://localhost:'+str(sensorport)) 
     92    except socket.error: 
     93      print 'port:', sensorport, 'failed.   Trying backup port...'  
     94      continue 
     95    print "Connected to port", sensorport 
     96    break 
     97  else: 
     98    print 'Could not locate a port!' 
     99    exitall() 
    99100 
    100 # should check the error status... 
    101 try:  
    102   if not s.isSeattleSensor(): 
    103     print 'something other than a Seattle sensor was bound to the port...' 
    104     sys.exit(1) 
    105 except: 
    106     print 'Got an error when checking if this is a Seattle sensor...' 
    107     sys.exit(1) 
    108    
    109 # Get the list of available methods 
    110 methodlist = s.system.listMethods() 
     101  # should check the error status... 
     102  try:  
     103    if not s.send_request("isSeattleSensor", ()): 
     104      print 'something other than a Seattle sensor was bound to the port...' 
     105      exitall() 
     106  except Exception, e: 
     107    print 'Got an error when checking if this is a Seattle sensor:', str(e) 
     108    exitall() 
    111109 
    112 for methodname in methodlist: 
    113   thissignature = s.system.methodSignature(methodname) 
    114   if thissignature == 'signatures not supported': 
    115     print 'Method:',methodname,'has an unknown signature.' 
    116   else:   
    117     print 'Method:',methodname,'has the signature', thissignature 
     110  # Get the list of available methods 
     111  methodlist = s.send_request("system.listMethods", ()) 
    118112 
    119   if thissignature == (): 
    120     print 'Empty call returns:',safe_eval("s."+methodname+"()") 
     113  for methodname in methodlist: 
     114    # NOTE: Wrap the methodname string inside a tuple, otherwise 
     115    # xmlrpc_common will treat the string's characters as separate params 
     116    thissignature = s.send_request("system.methodSignature", (methodname,)) 
    121117 
    122 print s.isSeattleSensor() 
    123 print s.mySensorName() 
    124 print s.readSensor() 
    125 print s.readSensorForLanguage('English') 
     118    # BUG: This is true for all signatures, but shouldn't be. 
     119    if thissignature == 'signatures not supported': 
     120      print 'Method:', methodname, 'has an unknown signature.' 
     121    else:   
     122      print 'Method:',methodname,'has the signature', thissignature 
     123 
     124    if thissignature == (): 
     125      print 'Empty call returns:', s.send_request(methodname, ()) 
     126 
     127  print s.send_request("isSeattleSensor", ()) 
     128  print s.send_request("mySensorName", ()) 
     129  print s.send_request("readSensor", ()) 
     130  print s.send_request("readSensorForLanguage", ('Mandarin',)) 
    126131 
    127132}}}