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
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
# -*- coding: utf-8 -*- import b0 import time if not b0.is_initialized(): b0.init() node = b0.Node('python-publisher') pub = b0.Publisher(node, 'A') node.init() print('Publishing to topic "%s"...' % pub.get_topic_name()) i = 0 while not node.shutdown_requested(): msg_str = u'µsg-%d' % i i += 1 print('Sending message "%s"...' % msg_str) msg = msg_str.encode('utf-8') pub.publish(msg) node.spin_once() time.sleep(1) node.cleanup()