static void Main(string[] args) { SetLogFileName("fbtrt.log"); SetLogLevel(255); int devId = OpenDevice(); if (devId == -1) { W32_ERROR error = (W32_ERROR)GetLastError(); if (W32_ERROR.ERROR_DEVICE_IN_USE == error) { Console.WriteLine("ERROR_DEVICE_IN_USE"); } else if (W32_ERROR.ERROR_DEVICE_NOT_AVAILABLE == error) { Console.WriteLine("ERROR_DEVICE_NOT_AVAILABLE"); } } else { hciEventListener = new HciEventListenerDelegate(OnHciEvent); SubscribeHCIEvent(devId, hciEventListener); //Console.WriteLine("Enter HCI command (empty for exit):"); //for (;;) //{ // string cmd = Console.ReadLine(); // if (cmd.Length == 0) break; //} byte[] reset = new byte[] { 0x01, 0x03, 0x0c, 0x00 }; //byte[] connect = new byte[] { 0x05, 0x04, 0x0d, 0xf7, 0x00, 0xfd, 0x76, 0x02, 0x00, 0x18, 0xcc, 0x01, 0x00, 0x00, 0x00, 0x01 }; //byte[] acl = new byte[] { 0x01, 0x20, 0x0c, 0x00, 0x08, 0x00, 0x01, 0x00, 0x02, 0x0a, 0x04, 0x00, 0x01, 0x00, 0x43, 0x00 }; byte[] buffer = reset; int ret = SendHCICommand(devId, buffer, (uint)buffer.Length); string result = (ret != 0) ? "OK" : "Fail"; string packetType = "COMMAND_PACKET"; string packetData = BytesToHex(buffer, buffer.Length); Console.WriteLine(string.Format("{0}: {1} {2}", packetType, packetData, result)); Thread.Sleep(1000); int size = 256; IntPtr hglobal = Marshal.AllocHGlobal(size); for (ushort i = ushort.MinValue; i < ushort.MaxValue; ++i) { ret = GetManufacturerName(i, hglobal, (uint)size); if (ret == 1) { string manufacturer = Marshal.PtrToStringUni(hglobal); Console.WriteLine(manufacturer); } else { break; } } Marshal.FreeHGlobal(hglobal); Console.WriteLine("Press any key..."); Console.ReadLine(); /* * uint sent = 0; * buffer = acl; * ret = SendData(buffer, (uint)buffer.Length, ref sent); * result = (ret != 0) ? "OK" : "Fail"; * packetType = "ACL_PACKET"; * packetData = BytesToHex(buffer, buffer.Length); * Console.WriteLine(string.Format("{0}: {1} {2}", packetType, packetData, result)); * * Console.ReadLine(); * * byte[] bigBuffer = new byte[1024]; * uint readed = 0; * ret = GetData(bigBuffer, (uint)bigBuffer.Length, ref readed); * result = (ret != 0) ? "OK" : "Fail"; * packetType = "Get Data"; * packetData = BytesToHex(bigBuffer, (int)readed); * Console.WriteLine(string.Format("{0}: {1} {2}", packetType, packetData, result)); */ CloseDevice(devId); } }
public static extern int SubscribeHCIEvent(int devId, HciEventListenerDelegate hciEventListener);
static void Main( string[] args ) { SetLogFileName("fbtrt.log"); SetLogLevel(255); int devId = OpenDevice(); if ( devId == -1 ) { W32_ERROR error = (W32_ERROR)GetLastError(); if ( W32_ERROR.ERROR_DEVICE_IN_USE == error ) { Console.WriteLine( "ERROR_DEVICE_IN_USE" ); } else if ( W32_ERROR.ERROR_DEVICE_NOT_AVAILABLE == error ) { Console.WriteLine("ERROR_DEVICE_NOT_AVAILABLE" ); } } else { hciEventListener = new HciEventListenerDelegate( OnHciEvent ); SubscribeHCIEvent( devId, hciEventListener ); //Console.WriteLine("Enter HCI command (empty for exit):"); //for (;;) //{ // string cmd = Console.ReadLine(); // if (cmd.Length == 0) break; //} byte[] reset = new byte[] { 0x01, 0x03, 0x0c, 0x00 }; //byte[] connect = new byte[] { 0x05, 0x04, 0x0d, 0xf7, 0x00, 0xfd, 0x76, 0x02, 0x00, 0x18, 0xcc, 0x01, 0x00, 0x00, 0x00, 0x01 }; //byte[] acl = new byte[] { 0x01, 0x20, 0x0c, 0x00, 0x08, 0x00, 0x01, 0x00, 0x02, 0x0a, 0x04, 0x00, 0x01, 0x00, 0x43, 0x00 }; byte[] buffer = reset; int ret = SendHCICommand(devId, buffer, (uint)buffer.Length); string result = ( ret != 0 ) ? "OK" : "Fail"; string packetType = "COMMAND_PACKET"; string packetData = BytesToHex(buffer, buffer.Length); Console.WriteLine( string.Format( "{0}: {1} {2}", packetType, packetData, result ) ); Thread.Sleep(1000); int size = 256; IntPtr hglobal = Marshal.AllocHGlobal(size); for (ushort i = ushort.MinValue; i < ushort.MaxValue; ++i) { ret = GetManufacturerName(i, hglobal, (uint)size); if (ret == 1) { string manufacturer = Marshal.PtrToStringUni(hglobal); Console.WriteLine(manufacturer); } else { break; } } Marshal.FreeHGlobal(hglobal); Console.WriteLine("Press any key..."); Console.ReadLine(); /* uint sent = 0; buffer = acl; ret = SendData(buffer, (uint)buffer.Length, ref sent); result = (ret != 0) ? "OK" : "Fail"; packetType = "ACL_PACKET"; packetData = BytesToHex(buffer, buffer.Length); Console.WriteLine(string.Format("{0}: {1} {2}", packetType, packetData, result)); Console.ReadLine(); byte[] bigBuffer = new byte[1024]; uint readed = 0; ret = GetData(bigBuffer, (uint)bigBuffer.Length, ref readed); result = (ret != 0) ? "OK" : "Fail"; packetType = "Get Data"; packetData = BytesToHex(bigBuffer, (int)readed); Console.WriteLine(string.Format("{0}: {1} {2}", packetType, packetData, result)); */ CloseDevice(devId); } }