ASCOMInitiative / ASCOMRemote

The ASCOM REST based Remote Driver Server and Remote Access Clients
GNU General Public License v3.0
57 stars 15 forks source link

Error during processing Az in dome slewing mode #21

Closed Ghir8 closed 2 years ago

Ghir8 commented 3 years ago

Most ASCOM Client that we've tested, when try to slave the dome rotation with the telescope, send Az as double with respect of regional format, so the parser in CallMethod present in "Remote Server/ServerForm.cs" fail to correctly parse the sting in a proper double.

Logs shows:

RequestReceived        Processed parameter key and value: Azimuth = 194,127878108074
[...]
RequestReceived        Parameter Azimuth = 194,127878108074
[...]
slewtoazimuth          Parameter Azimuth = 194127878108074

A simple solution is including a string substitution directly in the switch of the GetParameter method, to avoid any other regional problems with doubles due to the InvariantCulture parameter, as you can see in our fork:

case "Double":
        parameterStringValue = parameterStringValue.Replace(",", ".");  
        double doubleValue;
        if (!double.TryParse(parameterStringValue, NumberStyles.Number, CultureInfo.InvariantCulture, out doubleValue)) throw new InvalidParameterException(string.Format("GetParameter - Supplied argument {0} for parameter {1} can not be converted to a floating point value", parameterStringValue, ParameterName));
        LogMessage1(requestData, requestData.Elements[URL_ELEMENT_METHOD], string.Format("{0} = {1}", ParameterName, doubleValue.ToString()));
        return (T)(object)doubleValue

With this method the parser don't fail and the dome move as expected, as you can se in the logs:

RequestReceived        Processed parameter key and value: Azimuth = 183,782590744931
[...]
RequestReceived        Parameter Azimuth = 183,782590744931
[...]
slewtoazimuth          Parameter Azimuth = 183.782590744931
Peter-Simpson commented 2 years ago

JSON requires numbers to use point as the decimal separator and for consistency across the Alpaca API we have adopted this standard for parameter values as well. This is now documented in the Alpaca API reference on page 7.

Best wishes, Peter