Skip to content

Commit

Permalink
Timing out on UDP connections if the sensor is not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilNad committed Jan 26, 2024
1 parent eb9c6c5 commit 5e0267f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions AxiaDriver/udp_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import threading
from .configuration import AxiaConfiguration
from .communication import AxiaCommunication

'''
The AxiaUdpListener class listens to the UDP port of the Axia sensor and
Expand Down Expand Up @@ -30,12 +31,20 @@ def __init__(self, axia_config: AxiaConfiguration):
self._cpt = axia_config.counts_per_torque
self._connected = False

def connect(self):
def connect(self, timeout=5):
'''
Connects to the Axia sensor.
Listen to data coming from the Axia sensor via UDP packets.
timeout: The timeout in seconds for the connection.
'''

#Test if the sensor is connected by attempting a telnet connection.
# Calling the connect() method will raise an exception if the connection fails.
com = AxiaCommunication(self._ip_address)
com.connect(timeout=timeout)

self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._logger.info("Connected to {}:{} @ {} (Good Status = {})".format(self._ip_address, self._port, self._location, self._status))
self._logger.info("Listening to {}:{} @ {} (Good Status = {})".format(self._ip_address, self._port, self._location, self._status))
self._connected = True

def disconnect(self):
Expand Down

0 comments on commit 5e0267f

Please sign in to comment.