Esempio n. 1
0
 public void SetupDialog()
 {
     EventLogger.LogMessage("Opening Setup Dialog Form", System.Diagnostics.TraceLevel.Info);
     var f = new SetupDialogForm(this, driverID, "Steps");
     f.ShowDialog();
     f.Dispose();
 }
Esempio n. 2
0
        public string Action(string actionName, string actionParameters)
        {
            // Make sure the action is supported.
            if(!GeminiSupportedActions.Contains(actionName))
                throw new System.ApplicationException("The requested action (" + actionName +") is not supported by this driver.");
            // Handle the requested action
            string returnValue = "";
            switch (actionName)
            {
                case "RefreshConfigNow":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.RefreshConfigNow();
                    break;

                case "HomeDevice":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.Home();
                    break;

                case "CenterDevice":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.Center();
                    break;

                case "GetDeviceNickname":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.Nickname;
                    break;

                case "SetDeviceNickname":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.Nickname = actionParameters;
                    break;

                case "GetTempCoeffValue":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    try
                    {
                        char c = actionParameters[0];
                        returnValue = myFoc.GetTempCoeffValue(c).ToString();
                    }
                    catch(IndexOutOfRangeException)
                    {
                        throw new ApplicationException("Action: GetTempCoeffValue expects a char parameter 'A' through 'E'");
                    }
                    break;
                case "SetTempCoeffValue":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    {
                        string[] parms = actionParameters.Split('|');
                        if (parms.Length != 2) throw new ApplicationException("The SetTempCoeffValue action requires exactly two parameters for (1)Mode and (2)New Value delimited by the | character." +
                             parms.Length.ToString() + " parameters were received.");
                        char mode = parms[0][0];    // the first (and only) character of the first parameter
                        int value = 0;
                        if (!int.TryParse(parms[1], out value)) throw new ApplicationException("The SetTempCoeffvalue action expects a valid integer for its second parameter. " +
                                parms[1] + " was received");
                        myFoc.SetTempCoeffValue(mode, value);
                        break;
                    }

                case "GetTempCoeffName":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    try
                    {
                        char c = actionParameters[0];
                        returnValue = myFoc.GetTempCoeffName(c);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new ApplicationException("Action: GetTempCoeffName expects an index parameter 'A' through 'E'");
                    }
                    break;

                case "SetTempCoeffName":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    {
                        string[] parms = actionParameters.Split('|');
                        if (parms.Length != 2) throw new ApplicationException("The SetTempCoeffName action requires exactly two parameters for (1)Mode and (2)New Name delimited by the | character." +
                             parms.Length.ToString() + " parameters were received.");
                        char mode = parms[0][0];    // the first (and only) character of the first parameter
                        myFoc.SetTempCoeffName(mode, parms[1]);
                        break;
                    }

                case "SetTempOffset":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.SetTempOffset(double.Parse(actionParameters));
                    break;

                case "GetTempOffset":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.GetTempOffset();
                    break;

                case "GetSelectedTempCompMode":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    try
                    {
                        returnValue = myFoc.TempCompMode;
                    }
                    catch
                    {
                        throw;
                    }
                    break;

                case "SetTempCompMode":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.TempCompMode = actionParameters;      // The TempCompMode property checks internally for the correct parameters.
                    break;

                case "GetLEDBrightness":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.LEDBrightness.ToString();
                    break;

                case "SetLEDBrightness":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    {
                        // Make sure we have a valid value.
                        double d;
                        int i;
                        if(!double.TryParse(actionParameters, out d)) throw new ApplicationException("SetLEDBrightness expects a valid number for its parameter. " +
                            "Received " + actionParameters);
                        i = (int)d;
                        myFoc.LEDBrightness = i;
                    }
                    break;

                case "GetDeviceType":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.DeviceType.ToString();
                    break;

                case "SetDeviceType":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.DeviceType = actionParameters[0];
                    break;

                case "GetTempComp":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.TempCompEnabled.ToString();
                    break;

                case "SetTempComp":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    if (actionParameters == true.ToString()) myFoc.TempCompEnabled = true;
                    else myFoc.TempCompEnabled = false;
                    break;

                case "GetBacklashCompSteps":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.BacklashCompSteps.ToString();
                    break;

                case "SetBacklashCompSteps":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    {
                        uint steps;
                        try{ steps = uint.Parse(actionParameters); }
                        catch { throw new ApplicationException("Error parsing steps parameter in SetBacklashCompSteps action. Value received = " + actionParameters); }
                        myFoc.BacklashCompSteps = steps;
                    }
                    break;

                case "GetBacklashCompEnabled":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.BacklashCompEnabled.ToString();
                    break;

                case "SetBacklashCompEnabled":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    if (actionParameters == true.ToString()) myFoc.BacklashCompEnabled = true;
                    else myFoc.BacklashCompEnabled = false;
                    break;

                case "GetFirmwareVersion":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = HubFocRot.FirmwareVersion.ToString();
                    break;

                case "GetCOMPortName":
                    returnValue = HubFocRot.COMPortName;
                    break;

                case "ForceHubDisconnect":
                    // Call the static method of HubFocuser class to disconnect the entire hub.
                    HubFocRot.ForceHubDisconnect();
                    break;

                case "GetConnectionType":
                    returnValue = HubFocRot.ConnectionMethod.ToString();
                    break;

                case "GetTempCompAtStart":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.TempCompAtStart.ToString();
                    break;

                case "SetTempCompAtStart":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.TempCompAtStart = bool.Parse(actionParameters);
                    break;

                case "SyncPosition":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.SetCurrentPosition(int.Parse(actionParameters));
                    break;

                case "ResetToDefaults":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.FocuserResetDefaults();
                    break;

                case "GetWiFiConnectionState":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = HubFocRot.WiFiModuleConnected.ToString();
                    break;

                case "GetWiFiAttachedState":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = HubFocRot.WiFiModuleAttached.ToString();
                    break;

                case "GetWiFiFirmware":
                    returnValue = HubFocRot.WiFiFirmwareVersion.ToString();
                    break;

                case "GetWiFiIPAddress":
                    returnValue = HubFocRot.WiFiIPAddress.ToString();
                    break;

                case "GetWiFiNetworkName":
                    returnValue = HubFocRot.WiFiNetworkSSID;
                    break;

                case "SetWiFiNetworkName":
                    HubFocRot.WiFiNetworkSSID = actionParameters;
                    break;

                case "GetWiFiSecurityType":
                    returnValue = HubFocRot.WiFiNetworkSecurityMode;
                    break;

                case "SetWiFiSecurityType":
                    HubFocRot.WiFiNetworkSecurityMode = actionParameters;
                    break;

                case "GetWiFiSecurityKey":
                    returnValue = HubFocRot.WiFiNetworkSecurityKey;
                    break;

                case "SetWiFiSecurityKey":
                    HubFocRot.WiFiNetworkSecurityKey = actionParameters;
                    break;

                case "GetWiFiWEPIndex":
                    returnValue = HubFocRot.WiFiNetworkWepKeyIndex.ToString();
                    break;

                case "SetWiFiWEPIndex":
                    HubFocRot.WiFiNetworkWepKeyIndex = int.Parse(actionParameters) - 1; //Convert from the 1-4 front end to the 0-3 back end
                    break;

                case "WiFiPushChanges":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    HubFocRot.WiFiPushChanges();
                    break;

                case "WiFiResetDefaults":
                    if (!HubFocRot.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    HubFocRot.WiFiResetDefaults();
                    break;
                case "SetupDialogNonStandard":
                    EventLogger.LogMessage("Opening Setup Dialog Form", System.Diagnostics.TraceLevel.Info);
                    var f = new SetupDialogForm(this, driverID, actionParameters);
                    f.ShowDialog();
                    f.Dispose();
                    break;

                default:
                    throw new ApplicationException("A supported action was requested but the driver cannot implement it. Requested Action = " + actionName +
                    " Please contact technical support.");
            }
            return returnValue;
        }