private void button2_Click(object sender, EventArgs e) { if (button2.Text == "connectDevice") { if (dev.connectDevice() == true) { groupBox2.Enabled = true; label1.ForeColor = Color.Blue; this.label1.Text = "connected to " + HIDDevice.DevicePath; button2.Text = "disconnectDevice"; } else { groupBox2.Enabled = false; label1.ForeColor = Color.Red; this.label1.Text = "can not find any device."; } } else { dev.disconnectDevice(); button2.Text = "connectDevice"; } }
static void Main(string[] args) { //test device temp convert for (float i = -200; i < 1000; i += 0.1F) { Console.Write("float: " + i.ToString()); var hex = TempValueToHex(i.ToString()); Console.Write("\t TempValueToHex" + hex); Console.Write("\t HexToTempValue" + HexToTempValue(hex)); Console.WriteLine(); } ////////////////////////////////////////// DevicePDF dev = new DevicePDF(); dev.connectDevice(); dev.DoRead(); //dev.Data.Description = "tttttest"; //dev.Data.Operator = "zhurenjie did"; var data = dev.Data; Type t = data.GetType(); PropertyInfo[] infos = t.GetProperties(); foreach (PropertyInfo info in infos) { var value = t.GetProperty(info.Name).GetValue(dev.Data, null); //t.GetProperty(info.Name).SetValue(dev.Data, 111); Console.WriteLine(info.Name + ":" + value); if (value.GetType() == typeof(string[])) { string[] vs = (string[])value; for (int i = 0; i < vs.Length; i++) { Console.WriteLine(info.Name + i.ToString() + ":" + vs[i]); } } if (value.GetType() == typeof(List <string>)) { Console.WriteLine("press enter to show List:"); Console.ReadLine(); List <string> vs = (List <string>)value; for (int i = 0; i < vs.Count; i++) { Console.WriteLine(info.Name + i.ToString() + ":" + vs[i]); } } } Console.WriteLine("press enter to Write:"); Console.ReadLine(); //dev.Data.Description = "20110916"; //dev.Data.LogInterval = 1; //dev.Data.LogCycle = 1; //dev.Data.RunMode = 1; //dev.Data.StartMode = "F8"; //dev.Data.TripNo = "xxxxxxx"; //dev.Data.Description = "abcdefghijklmnopqrstuvwxyz"; dev.DoWrite(); Console.WriteLine("press enter to exit:"); Console.ReadLine(); //Console.ReadLine(); //dev = new DevicePDF(); //dev.connectDevice(); ////start get data .. //Console.WriteLine(dev.Data.AlarmDelay); ////the end . ////////////////////////////////////////////// //string status=dev.QueryStatus(); //Console.WriteLine(status + " " + DateTime.Now.ToString()); //Console.WriteLine(dev.AllData.Count.ToString() + " " + DateTime.Now.ToString()); //string row = ""; //row=dev.GetValue(0, 1); //dev.DoRead(); //row = dev.GetValue(0, 1); //Console.WriteLine(dev.AllData.Count.ToString() + " " + DateTime.Now.ToString()); //for (int i = 0; i < 600; i++) //{ // for (int j = 0; j < 8; j++) // Console.WriteLine(i.ToString("X4") + j.ToString("X2") + " " + dev.GetValue(i, j)); //} ////DeviceData dd = new DeviceData(dev); //var dd = dev.Data; //Console.WriteLine(dev.AllData.Count.ToString() + " " + DateTime.Now.ToString()); ////SpecifiedDevice dev = SpecifiedDevice.FindSpecifiedDevice(0x04d8, 0x0054); ////dev.DataSend += new DataSendEventHandler(dev_DataSend); ////dev.DataRecieved += new DataRecievedEventHandler(dev_DataRecieved); ////dev.SendData(HexToByte("68C000000000000000000000000000000000000000000000000000000000000000000000000000AA")); Thread.Sleep(1000); ////InputReport irp = dev.CreateInputReport(); ////Console.WriteLine("IRP:" + ToHexString(irp.Buffer)); ////dev.SendData(HexToByte("68C000000000000000000000000000000000000000000000000000000000000000000000000000AA")); Thread.Sleep(1000); ////irp = dev.CreateInputReport(); ////Console.WriteLine("IRP:" + ToHexString(irp.Buffer)); ////for (int i = 0; i < 1000; i++) ////{ //// for (int j = 0; j < 8; j++) //// { //// dev.SendData(HexToByte("68AA31"+i.ToString("X4") + j.ToString("X2") + "000000000000000000000000000000000000000000000000000000000000000000AA")); //// irp = dev.CreateInputReport(); //// Console.WriteLine("IRP:" + ToHexString(irp.Buffer)); //// } //// Thread.Sleep(100); ////} }