Exemple #1
0
        private void openCmdLine(Phidget p, String pass)
        {
            int    serial = -1;
            String logFile = null;
            int    port = 5001;
            String host = null;
            bool   remote = false, remoteIP = false;

            string[] args    = Environment.GetCommandLineArgs();
            String   appName = args[0];

            try
            {
                //if (logFile != null)
                //  Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_INFO, logFile);
                if (remoteIP)
                {
                    p.open(serial, host, port, pass);
                }
                else if (remote)
                {
                    p.open(serial, host, pass);
                }
                else
                {
                    p.open(serial);
                }
                return; //success
            }
            catch
            {
                throw (new SystemException("error"));
            }
        }
        public ErrorEventLogViewModel(Phidget phidget)
        {
            this.phidget = phidget;

            this.phidget.Error += (o, e) => {
                if (lastErrorMessage != e.Description)
                {
                    repeatedLastErrorMessageCount = 0;
                    ErrorMessages += $"{DateTime.Now:MMMM dd, yyyy H:mm:ss tt} - {e.Description}{Environment.NewLine}";
                }
                else
                {
                    repeatedLastErrorMessageCount++;
                    if (repeatedLastErrorMessageCount % 100 == 0)
                    {
                        ErrorMessages += $"last message repeated {repeatedLastErrorMessageCount} times{Environment.NewLine}";
                    }
                }
                lastErrorMessage = e.Description;
                ErrorCount++;
            };

            Close = new RelayCommand <Window>((window) => {
                this.phidget.Error += null;
                window.Close();
            });

            ClearLogs = new RelayCommand(() => {
                lastErrorMessage = "";
                ErrorCount       = 0;
                ErrorMessages    = "";
            });
        }
Exemple #3
0
        //Error event handler
        void ifKit_Error(object sender, ErrorEventArgs e)
        {
            Phidget phid = (Phidget)sender;

            switch (e.Type)
            {
            case PhidgetException.ErrorType.PHIDGET_ERREVENT_BADPASSWORD:

                break;

            case PhidgetException.ErrorType.PHIDGET_ERREVENT_PACKETLOST:
                //Ignore this error - it's not useful in this context.
                break;

            case PhidgetException.ErrorType.PHIDGET_ERREVENT_OVERRUN:
                //Ignore this error - it's not useful in this context.
                break;
            }
            if (m_errorEvent != null)
            {
                m_phidgetError = e.Type.ToString();
                m_eventCode[PhidgetCallbackCode.ERROR]++;
                m_errorEvent.Set();
            }
        }
Exemple #4
0
        void rfid_Error(object sender, ErrorEventArgs e)
        {
            Phidget      phid = (Phidget)sender;
            DialogResult result;

            switch (e.Type)
            {
            case PhidgetException.ErrorType.PHIDGET_ERREVENT_BADPASSWORD:
                phid.close();
                TextInputBox dialog = new TextInputBox("Error Event",
                                                       "Authentication error: This server requires a password.", "Please enter the password, or cancel.");
                result = dialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    openCmdLine(phid, dialog.password);
                }
                else
                {
                    Environment.Exit(0);
                }
                break;

            default:
                if (!errorBox.Visible)
                {
                    errorBox.Show();
                }
                break;
            }
            errorBox.addMessage(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + ": " + e.Description);
        }
Exemple #5
0
        public IPhidgetViewModel Create(Phidget phidget, bool makeFourTimesThermocouplePhidgetViewModel)
        {
            if (makeFourTimesThermocouplePhidgetViewModel)
            {
                return(CreateViewModel((dynamic)phidget));
            }

            return(CreateThermoPhidgetViewModelViewModel((dynamic)phidget));
        }
 void OnApplicationQuit()
 {
     if (Application.isEditor)
     {
         Phidget.ResetLibrary();
     }
     else
     {
         Phidget.FinalizeLibrary(0);
     }
 }
 void OnApplicationQuit()
 {
     Debug.Log("QUIT");
     if (Application.isEditor)
     {
         Phidget.ResetLibrary();
     }
     else
     {
         Phidget.FinalizeLibrary(0);
     }
 }
