Exemplo n.º 1
0
        public void OpenCommandLine(Phidget phidget)
        {
            string[] args              = CommandLine;
            string   appName           = Assembly.GetEntryAssembly().GetName().Name;
            int      channel           = 0;
            int      serialNumber      = Phidget.AnySerialNumber;
            string   label             = Phidget.AnyLabel;
            int      hubPort           = Phidget.AnyHubPort;
            bool     isHubPort         = false;
            string   networkServerName = null;
            string   password          = null;
            string   logFile           = null;

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].EndsWith(appName))
                    {
                        continue;
                    }
                    if (args[i].StartsWith("-"))
                    {
                        string flag = args[i].Remove(0, 1);
                        switch (flag)
                        {
                        case "n":
                            isHubPort = true;
                            break;

                        case "l":
                            if (args.Length <= i + 1)
                            {
                                ShowInvalidCommandLineMessage(appName);
                                return;
                            }
                            logFile = args[++i];
                            break;

                        case "v":
                            if (args.Length <= i + 1)
                            {
                                ShowInvalidCommandLineMessage(appName);
                                return;
                            }
                            hubPort = int.Parse(args[++i]);
                            break;

                        case "c":
                            if (args.Length <= i + 1)
                            {
                                ShowInvalidCommandLineMessage(appName);
                                return;
                            }
                            channel = int.Parse(args[++i]);
                            break;

                        case "h":
                            isHubPort = true;
                            break;

                        case "s":
                            phidget.IsRemote = true;
                            if (i == args.Length - 1)
                            {
                                break;
                            }
                            if (args.Length <= i + 1)
                            {
                                ShowInvalidCommandLineMessage(appName);
                                return;
                            }
                            if (args[++i] != null && !args[i].StartsWith("-"))
                            {
                                networkServerName = args[i];
                            }
                            break;

                        case "p":
                            if (args.Length <= i + 1)
                            {
                                ShowInvalidCommandLineMessage(appName);
                                return;
                            }
                            password = args[++i];
                            break;

                        default:
                            ShowInvalidCommandLineMessage(appName);
                            break;
                        }
                    }
                    else
                    {
                        ShowInvalidCommandLineMessage(appName);
                    }
                }

                if (logFile != null)
                {
                    Phidget22.Log.Enable(LogLevel.Info, logFile);
                }
                phidget.Channel            = channel;
                phidget.DeviceSerialNumber = serialNumber;
                phidget.DeviceLabel        = label;
                phidget.HubPort            = hubPort;
                phidget.IsHubPortDevice    = isHubPort;
                phidget.ServerName         = networkServerName;

                if (phidget.IsRemote)
                {
                    Net.EnableServerDiscovery(ServerType.Device);
                    if (password != null && networkServerName != null)
                    {
                        Net.SetServerPassword(networkServerName, password);
                    }
                }
                else
                {
                    phidget.IsLocal = true;
                }
                phidget.Open();
            }
            catch (PhidgetException ex)
            {
                if (ex.ErrorCode == ErrorCode.Busy)
                {
                    if (ex.ErrorCode == ErrorCode.Busy)
                    {
                        MessageBox.Show("This hub port is in use - hub ports can only be opened in one mode at a time.", "Port in use", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else if (ex.ErrorCode == ErrorCode.Duplicate)
                    {
                        MessageBox.Show("This channel is already open - channels can only be opened once.", "Already open", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Phidget exception: " + ex.Message, "Phidget Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void openCmdLine(Phidget p)
        {
            string[] args    = commandLine;
            String   appName = System.AppDomain.CurrentDomain.FriendlyName;

            int    channel           = 0;
            int    serialNumber      = Phidget.AnySerialNumber;
            String label             = Phidget.AnyLabel;
            int    hubPort           = Phidget.AnyHubPort;
            bool   isHubPort         = false;
            String networkServerName = null;
            String password          = null;

            Debug.WriteLine(serialNumber);

            String logFile = null;

            try {             //Parse the command line flags
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].EndsWith(appName))
                    {
                        continue;
                    }

                    if (args[i].StartsWith("-"))
                    {
                        switch (args[i].Remove(0, 1).ToLower())
                        {
                        case "v":
                            hubPort = int.Parse(args[++i]);
                            break;

                        case "c":
                            channel = int.Parse(args[++i]);
                            break;

                        case "l":
                            logFile = (args[++i]);
                            break;

                        case "L":
                            label = args[++i];
                            break;

                        case "n":
                            serialNumber = int.Parse(args[++i]);
                            break;

                        case "h":
                            isHubPort = true;
                            break;

                        case "s":
                            p.IsRemote = true;                             //force open to look for "remote" devices only
                            if (i == args.Length - 1)                      //check if we are at the end of the args list implying no ssid provided
                            {
                                break;
                            }
                            if (args[++i] != null && !args[i].StartsWith("-"))                             //check for an ssid assuming we aren't at the end of the args list
                            {
                                networkServerName = args[i];
                            }
                            break;

                        case "p":
                            password = args[++i];
                            break;

                        default:
                            goto usage;
                        }
                    }
                    else
                    {
                        goto usage;
                    }
                }
                if (logFile != null)
                {
                    Phidget22.Log.Enable(LogLevel.Info, logFile);
                }

                p.Channel            = channel;
                p.DeviceSerialNumber = serialNumber;
                p.DeviceLabel        = label;
                p.HubPort            = hubPort;
                p.IsHubPortDevice    = isHubPort;
                p.ServerName         = networkServerName;

                if (p.IsRemote)
                {
                    Net.EnableServerDiscovery(ServerType.Device);                     //turn on network scan
                    if (password != null && networkServerName != null)
                    {
                        Net.SetServerPassword(networkServerName, password);                         //set the password if there is one
                    }
                }
                else
                {
                    p.IsLocal = true;                     //force open to search local devices only
                }
                p.Open();

                return;                 //success
            } catch (PhidgetException ex) {
                if (ex.ErrorCode == ErrorCode.Busy)
                {
                    MessageBox.Show("This hub port is in use - hub ports can only be opened in one mode at a time.",
                                    "Port In Use", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (ex.ErrorCode == ErrorCode.Duplicate)
                {
                    MessageBox.Show("This channel is already open - channels can only be opened once.",
                                    "Already Opened", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Phidget Exception: " + ex.Message, "Phidget Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                form.Close();
                return;
            } catch { }
usage:
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Invalid Command line arguments." + Environment.NewLine);
            sb.AppendLine("Usage: " + appName + " [Flags...]");
            sb.AppendLine("Flags:\t-n   serialNumber: Serial Number, omit for any serial");
            sb.AppendLine("\t-l   logFile: Enable phidget21 logging to logFile.");
            sb.AppendLine("\t-v   Port: Select the  Port that the device is connected to. 0 by default");
            sb.AppendLine("\t-c   deviceChannel: Select the specific channel of the device you want.  0 by default.");
            sb.AppendLine("\t-h   HubPort?: The device is connected to a hub port.");
            sb.AppendLine("\t-s   serverID\tServer Name, omit for any server");
            sb.AppendLine("\t-i   ipAddress:port\tIp Address and Port. Port is optional, defaults to 5000");
            sb.AppendLine("\t-p   password\tPassword, omit for no password" + Environment.NewLine);
            sb.AppendLine("Examples: ");
            sb.AppendLine(appName + " -n 50098 -h");
            sb.AppendLine(appName + " -n 1234567 -v 1 -c 0");
            sb.AppendLine(appName + " -r");
            sb.AppendLine(appName + " -s myphidgetserver");
            sb.AppendLine(appName + " -n 45670 -i 127.0.0.1:5001 -p password");
            MessageBox.Show(sb.ToString(), "Argument Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Application.Exit();
        }
Exemplo n.º 3
0
        public void OpenCmdLine(Phidget phidget)
        {
            string[] args              = CommandLine;
            string   appName           = System.AppDomain.CurrentDomain.FriendlyName;
            int      channel           = 0;
            int      serialNumber      = Phidget.AnySerialNumber;
            string   label             = Phidget.AnyLabel;
            int      hubPort           = Phidget.AnyHubPort;
            bool     isHubPort         = false;
            string   networkServerName = null;
            string   password          = null;
            string   logFile           = null;

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].EndsWith(appName))
                    {
                        continue;
                    }
                    if (args[i].StartsWith("-"))
                    {
                        switch (args[i].Remove(0, 1).ToLower())
                        {
                        case "v": hubPort = int.Parse(args[++i]);
                            break;

                        case "c": channel = int.Parse(args[++i]);
                            break;

                        case "l": logFile = (args[++i]);
                            break;

                        case "L": label = args[++i];
                            break;

                        case "n": isHubPort = true;
                            break;

                        case "s":
                            phidget.IsRemote = true;
                            if (i == args.Length - 1)
                            {
                                break;
                            }
                            if (args[++i] != null && !args[i].StartsWith("-"))
                            {
                                networkServerName = args[i];
                            }
                            break;

                        case "p": password = args[++i];
                            break;

                        default: goto usage;
                        }
                    }
                    else
                    {
                        goto usage;
                    }
                }

                if (logFile != null)
                {
                    Phidget22.Log.Enable(LogLevel.Info, logFile);
                }
                phidget.Channel            = channel;
                phidget.DeviceSerialNumber = serialNumber;
                phidget.DeviceLabel        = label;
                phidget.HubPort            = hubPort;
                phidget.IsHubPortDevice    = isHubPort;
                phidget.ServerName         = networkServerName;

                if (phidget.IsRemote)
                {
                    Net.EnableServerDiscovery(ServerType.Device);
                    if (password != null && networkServerName != null)
                    {
                        Net.SetServerPassword(networkServerName, password);
                    }
                }
                else
                {
                    phidget.IsLocal = true;
                }
                phidget.Open();
                return;
            }

            catch (PhidgetException ex)
            {
                if (ex.ErrorCode == ErrorCode.Busy)
                {
                    return;
                }
            }
usage:
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Invalid Command line arguments." + Environment.NewLine);
            stringBuilder.AppendLine("Usage: " + appName + " [Flags...]");
            stringBuilder.AppendLine("Flags:\t-n serialNumber: Serial Number, omit for any serial");
            stringBuilder.AppendLine("\t-l logFile: Enable phidget21 logging to logFile");
            stringBuilder.AppendLine("\t-v Port: Select the Port that the device is connected to. 0 by default");
            stringBuilder.AppendLine("\t-c deviceChannel: Select the specific channel of the device you want. 0 by default");
            stringBuilder.AppendLine("\t-h HubPort?: The device is connected to a hub port");
            stringBuilder.AppendLine("\t-s serverID\tServer Name, omit for any server");
            stringBuilder.AppendLine("\t-i ipAdress:port\tIp Address and Port. Port is optional, defaults to 5000");
            stringBuilder.AppendLine("\t-p password\tPassword, omit for no password" + Environment.NewLine);
            stringBuilder.AppendLine("Examples: ");
            stringBuilder.AppendLine(appName + " -n 50098 -h");
            stringBuilder.AppendLine(appName + " -n 1234567 -v 1 -c 0");
            stringBuilder.AppendLine(appName + "-r");
            stringBuilder.AppendLine(appName + " -s myphidgetserver");
            stringBuilder.AppendLine(appName + "-n 45670 -i 127.0.0.1:5001 -p password");
        }