Skip to content

Commit

Permalink
Merge pull request #346 from vshekar/jsonize-server-comm
Browse files Browse the repository at this point in the history
Replaced python calls with json
  • Loading branch information
vshekar authored Nov 21, 2023
2 parents f81b72d + 21acc7f commit 6d644da
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 170 deletions.
88 changes: 74 additions & 14 deletions daq_main_common.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import _thread
import atexit
import json
import logging
import os
import string
import sys
import os
import time
import _thread
import traceback

import beamline_lib
import beamline_support
import config_params
import daq_lib
import daq_utils
import det_lib
import beamline_support
import beamline_lib
from start_bs import plt
import config_params
import atexit
import traceback
from beamline_lib import *
from daq_lib import *

#imports to get useful things into namespace for server
from daq_macros import *
from daq_lib import *
from robot_lib import *
from beamline_lib import *
from gov_lib import setGovRobot
from robot_lib import *
from start_bs import gov_robot, plt

import logging
logger = logging.getLogger(__name__)

sitefilename = ""
Expand All @@ -29,10 +31,68 @@
immediate_command_list = []
z = 25

def setGovState(state):
setGovRobot(gov_robot, state)


functions = [anneal,
set_beamsize,
importSpreadsheet,
mvaDescriptor,
setTrans,
loop_center_xrec,
autoRasterLoop,
snakeRaster,
ispybLib.insertRasterResult,
backlightBrighter,
backlightDimmer,
changeImageCenterHighMag,
changeImageCenterLowMag,
center_on_click,
runDCQueue,
warmupGripper,
dryGripper,
enableDewarTscreen,
parkGripper,
stopDCQueue,
continue_data_collection,
mountSample,
unmountSample,
reprocessRaster,
fastDPNodes,
spotNodes,
unmountCold,
openPort,
set_beamcenter,
closePorts,
clearMountedSample,
recoverRobot,
rebootEMBL,
restartEMBL,
openGripper,
closeGripper,
homePins,
setSlit1X,
setSlit1Y,
testRobot,
setGovState]

whitelisted_functions: "Dict[str, Callable]" = {
func.__name__: func for func in functions
}

def execute_command(command_s):
logger.info('executing command: %s' % command_s)
exec(command_s)
logger.info("executing command: %s" % command_s)
try:
command: "dict[str, Any]" = json.loads(command_s)
func = whitelisted_functions[command["function"]]
except Exception as e:
logger.exception(f"Error in function parsing and lookup: {e}")

try:
func(*command["args"], **command["kwargs"])
except Exception as e:
logger.exception(f"Error executing {command_s}: {e}")


def pybass_init():
Expand Down
Loading

0 comments on commit 6d644da

Please sign in to comment.