static void Main(string[] args) { /* hello, world! */ Console.WriteLine("List of USB HID devices:"); /* browse for hid devices */ var devs = HIDBrowse.Browse(); /* display VID and PID for every device found */ foreach (var dev in devs) { Console.WriteLine("VID = " + dev.Vid.ToString("X4") + " PID = " + dev.Pid.ToString("X4") + " Product: " + dev.Product); } /* try to connect to first device */ if (devs.Count > 0) { /* new device */ HIDDev dev = new HIDDev(); /* connect */ dev.Open(devs[0]); /* an example of hid report, report id is always located * at the beginning of every report. Here it was set to 0x01. * adjust this report so it does meet your hid device reports */ byte[] report = new byte[32]; report[0] = 0x01; /* send report */ dev.Write(report); /* get response */ dev.Read(report); } /* bye bye! */ Console.Read(); }
private static void Main(string[] args) { /* hello, world! */ Console.WriteLine("Looking for DsHidMini devices"); /* browse for hid devices */ var devs = HIDBrowse.Browse().Where(d => d.Vid == 0x054C && d.Pid == 0x0268); if (!devs.Any()) { Console.WriteLine("None found, nothing to do"); return; } Console.WriteLine("Found one"); var instructions = ((IList <dynamic>)Config.Global.Instructions) .Select(i => new ReplayEntry((string)i.OutputReport, (int)i.WaitPeriodMs, (int)i.SendXTimes, (int)i.RepeatDelay)).ToList(); /* new device */ var dev = new HIDDev(); /* connect */ dev.Open(devs.First()); /* send report */ String userin; Console.Write("Execute how many times? (0 = indefinitely): "); userin = Console.ReadLine(); int FullRepeat = Convert.ToInt32(userin); Console.WriteLine(); int FR = 1; while (FullRepeat == 0 || FR <= FullRepeat) { Console.Clear(); if (FullRepeat >= 1) { Console.WriteLine("===== EXECUTING (" + FR + "/" + FullRepeat + ") ====="); Console.WriteLine(); } int CurrentI = 0; foreach (var instruction in instructions) { Console.WriteLine("Executing instructions block number " + CurrentI); int P = 1; while (P <= instruction.TimesToSend) { dev.Write(instruction.Report); Console.Write("."); // Print "." to inform that a command has been sent if (P == instruction.TimesToSend) // Break; if on the last repeat to prevent an aditional delay on Thread.Sleep(instruction.RepDelay) { Console.WriteLine(); Console.WriteLine(P + " command(s) sent"); // informs the number of sent commands break; } if (instruction.RepDelay > TimeSpan.Zero) // Print "-" if RepDelay > 0 { Console.Write("-"); Thread.Sleep(instruction.RepDelay); } P++; } if (instruction.WaitPeriod > TimeSpan.Zero) { Console.WriteLine("Waiting for " + instruction.WaitPeriod + "ms"); Thread.Sleep(instruction.WaitPeriod); } else { Console.WriteLine("Not waiting"); } CurrentI++; Console.WriteLine(); } if (FullRepeat >= 1) { FR++; } } Console.WriteLine("Done!"); Console.Read(); }