Exemplo n.º 1
0
 def __init__(self,nodeName='b0RemoteApi_pythonClient',channelName='b0RemoteApi',inactivityToleranceInSec=60,setupSubscribersAsynchronously=False):
     self._channelName=channelName
     self._serviceCallTopic=channelName+'SerX'
     self._defaultPublisherTopic=channelName+'SubX'
     self._defaultSubscriberTopic=channelName+'PubX'
     self._nextDefaultSubscriberHandle=2
     self._nextDedicatedPublisherHandle=500
     self._nextDedicatedSubscriberHandle=1000
     b0.init()
     self._node=b0.Node(nodeName)
     self._clientId=''.join(random.choice(string.ascii_uppercase+string.ascii_lowercase+string.digits) for _ in range(10))
     self._serviceClient=b0.ServiceClient(self._node,self._serviceCallTopic)
     self._serviceClient.set_option(3,1000) #read timeout of 1000ms
     self._defaultPublisher=b0.Publisher(self._node,self._defaultPublisherTopic)
     self._defaultSubscriber=b0.Subscriber(self._node,self._defaultSubscriberTopic,None) # we will poll the socket
     print('\n  Running B0 Remote API client with channel name ['+channelName+']')
     print('  make sure that: 1) the B0 resolver is running')
     print('                  2) V-REP is running the B0 Remote API server with the same channel name')
     print('  Initializing...\n')
     self._node.init()
     self._handleFunction('inactivityTolerance',[inactivityToleranceInSec],self._serviceCallTopic)
     print('\n  Connected!\n')
     self._allSubscribers={}
     self._allDedicatedPublishers={}
     self._setupSubscribersAsynchronously=setupSubscribersAsynchronously
Exemplo n.º 2
0
    def __init__(self,
                 nodeName=None,
                 channelName=None,
                 inactivityToleranceInSec=60,
                 setupSubscribersAsynchronously=False,
                 timeout=3):

        if nodeName == None:
            nodeName = 'b0RemoteApi_pythonClient' + str(threading.get_ident())
        if channelName == None:
            channelName = 'b0RemoteApiAddOn'

        self._channelName = channelName
        self._serviceCallTopic = channelName + 'SerX'
        self._defaultPublisherTopic = channelName + 'SubX'
        self._defaultSubscriberTopic = channelName + 'PubX'
        self._nextDefaultSubscriberHandle = 2
        self._nextDedicatedPublisherHandle = 500
        # print(f'(nodeName:{{{nodeName}}} channelName:{{{channelName}}})')
        self._nextDedicatedSubscriberHandle = 1000
        # print('Calling b0.init()')
        b0.init()
        # print('Calling b0.Node(nodeName)')
        self._node = b0.Node(nodeName)
        self._clientId = ''.join(
            random.choice(string.ascii_uppercase + string.ascii_lowercase +
                          string.digits) for _ in range(10))
        self._serviceClient = b0.ServiceClient(self._node,
                                               self._serviceCallTopic)
        self._serviceClient.set_option(3, timeout * 1000)  #read timeout
        self._defaultPublisher = b0.Publisher(self._node,
                                              self._defaultPublisherTopic)
        self._defaultSubscriber = b0.Subscriber(
            self._node, self._defaultSubscriberTopic,
            None)  # we will poll the socket
        # print('\n  Running B0 Remote API client with channel name ['+channelName+']')
        # print('  make sure that: 1) the B0 resolver is running')
        # print('                  2) CoppeliaSim is running the B0 Remote API server with the same channel name')
        # print('  Initializing...\n')
        self._node.init()
        self._handleFunction('inactivityTolerance', [inactivityToleranceInSec],
                             self._serviceCallTopic)
        # print('\n  Connected!\n')
        self._allSubscribers = {}
        self._allDedicatedPublishers = {}
        self._setupSubscribersAsynchronously = setupSubscribersAsynchronously
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
import b0

node = b0.Node('python-service-client')
cli = b0.ServiceClient(node, 'control')
node.init()
print('Using service "%s"...' % cli.get_service_name())
req_str = u'hellò'
print('Sending "%s"...' % req_str)
req = req_str.encode('utf-8')
rep = cli.call(req)
rep_str = rep.decode('utf-8')
print('Received "%s"' % rep_str)
node.cleanup()