/// <summary> /// Constructor attempts to automatically detect an ANT USB device and open a connection to it /// </summary> public ANTFS_ClientChannel(IANT_Channel channel_) { try { channel = channel_; // Create the ANT-FS client object if (ANTFSClient_New(ref unmanagedClientPtr) == 0) { throw new ANTFS_Exception("Unable to initialize ANT-FS Client"); } if (ANTFSClient_Init(unmanagedClientPtr, channel.getUnmgdFramer(), channel.getChannelNum()) == 0) { throw new ANTFS_Exception("Unable to initialize client"); } rawChannelResponseHandler += new dRawChannelResponseHandler((msg, size) => ANTFSClient_ProcessMessage(unmanagedClientPtr, ref msg, size)); deviceNotificationHandler += new dDeviceNotificationHandler(channel_DeviceNotification); channel.rawChannelResponse += rawChannelResponseHandler; channel.DeviceNotification += deviceNotificationHandler; // Setup thread to handle responses from the ANT-FS library bResponseThreadExit = false; ResponseThread = new Thread(new ThreadStart(ResponseThreadHandler)); ResponseThread.Name = "ANT-FS Client Response Thread"; ResponseThread.IsBackground = true; // Make this a background thread so it will terminate when main program closes ResponseThread.Start(); bInitialized = true; } catch (Exception) // Catch so we can cleanup { this.Dispose(); throw; // Forward the error to the caller } }
/// <summary> /// Creates ANT-FS object, response thread, and allocates unmanaged buffer for use with library /// </summary> public ANTFS_HostChannel(IANT_Channel channel_) { try { channel = channel_; // Create the ANT-FS host object if (ANTFSHost_New(ref unmanagedHostPtr) == 0) throw new ANTFS_Exception("Unable to initialize ANT-FS Host"); if (ANTFSHost_Init(unmanagedHostPtr, channel.getUnmgdFramer(), channel.getChannelNum()) == 0) throw new ANTFS_Exception("Unable to initialize host"); bInitialized = true; rawChannelResponseHandler = new dRawChannelResponseHandler( ( msg, size ) => ANTFSHost_ProcessMessage( unmanagedHostPtr, ref msg, size ) ); deviceNotificationHandler = new dDeviceNotificationHandler( channel_DeviceNotification ); channel.rawChannelResponse += rawChannelResponseHandler; channel.DeviceNotification += deviceNotificationHandler; // Allocate buffer to hold authentication response in native heap try { this.unmanagedAuthBuffer = Marshal.AllocHGlobal(Byte.MaxValue); this.unmanagedAuthSize = Marshal.AllocHGlobal(1); } catch (Exception ex) { throw new ANTFS_Exception("Unable to initialize ANT-FS Host: " + ex.Message); } // Setup thread to handle responses from the ANT-FS library bResponseThreadExit = false; ResponseThread = new Thread(new ThreadStart(ResponseThreadHandler)); ResponseThread.Name = "ANT-FS Host Response Thread"; ResponseThread.IsBackground = true; // Make this a background thread so it will terminate when main program closes ResponseThread.Start(); } catch { this.Dispose(); throw; } }
/// <summary> /// Constructor attempts to automatically detect an ANT USB device and open a connection to it /// </summary> public ANTFS_ClientChannel(IANT_Channel channel_) { try { channel = channel_; // Create the ANT-FS client object if (ANTFSClient_New(ref unmanagedClientPtr) == 0) throw new ANTFS_Exception("Unable to initialize ANT-FS Client"); if (ANTFSClient_Init(unmanagedClientPtr, channel.getUnmgdFramer(), channel.getChannelNum()) == 0) throw new ANTFS_Exception("Unable to initialize client"); rawChannelResponseHandler += new dRawChannelResponseHandler((msg,size) => ANTFSClient_ProcessMessage(unmanagedClientPtr, ref msg,size)); deviceNotificationHandler += new dDeviceNotificationHandler(channel_DeviceNotification); channel.rawChannelResponse += rawChannelResponseHandler; channel.DeviceNotification += deviceNotificationHandler; // Setup thread to handle responses from the ANT-FS library bResponseThreadExit = false; ResponseThread = new Thread(new ThreadStart(ResponseThreadHandler)); ResponseThread.Name = "ANT-FS Client Response Thread"; ResponseThread.IsBackground = true; // Make this a background thread so it will terminate when main program closes ResponseThread.Start(); bInitialized = true; } catch (Exception) // Catch so we can cleanup { this.Dispose(); throw; // Forward the error to the caller } }