Пример #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();
 }
Пример #2
0
        public string Action(string actionName, string actionParameters)
        {
            // Make sure the action is supported.
            if(!flSupportedActions.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.RefreshConfigNow();
                    break;

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

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

                case "GetFocuserNumber":
                    returnValue = myFoc.FocuserNumber;
                    break;

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

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

                case "GetTempCoeffValue":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.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 (!HubFocuserRev2.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 (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    myFoc.SetTempOffset(double.Parse(actionParameters));
                    break;

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

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

                case "SetTempCompMode":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.LEDBrightness.ToString();
                    break;

                case "SetLEDBrightness":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.DeviceType.ToString();
                    break;

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

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

                case "SetTempComp":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.BacklashCompSteps.ToString();
                    break;

                case "SetBacklashCompSteps":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = myFoc.BacklashCompEnabled.ToString();
                    break;

                case "SetBacklashCompEnabled":
                    if (!HubFocuserRev2.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 (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    returnValue = HubFocuserRev2.FirmwareVersion.ToString();
                    break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                case "WiFiResetDefaults":
                    if (!HubFocuserRev2.IsHubConnected) throw new ASCOM.NotConnectedException("Operation cannot be completed. Device is not connected.");
                    HubFocuserRev2.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;
        }