Exemple #8
0
        protected virtual void openCmdLine(Phidget p, String pass)
        {
            int serial = -1;

            try
            {
                p.open(serial);
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }
Exemple #9
0
    private void OnApplicationQuit()
    {
        for (int i = 0; i < 4; i++)
        {
            sensors[i].Close();
            sensors[i] = null;
        }

        if (Application.isEditor)
        {
            Phidget.ResetLibrary();
        }
        else
        {
            Phidget.FinalizeLibrary(0);
        }
    }
Exemple #10
0
        void rfid_Error(object sender, ErrorEventArgs e)
        {
            Phidget phid = (Phidget)sender;

            switch (e.Type)
            {
            case PhidgetException.ErrorType.PHIDGET_ERR_BADPASSWORD:
                phid.close();
                break;

            default:
                if (!errorBox.Visible)
                {
                    errorBox.Show();
                }
                break;
            }
            errorBox.addMessage(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + " : " + e.Description);
        }
        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();
        }
        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);
                    }
                }
            }
        }
Exemple #13
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");
        }
Exemple #14
0
 public AddressingInformationViewModel(Phidget phidget)
 {
     this.phidget = phidget;
 }
 private void openCmdLine(Phidget p)
 {
     openCmdLine(p, null);
 }
Exemple #16
0
 // コマンドラインから Parses command line arguments and calls the appropriate open
 #region Command line open functions
 private void OpenCmdLine(Phidget p)
 {
     OpenCmdLine(p, null);
 }
Exemple #17
0
 IPhidgetViewModel CreateViewModel(Phidget phidget)
 {
     return(new GenericPhidgetViewModel(phidget));
 }
Exemple #18
0
 protected virtual void openCmdLine(Phidget p)
 {
     openCmdLine(p, null);
 }
Exemple #19
0
 public Form1()
 {
     InitializeComponent();
     errorBox = new ErrorEventBox();
     Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_VERBOSE, null);
 }
Exemple #20
0
 void rfid_Error(object sender, ErrorEventArgs e)
 {
     Phidget p = (Phidget)sender;
 }
Exemple #21
0
 //Reference: https://stackoverflow.com/questions/56904776/casting-abstract-type-object-to-derived-type
 public IPhidgetViewModel Create(Phidget phidget)
 {
     return(CreateViewModel((dynamic)phidget));
 }
Exemple #22
0
        private void openCmdLine(Phidget p, String pass)
        {
            int    serial = -1;
            String logFile = null;
            int    port = 5001;
            String host = null;
            bool   remote = false, remoteIP = false;

            string[] args    = Environment.GetCommandLineArgs();
            String   appName = args[0];

            try
            { //Parse the flags
                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i].StartsWith("-"))
                    {
                        switch (args[i].Remove(0, 1).ToLower())
                        {
                        case "l":
                            logFile = (args[++i]);
                            break;

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

                        case "r":
                            remote = true;
                            break;

                        case "s":
                            remote = true;
                            host   = args[++i];
                            break;

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

                        case "i":
                            remoteIP = true;
                            host     = args[++i];
                            if (host.Contains(":"))
                            {
                                port = int.Parse(host.Split(':')[1]);
                                host = host.Split(':')[0];
                            }
                            break;

                        default:
                            goto usage;
                        }
                    }
                    else
                    {
                        goto usage;
                    }
                }
                if (logFile != null)
                {
                    Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_INFO, logFile);
                }
                if (remoteIP)
                {
                    p.open(serial, host, port, pass);
                }
                else if (remote)
                {
                    p.open(serial, host, pass);
                }
                else
                {
                    p.open(serial);
                }
                return; //success
            }
            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\tSerial Number, omit for any serial");
            sb.AppendLine("\t-l   logFile\tEnable phidget21 logging to logFile.");
            sb.AppendLine("\t-r\t\tOpen remotely");
            sb.AppendLine("\t-s   serverID\tServer ID, omit for any server");
            sb.AppendLine("\t-i   ipAddress:port\tIp Address and Port. Port is optional, defaults to 5001");
            sb.AppendLine("\t-p   password\tPassword, omit for no password" + Environment.NewLine);
            sb.AppendLine("Examples: ");
            sb.AppendLine(appName + " -n 50098");
            sb.AppendLine(appName + " -r");
            sb.AppendLine(appName + " -s myphidgetserver");
            sb.AppendLine(appName + " -n 45670 -i 127.0.0.1:5001 -p paswrd");
            MessageBox.Show(sb.ToString(), "Argument Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Application.Exit();
        }
Exemple #23
0
 public PhidgetsDevice(Phidget phidget)
 {
     m_Phidget = phidget;
     m_Device  = buildDevice();
 }
