/// <overloads>Configure the device ANT library, ie: to send extra msg info</overloads> /// <summary> /// Configure the device ANT library, ie: to send extra msg info /// </summary> /// <param name="libConfigFlags">Config flags</param> /// <param name="responseWaitTime">Time to wait for response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool setLibConfig(ANT_ReferenceLibrary.LibConfigFlags libConfigFlags, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return ANT_SetLibConfig(unmanagedANTFramerPtr, (byte)libConfigFlags, responseWaitTime) == 1; }
public void setCryptoInfo(ANT_ReferenceLibrary.EncryptionInfo encryptionParameter, byte[] parameterData) { setCryptoInfo(encryptionParameter, parameterData, 0); }
/// <summary> /// Request a message from device /// </summary> /// <param name="messageID">Request to send</param> public void requestMessage(ANT_ReferenceLibrary.RequestMessageID messageID) { requestMessage(0, messageID); }
/// <summary> /// Request a message from device on channel 0 and returns the response. /// Throws exception on timeout. /// </summary> /// <param name="messageID">Request to send</param> /// <param name="responseWaitTime">Time to wait for device success response</param> public ANT_Response requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID messageID, UInt32 responseWaitTime) { return requestMessageAndResponse(0, messageID, responseWaitTime); }
/// <summary> /// Configure advanced bursting for this device. /// </summary> /// <param name="enable">Whether to enable advanced bursting messages</param> /// <param name="maxPacketLength">Maximum packet length allowed for bursting messages (valid values are 1-3)</param> /// <param name="requiredFields">Features that the application requires the device to use</param> /// <param name="optionalFields">Features that the device should use if it supports them</param> public void configureAdvancedBursting(bool enable, byte maxPacketLength, ANT_ReferenceLibrary.AdcancedBurstConfigFlags requiredFields, ANT_ReferenceLibrary.AdcancedBurstConfigFlags optionalFields) { configureAdvancedBursting(enable, maxPacketLength, requiredFields, optionalFields, (UInt32)0); }
/// <summary> /// Configure advanced bursting for this device including extended parameters. /// </summary> /// <param name="enable">Whether to enable advanced bursting messages</param> /// <param name="maxPacketLength">Maximum packet length allowed for bursting messages (valid values are 1-3)</param> /// <param name="requiredFields">Features that the application requires the device to use</param> /// <param name="optionalFields">Features that the device should use if it supports them</param> /// <param name="stallCount">Maximum number of burst periods (~3.1ms) to stall for while waiting for the next message</param> /// <param name="retryCount">Number of times (multiplied by 5) to retry burst</param> public void configureAdvancedBursting_ext(bool enable, byte maxPacketLength, ANT_ReferenceLibrary.AdcancedBurstConfigFlags requiredFields, ANT_ReferenceLibrary.AdcancedBurstConfigFlags optionalFields, UInt16 stallCount, byte retryCount) { configureAdvancedBursting_ext(enable, maxPacketLength, requiredFields, optionalFields, stallCount, retryCount, 0); }
/// <summary> /// Creates and fills the ChannelStatus /// </summary> /// <param name="BasicStatus"></param> /// <param name="networkNumber"></param> /// <param name="ChannelType"></param> public ANT_ChannelStatus(ANT_ReferenceLibrary.BasicChannelStatusCode BasicStatus, byte networkNumber, ANT_ReferenceLibrary.ChannelType ChannelType) { this.BasicStatus = BasicStatus; this.networkNumber = networkNumber; this.ChannelType = ChannelType; }
/// <overloads>Initializes and starts CW test mode</overloads> /// <summary> /// Initialize and start CW test mode. This mode is to test your implementation for RF frequency requirements. /// The device will transmit an unmodulated carrier wave at the RF frequency of 2400Mhz + RFFreqOffset at the specified power level. /// This mode can then only be exited by a system reset. /// Note: When this function call returns false, the system will be reset automatically. /// </summary> /// <param name="transmitPower">Transmission power to test at</param> /// <param name="RFFreqOffset">Offset to add to 2400Mhz</param> /// <param name="responseWaitTime">Time to wait for response, used for both initialization and start command</param> /// <returns>False if initialization or starting of CW test mode fails. On false, the system is automatically reset.</returns> /// <remarks> /// This function encapsulates both ANT_InitCWTestMode and ANT_SetCWTestMode from the old library. /// It will automatically reset the system if either call fails. /// The given response time is used for both calls and the reset time is 500ms. /// So max wait time = responseTime*2 + 500ms /// </remarks> public bool startCWTest(ANT_ReferenceLibrary.TransmitPower transmitPower, byte RFFreqOffset, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); bool retVal = true; ResetSystem(); //CW Mode is only supposed to be set up after a reset if (ANT_InitCWTestMode(unmanagedANTFramerPtr, responseWaitTime) != 1) retVal = false; if (ANT_SetCWTestMode(unmanagedANTFramerPtr, (byte)transmitPower, RFFreqOffset, responseWaitTime) != 1) retVal = false; if (retVal == false && ANT_Common.autoResetIsEnabled) //If we messed up we want to make sure the module doesn't get messed up in CW mode, so we reset ResetSystem(500); return retVal; }
/// <summary> /// Allows buffering of ANT events. Preset groups of events may be selected for buffering. /// Events may be buffered by size or time and buffering can be used in conjunction with filtering. /// </summary> /// <param name="config">Selects which events are buffered</param> /// <param name="size">Number of bytes that will be stored before a buffer flush occurs. Set to 0 to disable.</param> /// <param name="time">Maximum time (in 10ms units) before a buffer flush occurs. Set to 0 to disable. /// Buffer size must also be set to a non zero value.</param> public void configureEventBuffer(ANT_ReferenceLibrary.EventBufferConfig config, UInt16 size, UInt16 time) { configureEventBuffer(config, size, time, 0); }
/// <summary> /// Configures the transmit power for the ANT-FS channel, in case /// different power levels are desired in the link and connected states, /// for example, to allow the use of proximity search in a host device. /// If not configured, the transmit power will be set to 0dBm. /// </summary> /// <param name="pairingLevel">Transmit power to use while in Link state</param> /// <param name="connectedLevel">Transmit power to use after a connection has been established to a host</param> public void SetTransmitPower(ANT_ReferenceLibrary.TransmitPower pairingLevel, ANT_ReferenceLibrary.TransmitPower connectedLevel) { if (!bInitialized) throw new ObjectDisposedException("ANTFSClient object has been disposed"); ANTFSClient_SetTxPower(unmanagedClientPtr, (byte) pairingLevel, (byte) connectedLevel); }
/// <overloads>Configures Event Buffering</overloads> /// <summary> /// Allows buffering of ANT events. Preset groups of events may be selected for buffering. /// Events may be buffered by size or time and buffering can be used in conjunction with filtering. /// </summary> /// <param name="config">Selects which events are buffered</param> /// <param name="size">Number of bytes that will be stored before a buffer flush occurs. Set to 0 to disable.</param> /// <param name="time">Maximum time (in 10ms units) before a buffer flush occurs. Set to 0 to disable. /// Buffer size must also be set to a non zero value.</param> /// <param name="responseWaitTime">Time to wait for device success response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool configureEventBuffer(ANT_ReferenceLibrary.EventBufferConfig config, UInt16 size, UInt16 time, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return ANT_ConfigEventBuffer(unmanagedANTFramerPtr, (byte)config, size, time, responseWaitTime) == 1; }
public void cryptoKeyNVMOp(ANT_ReferenceLibrary.EncryptionNVMOp memoryOperation, byte nonVolatileKeyIndex, byte[] operationData) { cryptoKeyNVMOp(memoryOperation, nonVolatileKeyIndex, operationData, 0); }
public bool cryptoKeyNVMOp(ANT_ReferenceLibrary.EncryptionNVMOp memoryOperation, byte nonVolatileKeyIndex, byte[] operationData, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return (ANT_CryptoKeyNVMOp(unmanagedANTFramerPtr, (byte)memoryOperation, nonVolatileKeyIndex, operationData, responseWaitTime) == 1); }
/// <overloads>Sets the transmit power for all channels</overloads> /// <summary> /// Set the transmit power for all channels of this device /// </summary> /// <param name="transmitPower">Transmission power to set to</param> /// <param name="responseWaitTime">Time to wait for device success response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool setTransmitPowerForAllChannels(ANT_ReferenceLibrary.TransmitPower transmitPower, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return (ANT_SetTransmitPower(unmanagedANTFramerPtr, (byte)transmitPower, responseWaitTime) == 1); }
/// <summary> /// Assign an ANT channel. /// </summary> /// <param name="channelTypeByte">Channel Type byte</param> /// <param name="networkNumber">Network to assign to channel</param> public void assignChannel(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber) { assignChannel(channelTypeByte, networkNumber, 0); }
/// <summary> /// Set the transmit power for all channels of this device /// </summary> /// <param name="transmitPower">Transmission power to set to</param> public void setTransmitPowerForAllChannels(ANT_ReferenceLibrary.TransmitPower transmitPower) { setTransmitPowerForAllChannels(transmitPower, 0); }
/// <overloads>Assign channel (extended)</overloads> /// <summary> /// Assign an ANT channel, using extended channel assignment /// Throws exception if the network number is invalid. /// </summary> /// <param name="channelTypeByte">Channel Type byte</param> /// <param name="networkNumber">Network to assign to channel, must be less than device's max netwoks - 1</param> /// <param name="extAssignByte">Extended assignment byte</param> /// <param name="responseWaitTime">Time to wait for device success response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte, UInt32 responseWaitTime) { if (disposed) throw new ObjectDisposedException("This ANTChannel object has been disposed"); if (networkNumber > creatingDevice.getDeviceCapabilities().maxNetworks - 1) throw new ANT_Exception("Network number must be less than device's max networks - 1"); return (ANT_AssignChannelExt(unmanagedANTFramerPointer, channelNumber, (byte)channelTypeByte, networkNumber, (byte)extAssignByte, responseWaitTime) == 1); }
//This is all the initialization, pulled out to this method so it could be called by both constructors private void startUp(byte USBDeviceNum, uint baudRate, ANT_ReferenceLibrary.FramerType frameType, ANT_ReferenceLibrary.PortType portType, bool calledByAutoInit) { // The SI libraries are not required for USB2, so attempt to connect first and only throw an // exception if this fails. int ret = ANT_Init(USBDeviceNum, baudRate, ref unmanagedANTSerialPtr, ref unmanagedANTFramerPtr, (byte)portType, (byte)frameType); if (ret != 0) { switch(ret) { case -1: throw new ANT_Exception("Unexpected init library error. This is typically a problem with the c++ library"); case -2: throw new ANT_Exception("Unrecognized type parameters"); case -3: if (!calledByAutoInit) //Auto-init checks only after checking all devices ANT_Common.checkUSBLibraries(); // throws exception if libraries are missing throw new ANT_Exception("Unable to initialize USB:" + USBDeviceNum + " at Baud:" + baudRate + ", probably device not present or already in use, or drivers not installed"); default: throw new ANT_Exception("Unrecognized error code received from c++ library"); } } initializedUSB = true; //Keep track of whether device is connected or not this.USBDeviceNum = USBDeviceNum; //Keep the parameters for reference this.USBBaudRate = baudRate; this.frameType = frameType; this.portType = portType; #if (ANTFS_DEBUGGING) //This logging is used in the ANT-FS libraries. Will not create any files if logging not enabled ANT_Common.initDebugLogThread("Device" + USBDeviceNum + "_Application"); ANT_Common.ANT_DebugResetTime(); ANT_Common.writeToDebugLog("ANT_NET.DLL " + ANT_VersionInfo.getManagedLibraryVersion() + " with ANT_WrappedLib.DLL " + ANT_VersionInfo.getUnmanagedLibraryVersion()); #endif try { responsePoller = new System.Threading.Thread(responsePollFunc); responsePoller.Name = this.ToString() + " Receive Thread"; responsePoller.IsBackground = true; //Make this a background thread so it will terminate when a program closes responsePoller.Start(); //Get capabilities so we know how many channels we have //If this throws an exception it is probably connected at the wrong baud rate, so we send a descriptive exception try { getDeviceCapabilities(true, 200); } catch (ANT_Exception ex) { throw new ANT_Exception(ex.Message.Remove(0, 22) + ", probably connecting at wrong baud rate"); } if(ANT_Common.autoResetIsEnabled) ANT_ResetSystem(unmanagedANTFramerPtr, 200); //Send a reset so by the time the user gets this handle the device is viable numDeviceChannels = capabilities.maxANTChannels; // Set up the channel list to the right size antChannels = new ANT_Channel[numDeviceChannels]; unmanagedCancelBool = Marshal.AllocHGlobal(4); cancelTxFlag = false; ANT_SetCancelParameter(unmanagedANTFramerPtr, unmanagedCancelBool); } catch (Exception) // clean up { shutdown(); throw; //Forward the error to caller } }
/// <summary> /// Assign an ANT channel, using extended channel assignment /// Throws exception if the network number is invalid. /// </summary> /// <param name="channelTypeByte">Channel Type byte</param> /// <param name="networkNumber">Network to assign to channel, must be less than device's max netwoks - 1</param> /// <param name="extAssignByte">Extended assignment byte</param> public void assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte) { assignChannelExt(channelTypeByte, networkNumber, extAssignByte, 0); }
/// <summary> /// Configure advanced bursting for this device including extended parameters. /// </summary> /// <param name="enable">Whether to enable advanced bursting messages</param> /// <param name="maxPacketLength">Maximum packet length allowed for bursting messages (valid values are 1-3)</param> /// <param name="requiredFields">Features that the application requires the device to use</param> /// <param name="optionalFields">Features that the device should use if it supports them</param> /// <param name="stallCount">Maximum number of burst periods (~3.1ms) to stall for while waiting for the next message</param> /// <param name="retryCount">Number of times (multiplied by 5) to retry burst</param> /// <param name="responseWaitTime">Time to wait for device success response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool configureAdvancedBursting_ext(bool enable, byte maxPacketLength, ANT_ReferenceLibrary.AdcancedBurstConfigFlags requiredFields, ANT_ReferenceLibrary.AdcancedBurstConfigFlags optionalFields, UInt16 stallCount, byte retryCount, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return (ANT_ConfigureAdvancedBurst_ext(unmanagedANTFramerPtr, (enable ? 1 : 0), maxPacketLength, (UInt32)requiredFields, (UInt32)optionalFields, stallCount, retryCount, responseWaitTime) == 1); }
/// <overloads>Sets the channel transmission power</overloads> /// <summary> /// Set the transmission power of this channel /// Throws exception if device is not capable of per-channel transmit power. /// </summary> /// <param name="transmitPower">Transmission power to set to</param> /// <param name="responseWaitTime">Time to wait for device success response</param> /// <returns>True on success. Note: Always returns true with a response time of 0</returns> public bool setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower, UInt32 responseWaitTime) { if (disposed) throw new ObjectDisposedException("This ANTChannel object has been disposed"); if (!creatingDevice.getDeviceCapabilities().perChannelTransmitPower) throw new ANT_Exception("Device not capable of per-channel transmit power"); return (ANT_SetChannelTxPower(unmanagedANTFramerPointer, channelNumber, (byte)transmitPower, responseWaitTime) == 1); }
/// <overloads>Requests a message from the device</overloads> /// <summary> /// Request a message from device /// </summary> /// <param name="channelNum">Channel to send request on</param> /// <param name="messageID">Request to send</param> public void requestMessage(byte channelNum, ANT_ReferenceLibrary.RequestMessageID messageID) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); ANTMessageItem dummystruct = new ANTMessageItem(); ANT_RequestMessage(unmanagedANTFramerPtr, channelNum, (byte)messageID, ref dummystruct, 0); }
/// <summary> /// Set the transmission power of this channel /// </summary> /// <param name="transmitPower">Transmission power to set to</param> public void setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower) { setChannelTransmitPower(transmitPower, 0); }
/// <overloads>Requests a message from the device and returns the response</overloads> /// <summary> /// Request a message from device and returns the response. /// Throws exception on timeout. /// </summary> /// <param name="channelNum">Channel to send request on</param> /// <param name="messageID">Request to send</param> /// <param name="responseWaitTime">Time to wait for device success response</param> public ANT_Response requestMessageAndResponse(byte channelNum, ANT_ReferenceLibrary.RequestMessageID messageID, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); ANTMessageItem response = new ANTMessageItem(); if (ANT_RequestMessage(unmanagedANTFramerPtr, channelNum, (byte)messageID, ref response, responseWaitTime) == 0) throw new ANT_Exception("Timed out waiting for requested message"); ANT_Response retVal = new ANT_Response(this, channelNum, DateTime.Now, response.antMsgData.msgID, response.antMsgData.ucharBuf.Take(response.dataSize).ToArray()); return retVal; }
public bool encryptedChannelEnable(ANT_ReferenceLibrary.EncryptedChannelMode encryptionMode, byte volatileKeyIndex, byte decimationRate, UInt32 responseWaitTime) { if (disposed) throw new ObjectDisposedException("This ANTChannel object has been disposed"); return ANT_EncryptedChannelEnable(unmanagedANTFramerPointer, channelNumber, (byte)encryptionMode, volatileKeyIndex, decimationRate, responseWaitTime) == 1; }
/// <overloads> /// Opens a connection to an ANT device attached by USB. /// Throws exception if a connection can not be established. /// </overloads> /// <summary> /// Attempts to open a connection to an ANT device attached by USB using the given deviceNum and baud rate /// Throws exception if a connection can not be established. /// </summary> /// <param name="portType">The type of connection to use when talking to the device</param> /// <param name="USBDeviceNum">If port type is USB, device number of the ANT USB device. /// If port type is COM this is the COM port number</param> /// <param name="baudRate">The baud rate to connect at (USB: AP2/AT3=57600, AP1=50000)</param> /// <param name="frameType">The framing method to use for the connection to the chip. /// Needed for multimode chips and currently only supported on COM connections.</param> public ANT_Device(ANT_ReferenceLibrary.PortType portType, byte USBDeviceNum, uint baudRate, ANT_ReferenceLibrary.FramerType frameType) { try { ANT_Common.checkUnmanagedLibrary(); // First check if the unmanaged library is there, otherwise, we cannot connect to ANT anyway startUp(USBDeviceNum, baudRate, frameType, portType, false); // Let exceptions propagate } catch { // If constructor throws an exception, release acquired resources and suppress finalization this.Dispose(); throw; } }
public void encryptedChannelEnable(ANT_ReferenceLibrary.EncryptedChannelMode encryptionMode, byte volatileKeyIndex, byte decimationRate) { encryptedChannelEnable(encryptionMode, volatileKeyIndex, decimationRate, 0); }
/// <summary> /// Configure the device ANT library, ie: to send extra msg info /// </summary> /// <param name="libConfigFlags">Config flags</param> public void setLibConfig(ANT_ReferenceLibrary.LibConfigFlags libConfigFlags) { setLibConfig(libConfigFlags, 0); }
public bool setCryptoInfo(ANT_ReferenceLibrary.EncryptionInfo encryptionParameter, byte[] parameterData, UInt32 responseWaitTime) { if (!initializedUSB) throw new ObjectDisposedException("ANTDevice object has been disposed"); return (ANT_SetCryptoInfo(unmanagedANTFramerPtr, (byte)encryptionParameter, parameterData, responseWaitTime) == 1); }