Skip to content

User interface and server data interchange

fabcor edited this page Jan 16, 2024 · 2 revisions

Warning

This page is now deprecated.

The up-to-date documentation can be found at:

https://mxcubecore.readthedocs.io/


Define the structure of the messages (a dictionary) to be exchanged and provide a common api for both the backend and the interface.

As a preliminary draft:

{
  "Data": {
	  DATA_STRUCTURE,
  },
  "Origin": aClass.aMethod, #who is sending the data
  "HTTP request": PUT/GET, # is this really useful?
  "Debug": True, #to print or not to print
  "Time": YY:MM:DD, HH:MM:SS,
  "Username": username,
  "Proposal": proposal
}

The data structure is very dependant on the request or action to be executed, for example for getting the status of a motor.

 "Data": { "kappa":{'Status': 'DeviceReady', 'Position': 3.14}  }

same for several:

 "Data": { "kappa":{'Status': 'DeviceReady', 'Position': 3.14},
         { "omega":{'Status': 'Moving', 'Position': 42.0} ,
         { "phi":{'Status': 'Unknown', 'Position': 2.72} 
}

We need to define the general structure and wherever we can the internal 'Data' field.

Another approach when sending data/commands from the client to the server could be to define everything in the url:

$.ajax({
      url: '/mxcube/api/v0.1/samplecentring/zoom/move?newpos='+newZoom, //where newZoom is e.g. 'Zoom 3'
      contentType: 'application/json;charset=UTF-8',
      type: 'PUT',
      success: function(res) {  :-)    },
      error: function(error) {  :-(    },
    });

And then in the server, get the argument

@mxcube.route("/mxcube/api/v0.1/samplecentring/<id>/move", methods=['PUT'])
def moveSampleCentringMotor(id):
    new_pos = request.args.get('newpos','')
    try:
        motor_hwobj = mxcube.diffractometer.getObjectByRole(id.lower()) # id would be 'zoom' in this example
        return 'True'
    except:
        return 'False' # or better a well formed dict