Exemple #24
0
        static void Main(string[] args)
        {
            try
            {
                Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_VERBOSE, null);
                ir = new IR();

                //Basic event handlers
                ir.Attach += new Phidgets.Events.AttachEventHandler(ir_Attach);
                ir.Detach += new Phidgets.Events.DetachEventHandler(ir_Detach);
                ir.Error  += new Phidgets.Events.ErrorEventHandler(ir_Error);

                //Specific event handlers
                ir.Code    += new Phidgets.Events.IRCodeEventHandler(ir_Code);
                ir.Learn   += new Phidgets.Events.IRLearnEventHandler(ir_Learn);
                ir.RawData += new Phidgets.Events.IRRawDataEventHandler(ir_RawData);

                //Open the device
                ir.open();

                //Wait for attachment
                Console.WriteLine("Waiting for PhidgetIR to be attached...");
                ir.waitForAttachment();

                //demonstrate sending a code
                Console.WriteLine("Press any key to send a code...");
                Console.ReadLine();

                //send the code for Apple remote Volume UP (Standard NEC encoding)
                IRCodeInfo codeInfo = new IRCodeInfo(
                    IRCodeInfo.IREncoding.Space,   //encoding
                    32,                            //bit count
                    new int[] { 9078, 4610 },      //header
                    new int[] { 593, 581 },        //zero
                    new int[] { 593, 1701 },       //one
                    593,                           //trail
                    108729,                        //gap
                    new int[] { 9078, 2345, 593 }  //repeat code
                    );

                ir.transmit(new IRCode("0x77e1d0f0", 32), codeInfo);

                //demonstrate sending RAW data
                Console.WriteLine("Press any key to send RAW data...");
                Console.ReadLine();

                //example of sending RAW Data - this was captured from an Apple remote Volume UP command
                int[] data =
                {
                    9040, 4590, 540,  630, 550, 1740, 550, 1750, 550, 1740,
                    550,   620, 550, 1750, 550, 1740, 550, 1750, 550, 1740,
                    550,  1740, 560, 1740, 540,  630, 550,  620, 550,  620,
                    540,   630, 550, 1750, 550, 1740, 560, 1740, 550,  620,
                    550,  1740, 550,  620, 550,  620, 560,  610, 550,  620,
                    550,  1750, 550, 1740, 550,  620, 550, 1740, 550, 1750,
                    550,   620, 550,  620, 550,  620, 540
                };

                ir.transmitRaw(data, 108729);

                //end
                Console.WriteLine("Press any key to end...");
                Console.ReadLine();

                //User input was rad so we'll terminate the program, so close the object
                ir.close();

                //set the object to null to get it out of memory
                ir = null;

                //If no expcetions where thrown at this point it is safe to terminate
                //the program
                Console.WriteLine("Done.");
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
        }
Exemple #25
0
 /* private void writeBtn_Click(object sender, EventArgs e)
  * {
  *  try
  *  {
  *      RFID.RFIDTagProtocol proto = (RFID.RFIDTagProtocol)Enum.Parse(typeof(RFID.RFIDTagProtocol), writeProtoCmb.SelectedItem.ToString());
  *      rfid.write(writeTagTxt.Text, proto, writeLockChk.Checked);
  *  }
  *  catch (PhidgetException ex)
  *  {
  *      MessageBox.Show("Error writing tag: " + ex.Message);
  *  }
  * }
  */
 //Parses command line arguments and calls the appropriate open
 #region Command line open functions
 private void openCmdLine(Phidget p)
 {
     openCmdLine(p, null);
 }
 public PhidgetsDevice(Phidget phidget)
 {
     m_Phidget = phidget;
     m_Device = buildDevice();
 }
