private void Page_Loaded(object sender, RoutedEventArgs e) { //Bind Buttons PointButton.StateChange += PointButton_StateChange; JoinButton.StateChange += JoinButton_StateChange; //Open ports PointButton.Open(); JoinButton.Open(); Output.Open(); }
//RFID Reader: Channel 0 //5V Digital Output: Channel 0 //LED Driver Ourput: Channel 1 //Onboard LED: Channel 2 public Form1() { InitializeComponent(); dig = new DigitalOutput(); dig.Channel = 2; dig.Open(); rfid = new RFID(); rfid.Open(); rfid.Attach += new AttachEventHandler(rfid_Attach); rfid.Detach += new DetachEventHandler(rfid_Detach); rfid.Error += new ErrorEventHandler(rfid_Error); rfid.Tag += new RFIDTagEventHandler(rfid_Tag); rfid.TagLost += new RFIDTagLostEventHandler(rfid_TagLost); }
static void Main(string[] args) { var greenButton = new DigitalInput(); greenButton.IsHubPortDevice = true; greenButton.HubPort = 1; var greenLed = new DigitalOutput(); greenLed.IsHubPortDevice = true; greenLed.HubPort = 3; var redButton = new DigitalInput(); redButton.IsHubPortDevice = true; redButton.HubPort = 0; var redLed = new DigitalOutput(); redLed.IsHubPortDevice = true; redLed.HubPort = 2; var sonar = new DistanceSensor(); sonar.HubPort = 4; sonar.Open(1000); redButton.Open(1000); redLed.Open(1000); greenButton.Open(1000); greenLed.Open(1000); greenButton.StateChange += (o, e) => { greenLed.State = e.State; }; redButton.StateChange += (o, e) => { redLed.State = e.State; if (e.State) { var sound = new SoundPlayer(@"C:\windows\media\tada.wav"); sound.Play(); var random = new Random(); Console.WriteLine("The next random number is {0}!", random.Next(0, 10)); } }; sonar.DistanceChange += (o, e) => { if (e.Distance > 100) { greenLed.State = true; redLed.State = false; } else { greenLed.State = false; redLed.State = true; } }; Console.WriteLine("Press enter to exit."); Console.ReadLine(); redButton.Close(); redLed.Close(); greenButton.Close(); greenLed.Close(); }
private void OnLoaded(object sender, RoutedEventArgs e) { this.socket = IO.Socket("http://192.168.0.182:2000"); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(800); // 2 sec timer.Tick += new EventHandler(timer_Tick); if (Window.GetWindow(this) != null) { WindowInteropHelper helper = new WindowInteropHelper(Window.GetWindow(this)); HwndSource.FromHwnd(helper.Handle).AddHook(new HwndSourceHook(this.WndProc)); } this.socket.On(Socket.EVENT_CONNECT_ERROR, () => { Console.WriteLine("EVT_CON_ERR"); }); this.socket.On(Socket.EVENT_CONNECT_TIMEOUT, () => { Console.WriteLine("EVT_CON_TOUT"); }); this.socket.On(Socket.EVENT_CONNECT, () => { Console.WriteLine("EVT_CON"); }); this.socket.On(Socket.EVENT_DISCONNECT, () => { Console.WriteLine("EVT_DISCON"); }); this.socket.On("attack-app-cs", () => { timer.Start(); }); this.socket.On("attack-obd-cs", () => { timer.Start(); }); this.socket.On("attack-auto-cs", () => { timer.Start(); }); this.socket.On("attack-usb-cs", () => { timer.Start(); }); this.socket.On("attack-rans-cs", () => { timer.Start(); }); this.socket.On("check-usb", (v) => { String command = v.ToString(); Boolean found = false; foreach (DriveInfo drive in DriveInfo.GetDrives()) { if (drive.DriveType == DriveType.Removable) { Console.WriteLine(string.Format("({0}) {1}", drive.Name.Replace("\\", ""), drive.VolumeLabel)); found = true; } } if (found == true) { if (command.Equals("check-usb-usb")) { this.socket.Emit("usb-status", "usb-on"); } else if (command.Equals("check-rans-usb")) { this.socket.Emit("usb-status", "rans-on"); } } else { this.socket.Emit("usb-status", "off"); } }); this.socket.On("reset", () => { timer.Stop(); ResetRelay(); }); this.socket.On("red", () => { PR1(true); PR2(false); PR3(false); print_PR(); }); this.socket.On("yellow", () => { PR1(false); PR2(true); PR3(false); print_PR(); }); this.socket.On("green", () => { PR1(false); PR2(false); PR3(true); print_PR(); }); string errmsg = ""; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { MessageBox.Show("RegisterHub error: " + errmsg); Environment.Exit(0); } relay1 = YRelay.FindRelay("RELAYLO1-CD6A7.relay1"); relay2 = YRelay.FindRelay("RELAYLO1-CD6A7.relay2"); digout1 = new DigitalOutput(); digout2 = new DigitalOutput(); digout3 = new DigitalOutput(); digout4 = new DigitalOutput(); digout1.Channel = 0; digout2.Channel = 1; digout3.Channel = 2; digout4.Channel = 3; try { digout1.IsLocal = true; digout2.IsLocal = true; digout3.IsLocal = true; digout4.IsLocal = true; digout1.Open(); digout2.Open(); digout3.Open(); digout4.Open(); } catch (PhidgetException ex) { Console.WriteLine(ex); } }