Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Python (http://www.chiefdelphi.com/forums/forumdisplay.php?f=187)
-   -   pynetworktables check server connection (http://www.chiefdelphi.com/forums/showthread.php?t=128653)

Thad House 09-04-2014 15:07

pynetworktables check server connection
 
I am working on something for this weekend, and I was wondering if there was a way to check and see if the pynetworktables client has a way to see if it is connected to the server on the robot? If there isnt a direct way, is there a way to hack around and check?

virtuald 10-04-2014 10:17

Re: pynetworktables check server connection
 
Yes, NetworkTables has a class called IRemoteConnectionListener that you can use with the AddConnectionListener/RemoveConnectionListener. I use the following code.

Code:

class RemoteListener(IRemoteConnectionListener):
    '''Calls a function when a table value is updated'''
   
    def __init__(self, connect_fn, disconnect_fn):
        '''fn must be a callable that takes (value)'''
        IRemoteConnectionListener.__init__(self)
        self.connect_fn = connect_fn
        self.disconnect_fn = disconnect_fn
       
    def attach(self, table):
        self.table = table
        table.AddConnectionListener(self, True)
       
    def detach(self):
        if hasattr(self, 'table'):
            self.table.RemoveConnectionListener(self)
       
    def Connected(self, remote):
        self.connect_fn(remote)
       
    def Disconnected(self, remote):
        self.disconnect_fn(remote)


Thad House 11-04-2014 00:09

Re: pynetworktables check server connection
 
Thanks for the reply. While looking through all the functions, I found an IsConnected function in the NetworkTables library, and that seems to work just fine. Thanks though.


All times are GMT -5. The time now is 19:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi