Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ping_BBB function in wiregrid_encoder #560

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/agents/wiregrid_encoder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ An example site-config-file block::

{'agent-class': 'WiregridEncoderAgent',
'instance-id': 'wgencoder',
'arguments': [['--port', 50007]]},
'arguments': [['--port', 50007],
['--ip-address', '192.168.11.29']]},

The port is used to receive the data from the BeagleBoneBlack.
The port number is determined in the script running in the BeagleBoneBlack.
The IP address is used to ping to the BeagleBoneBlack for connection check.

Docker Compose
``````````````
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pyepics
# xy_stage
xy_stage_control @ git+https://github.com/kmharrington/xy_stage_control.git@main

# wiregrid encoder agent
ping3

# pysmurf controller
pysmurf @ git+https://github.com/slaclab/pysmurf.git@main
sodetlib @ git+https://github.com/simonsobs/sodetlib.git@master
Expand Down
36 changes: 34 additions & 2 deletions socs/agents/wiregrid_encoder/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from ocs import ocs_agent, site_config
from ocs.ocs_twisted import TimeoutLock
from ping3 import ping

from socs.agents.wiregrid_encoder.drivers import EncoderParser

Expand All @@ -31,9 +32,11 @@ class WiregridEncoderAgent:
Args:
bbport(int): Port number of the PC
determined in the script running in the BBB.
bbip(str): IP address of the PC
determined in the script running in the BBB.
"""

def __init__(self, agent_obj, bbport=50007):
def __init__(self, agent_obj, bbport=50007, bbip='192.168.11.29'):

self.agent: ocs_agent.OCSAgent = agent_obj
self.log = agent_obj.log
Expand All @@ -42,6 +45,7 @@ def __init__(self, agent_obj, bbport=50007):
self.take_data = False

self.bbport = bbport
self.bbip = bbip

# Stored previous rising_edge_count and irig_time
self.rising_edge_count = 0
Expand All @@ -56,6 +60,13 @@ def __init__(self, agent_obj, bbport=50007):
self.agent.register_feed(
'wgencoder_full', record=True, agg_params=agg_params)

# Check ping to the BBB
ret, msg = self.ping_BBB()
if not ret:
msg = f'__init__(): {msg}'
self.log.error(msg)
raise

self.parser = EncoderParser(beaglebone_port=self.bbport)

def acq(self, session, params=None):
Expand Down Expand Up @@ -333,6 +344,21 @@ def stop_acq(self, session, params=None):
else:
return False, 'acq is not currently running.'

def ping_BBB(self, session, params=None):
"""ping_BBB()

**Task** - Ping to the beagleboneblack for wiregrid.

"""

ret = ping(self.ip)
if ret:
return True, f'Successfully ping to the BBB({self.ip}).'
elif ret is None:
return False, f'Failed to ping to the BBB({self.ip}). No response.'
else:
return False, f'Failed to ping to the BBB({self.ip}). Unknown host.'


def make_parser(parser=None):
if parser is None:
Expand All @@ -343,6 +369,10 @@ def make_parser(parser=None):
type=int, default=50007,
help='Port of the beaglebone '
'running wiregrid encoder DAQ')
pgroup.add_argument('--ip-address', dest='ip_address',
type=str, default='192.168.11.29',
help='IP address of the beaglebone '
'running wiregrid encoder DAQ')
return parser


Expand All @@ -354,11 +384,13 @@ def main(args=None):

agent, runner = ocs_agent.init_site_agent(args)

wg_encoder_agent = WiregridEncoderAgent(agent, bbport=args.port)
wg_encoder_agent = WiregridEncoderAgent(
agent, bbport=args.port, bbip=args.ip_address)

agent.register_process('acq',
wg_encoder_agent.acq,
wg_encoder_agent.stop_acq,
wg_encoder_agent.ping_BBB,
startup=True)

runner.run(agent, auto_reconnect=True)
Expand Down