Exemple #27
0
        public void FillPhidgetInfo(Phidget phidget)
        {
            channelTxt.Text = phidget.Channel.ToString();
            versionTxt.Text = phidget.DeviceVersion.ToString();

            if (phidget.IsHubPortDevice)
            {
                attachedDeviceNameTxt.Text = phidget.Hub.DeviceSKU + " - " + phidget.Hub.DeviceName;
            }
            else
            {
                attachedDeviceNameTxt.Text = phidget.DeviceSKU + " - " + phidget.DeviceName;
            }

            if (phidget.DeviceClass == DeviceClass.VINT)
            {
                serialNumberLbl.Text = "Hub Serial Number:";
                serialNumberTxt.Text = phidget.DeviceSerialNumber.ToString();

                hubPortLbl.Visible = true;
                hubPortTxt.Visible = true;
                hubPortTxt.Text    = phidget.HubPort.ToString();
            }
            else
            {
                serialNumberTxt.Text = phidget.DeviceSerialNumber.ToString();
            }

            try {
                String sku;

                if (phidget.IsHubPortDevice)
                {
                    sku = phidget.Hub.DeviceSKU.Split(new char[] { '/' })[0];
                }
                else
                {
                    sku = phidget.DeviceSKU.Split(new char[] { '/' })[0];
                }

                //Special attention to the 1018 because it's so common
                if (phidget.DeviceSKU.Contains("1018"))
                {
                    sku = "1018";
                }

                Assembly _assembly = Assembly.GetExecutingAssembly();
                String   imageName = _assembly.GetManifestResourceNames().Where(img => img.EndsWith(sku + ".png")).FirstOrDefault();

                if (imageName != null)
                {
                    pictureBox1.Image   = Image.FromStream(_assembly.GetManifestResourceStream(imageName));
                    line1.Size          = new System.Drawing.Size(groupBox1.Size.Width - 101, 1);
                    pictureBox1.Visible = true;
                }

                if (phidget.IsRemote)
                {
                    remoteLbl.Visible = true;
                }
                else
                {
                    remoteLbl.Visible = false;
                }
            } catch { }

            Control par = this.Parent;

            while (!(par is Form))
            {
                par = par.Parent;
            }

            ((Form)par).Text = phidget.ChannelName;
        }
        private void OnEncoderAttach(object sender, Phidget22.Events.AttachEventArgs e)
        {
            Phidget phidget = sender as Phidget;

            Version = phidget.DeviceVersion.ToString();
            Channel = phidget.Channel.ToString();

            if (phidget.IsHubPortDevice)
            {
                DeviceName = phidget.Hub.DeviceSKU + " - " + phidget.Hub.DeviceName;
            }
            else
            {
                DeviceName = phidget.DeviceSKU + " - " + phidget.DeviceName;
            }

            SerialNumber = phidget.DeviceSerialNumber.ToString();

            if (phidget.DeviceClass == DeviceClass.VINT)
            {
                SerialNumberName = "Hub Serial Number:";
                HubPortVisible   = Visibility.Visible;
                HubPort          = phidget.HubPort.ToString();
            }
            else
            {
                SerialNumberName = "Serial Number:";
                HubPortVisible   = Visibility.Visible;
            }

            try
            {
                String StockKeepingUnit;

                if (phidget.IsHubPortDevice)
                {
                    StockKeepingUnit = phidget.Hub.DeviceSKU.Split(new char[] { '/' })[0];
                }
                else
                {
                    StockKeepingUnit = phidget.DeviceSKU.Split(new char[] { '/' })[0];
                }

                if (phidget.DeviceSKU.Contains("1018"))
                {
                    StockKeepingUnit = "1018";
                }

                Assembly _assembly = Assembly.GetExecutingAssembly();
                String   imageName = _assembly.GetManifestResourceNames().Where(img => img.EndsWith(StockKeepingUnit + ".png")).FirstOrDefault();

                if (imageName != null)
                {
                    ImageSource  = BitmapFrame.Create(_assembly.GetManifestResourceStream(imageName));
                    ImageVisible = Visibility.Visible;
                }

                if (phidget.IsRemote)
                {
                    RemoteVisible = Visibility.Visible;
                }
                else
                {
                    RemoteVisible = Visibility.Collapsed;
                }
            }
            catch { }

            //Control par = this.Parent;
            //while (!(par is Form))
            //    par = par.Parent;
            //((Form)par).Text = phidget.ChannelName;

            Phidget22.Encoder attachedDevice = (Phidget22.Encoder)sender;

            if (_encoder.DeviceClass == DeviceClass.VINT)
            {
                try
                {
                    DataIntervalUnitText = "ms";
                    DataIntervalMinText  = attachedDevice.MinDataInterval.ToString();
                    DataIntervalMinimum  = attachedDevice.MinDataInterval;
                    DataIntervalMaxText  = attachedDevice.MaxDataInterval.ToString();
                    DataIntervalMaximum  = attachedDevice.MaxDataInterval;
                    DataIntervalValue    = attachedDevice.DataInterval;

                    if (attachedDevice.MaxDataInterval == attachedDevice.MinDataInterval)
                    {
                        DataIntervalEnable = false;
                    }

                    ChangeTriggerUnitText = "ticks";
                    ChangeTriggerMinText  = attachedDevice.MinPositionChangeTrigger.ToString();
                    ChangeTriggerMinimum  = attachedDevice.MinPositionChangeTrigger;
                    ChangeTriggerMaximum  = attachedDevice.MaxPositionChangeTrigger;
                    ChangeTriggerMaxText  = attachedDevice.MaxPositionChangeTrigger.ToString();
                    ChangeTriggerValue    = attachedDevice.PositionChangeTrigger;
                    //ChangeTriggerMinText = attachedDevice.PositionChangeTrigger.ToString("F0");
                }
                catch (PhidgetException ex)
                {
                    MessageBox.Show("Error setting data interval or change trigger: ", ex.Message);
                }
            }
            else
            {
                DataIntervalEnable  = false;
                ChangeTriggerEnable = false;
                IoModeEnable        = false;
            }

            _dataInterval      = attachedDevice.MinDataInterval;
            PositionChangeText = "N/A";
            TimeChangeText     = "N/A";
            PositionText       = "N/A";
            IndexPositionText  = "N/A";

            switch (((Phidget)sender).DeviceID)
            {
            case DeviceID.PN_1047:
                DeviceEnable     = true;
                IsEncoderChecked = true;
                IoModeEnable     = true;
                break;

            case DeviceID.PN_HIN1101:
                DeviceEnable     = true;
                IsEncoderChecked = true;
                IoModeEnable     = true;
                break;

            case DeviceID.PN_ENC1000:
                foreach (EncoderIOMode ioMode in Enum.GetValues(typeof(EncoderIOMode)))
                {
                    IOModes.Add(ioMode);
                }
                SelectedIOMode = IOModes.FirstOrDefault();
                break;

            case DeviceID.PN_DCC1000:
                foreach (EncoderIOMode ioMode in Enum.GetValues(typeof(EncoderIOMode)))
                {
                    IOModes.Add(ioMode);
                }
                SelectedIOMode = IOModes.FirstOrDefault();
                break;
            }

            GroupBoxSettingsEnable = true;
            DataEnable             = true;
        }
        private void openCmdLine(Phidget p, String pass)
        {
            int serial = -1;
            String logFile = null;
            int port = 5001;
            String host = null;
            bool remote = false, remoteIP = false;
            string[] args = Environment.GetCommandLineArgs();
            String appName = args[0];

            try
            { //Parse the flags
                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i].StartsWith("-"))
                        switch (args[i].Remove(0, 1).ToLower())
                        {
                            case "l":
                                logFile = (args[++i]);
                                break;
                            case "n":
                                serial = int.Parse(args[++i]);
                                break;
                            case "r":
                                remote = true;
                                break;
                            case "s":
                                remote = true;
                                host = args[++i];
                                break;
                            case "p":
                                pass = args[++i];
                                break;
                            case "i":
                                remoteIP = true;
                                host = args[++i];
                                if (host.Contains(":"))
                                {
                                    port = int.Parse(host.Split(':')[1]);
                                    host = host.Split(':')[0];
                                }
                                break;
                            default:
                                goto usage;
                        }
                    else
                        goto usage;
                }
                if (logFile != null)
                    Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_INFO, logFile);
                if (remoteIP)
                    p.open(serial, host, port, pass);
                else if (remote)
                    p.open(serial, host, pass);
                else
                    p.open(serial);
                return; //success
            }
            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\tSerial Number, omit for any serial");
            sb.AppendLine("\t-l   logFile\tEnable phidget21 logging to logFile.");
            sb.AppendLine("\t-r\t\tOpen remotely");
            sb.AppendLine("\t-s   serverID\tServer ID, omit for any server");
            sb.AppendLine("\t-i   ipAddress:port\tIp Address and Port. Port is optional, defaults to 5001");
            sb.AppendLine("\t-p   password\tPassword, omit for no password" + Environment.NewLine);
            sb.AppendLine("Examples: ");
            sb.AppendLine(appName + " -n 50098");
            sb.AppendLine(appName + " -r");
            sb.AppendLine(appName + " -s myphidgetserver");
            sb.AppendLine(appName + " -n 45670 -i 127.0.0.1:5001 -p paswrd");
            MessageBox.Show(sb.ToString(), "Argument Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Application.Exit();
        }
 public static void ShowErrorEventLogWindow(this IMaintainableViewModel viewmodel, Phidget phidget)
 {
     App.Current.Dispatcher.Invoke((Action) delegate {
         var window = new ErrorEventLogWindow()
         {
             DataContext = new ErrorEventLogViewModel(phidget)
         };
         window.Activate();
         window.Topmost = true;
         window.Show();
     });
 }