levylabpitt / Instrument-Framework

An object-oriented framework for LabVIEW based on JKI SMOs.
BSD 3-Clause "New" or "Revised" License
4 stars 7 forks source link

Extend Help #105

Open ciozi137 opened 1 month ago

ciozi137 commented 1 month ago

Currently HELP

{
  "jsonrpc": "2.0",
  "method": "HELP",
  "id": "cbecd84d7b67f502880067bacad1dfa8"
}

returns a list of support commands:

{
  "jsonrpc": "2.0",
  "result": [
    "HELP",
    "ACK",
    "setConfiguration",
    "getAll",
    "getAllData",
    "Get Angle",
    "Get Helium Level",
    "Get Magnet",
    "Get Temperature",
    "Set Angle",
    "Set Chamber",
    "Set Magnet",
    "Set Temperature",
    "getAll"
  ],
  "id": "cbecd84d7b67f502880067bacad1dfa8"
}

Extend this so that HELP with the argument of of the commands will return the expected arguments and message format.

Example:

HELP Set Temperature

{
  "jsonrpc": "2.0",
  "method": "HELP",
  "params": {
    "Command": "Set Temperature"
  },
  "id": "cbecd84d7b67f502880067bacad1dfa8"
}

should return:

{
  "jsonrpc": "2.0",
  "results": {
    "jsonrpc": "2.0",
    "method": "Set Temperature",
    "params": {
      "Temperature (K)": 0,
      "Rate (K/min)": 0,
      "Channel": 0
    },
    "id": "#"
  },
  "id": "cbecd84d7b67f502880067bacad1dfa8"
}
ciozi137 commented 1 month ago

Range of valid parameters would also be useful

ciozi137 commented 1 month ago
{
  "jsonrpc": "2.0",
  "method": "setTemperature",
  "params": {
    "temperature": 75,
    "_metadata": {
      "temperature": {
        "valid_range": [60, 90],
        "description": "Temperature must be between 60 and 90 degrees."
      }
    }
  },
  "id": 1
}
ciozi137 commented 1 month ago

Documentation can be added to the response object however I want, and still remain valid JSON and valid JSON-RPC. I propose the following response object format:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "example": {
      "jsonrpc": "2.0",
      "method": "setTemperature",
      "params": {
        "temperature": 75,
        "rate": 5,
        "channel": 1
      },
      "id": 1
    },
    "documentation": {
      "temperature": {
        "description": "The temperature to set.",
        "valid_range": [
          60,
          90
        ],
        "units": "degrees"
      },
      "rate": {
        "description": "The rate of temperature change.",
        "valid_range": [
          1,
          10
        ],
        "units": "degrees per minute"
      },
      "channel": {
        "description": "The channel to set the temperature on.",
        "valid_range": [
          1,
          4
        ],
        "units": "channel number"
      }
    }
  }
}

The entire response from the server would be:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "example": {
      "jsonrpc": "2.0",
      "method": "setTemperature",
      "params": {
        "temperature": 75,
        "rate": 5,
        "channel": 1
      },
      "id": 1
    },
    "documentation": {
      "temperature": {
        "description": "The temperature to set.",
        "valid_range": [
          60,
          90
        ],
        "units": "degrees"
      },
      "rate": {
        "description": "The rate of temperature change.",
        "valid_range": [
          1,
          10
        ],
        "units": "degrees per minute"
      },
      "channel": {
        "description": "The channel to set the temperature on.",
        "valid_range": [
          1,
          4
        ],
        "units": "channel number"
      }
    }
  }
}
ciozi137 commented 1 month ago

Having difficulty constructing the dictionary containing LV variants:

{
  "jsonrpc": "2.0",
  "result": {
    "description": "Description of this method",
    "documentation": "{\"Path(s)\":{\"description\":\"path to something\",\"units\":\"any\",\"units\":\"none\"},\"Data\":{\"description\":\"data to log\",\"units\":\"whatever\",\"units\":\"variant\"}}",
    "example": "{\"jsonrpc\":\"2.0\",\"method\":\"setLogData\",\"params\":{\"Path(s)\":\"\",\"\":null},\"id\":\"abc123\"}"
  },
  "id": "efg456"
}
huipeng8 commented 1 month ago

I'm not sure. Is there a recursive call problem here? Perhaps we can process the JSON content contained in the resulting string by parsing the string.

ciozi137 commented 1 month ago

The issue appears to be with the JSON-text library and the way it parses variants, apparently by design:

Screenshot 2024-05-28 at 10 39 12 PM

What I want is for this code: image

to produce {"Path(s)":"","Data":""}

but instead it just makes {"Path(s)":"","":null}

huipeng8 commented 1 month ago

I did a simple test using JKI JSON and OPEN-G variants, not sure if this was the desired result test test.zip

ciozi137 commented 1 month ago

I was just using OpenG tools also. I think this will work: image JSON out: {"Path(s)":"","Data":""}

ciozi137 commented 1 month ago

Next issue how to remove all the escapes characters \" Not sure why JSON-text is adding them. Can probably construct the JSON object a different way

huipeng8 commented 1 month ago

在构建包含 LV 变体的字典时遇到困难:

{
  "jsonrpc": "2.0",
  "result": {
    "description": "Description of this method",
    "documentation": "{\"Path(s)\":{\"description\":\"path to something\",\"units\":\"any\",\"units\":\"none\"},\"Data\":{\"description\":\"data to log\",\"units\":\"whatever\",\"units\":\"variant\"}}",
    "example": "{\"jsonrpc\":\"2.0\",\"method\":\"setLogData\",\"params\":{\"Path(s)\":\"\",\"\":null},\"id\":\"abc123\"}"
  },
  "id": "efg456"
}

Where did we get the json object with the "\"? If just cancel the "\" and the """ in the beginning and end positions, can use the string directly

ciozi137 commented 1 month ago

It comes from the LV object to JSON object code, specifically JSONtext:Make JSON Object.vi when the LV Object is a nested cluster. I fix the problem by constructing the desired object a little more by hand: image

returns:

{
    "jsonrpc": "2.0",
    "result": {
        "description": "Description of this method",
        "documentation": {
            "Path(s)": {
                "description": "path to something",
                "valid range": "any",
                "units": "none"
            },
            "Data": {
                "description": "data to log",
                "valid range": "whatever",
                "units": "variant"
            }
        },
        "example": {
            "jsonrpc": "2.0",
            "method": "setLogData",
            "params": {
                "Path(s)": "",
                "Data": ""
            },
            "id": "abc123"
        }
    },
    "id": "efg456"
}
huipeng8 commented 1 month ago

Reference

https://bitbucket.org/drjdpowell/jsontext/issues/45/variant-name-missing-after-json

问题似乎出在 JSON 文本库及其解析变体的方式上,显然是设计使然: Screenshot 2024-05-28 at 10 39 12 PM

我想要的是这段代码: image

生产{"Path(s)":"","Data":""}

但相反,它只是使{"Path(s)":"","":null}

ciozi137 commented 3 weeks ago

Handle Help.vi is called by Handle Command.vi:

image

Get SMO Help.vi is an override method that will provide return the documentation to construct the Help Object:

image

ciozi137 commented 2 weeks ago

Update Get SMO HELP.vi: store documentation in a 2D string array (table). Much easier for the end user to end information image