public Form1() { InitializeComponent(); errorBox = new ErrorEventBox(); Phidget.enableLogging(Phidget.LogLevel.PHIDGET_LOG_VERBOSE, null); }
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(); }
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); } }