Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

You are here: Forum Home → ANT+ Forums → ANT+ Heart Rate Monitor → Thread

   

What is the right code to receive HRM data from simulator

Rank

Total Posts: 2

Joined 2013-05-25

PM

Hi All,

I am a newbie to the ANT+ development. I am studying the code for the NET example and I have a simple goal. That is to receive the data from the Ant+ Sensor Simulator and to Send data that can be received by the Ant+ Display simulator.

Beginning with the program that receives HRM data from Ant+ Sensor Simulator , I have the code below. I got stuck as to what is the right code to tell the sensor to start receiving the messages. A code similar to:

device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);

Can someone point me to the right direction?

Here the code that I used
static void InitSlaveHRM()
        
{
             
                byte USER_ANT_CHANNEL 
0;         // ANT Channel to use
                
byte[] USER_NETWORK_KEY { 00000000 };
                
byte USER_RADIOFREQ 57;          // RF Frequency + 2400 MHz
                
byte USER_TRANSTYPE 0;           // Pairing
                
byte USER_DEVICETYPE 120;          // Device type
                
ushort USER_DEVICENUM 100;        // Device number    
                
ushort USER_CHANNELPERIOD 8070;  // Channel Period (8192/32768)s period = 4Hz
 
                
byte USER_NETWORK_NUM 0;         // The network key is assigned to this network number

               
device0 = new ANT_Device();
               
device0.setNetworkKey(USER_NETWORK_NUMUSER_NETWORK_KEY500);

                
channel0 device0.getChannel(0);
                
                
// Set the channel to receive using the current network number
                
if (channel0.assignChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00USER_NETWORK_NUM0))
                    
Console.WriteLine("Channel assigned.");
                else
                    
Console.WriteLine("Error: Channel not assigned.");
                    
                   
// id=100, non-pairing, device type, transmission type (HRM), delay                
                
if (channel0.setChannelID(USER_DEVICENUMfalseUSER_DEVICETYPEUSER_TRANSTYPE500))
                    
Console.WriteLine("Channel id assigned.");
                else
                    
Console.WriteLine("Error: Channel id not assigned.");

                if (
channel0.setChannelPeriod(USER_CHANNELPERIOD,500))                
                    
Console.WriteLine("Channel period id set.");
                else
                    
Console.WriteLine("Error: Channel period not set.");

                if (
channel0.setChannelFreq(USER_RADIOFREQ500))
                    
Console.WriteLine("Radio frequency set.");
                else
                    
Console.WriteLine("Error: Radio frequency not set.");

                if (
channel0.openChannel(500))
                    
Console.WriteLine("Channel opened.");
                else
                    
Console.WriteLine("Error: Channel not opened.");


                
// Message Handler Assignment
                
device0.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
                
channel0.channelResponse += new dChannelResponseHandler(ChannelResponse);
            
                
// Request some action here
                
device0.requestMessage(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E);                    
                
            
/*
    ??? What is the right code to read from the Ant+ Sensor Simulator for Heart Rate Monitor (HRM)?
    
                ANT_Response respChID = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);
                ushort usDeviceNumber = (ushort)((respChID.messageContents[2] << 8) + respChID.messageContents[1]);
                byte ucDeviceType = respChID.messageContents[3];                 byte ucTransmissi
                Console.WriteLine("CHANNEL ID: (" + usDeviceNumber.ToString() + "," + ucDeviceType.ToString() + "," + ucTransmissionType.ToString() + ")");

             */

                
Console.ReadLine();

                
Console.WriteLine("Disconnecting module...");
                
ANT_Device.shutdownDeviceInstance(ref device0);

                
        
     
RankRankRankRank

Total Posts: 156

Joined 2013-01-07

PM

Hi,

Could you clarify what you mean by: "I got stuck as to what is the right code to tell the sensor to start receiving the messages". In the HRM use case the communication is unidirectional and the sensor simulator will start transmitting automatically once it is turned on.

Are you referring to the display?

Refer to the ANT+ Heart Rate Monitor device profile (http://www.thisisant.com/resources/heart-rate-monitor/) for the message formats for ANT+ HRMs.

We also have the source code (C++) for our older ANT+ simulators avilable for download:(http://www.thisisant.com/developer/resources/downloads/#software_tab) the HRMDisplay.cpp file in this project would be a good reference on decoding ANT+ HRM messages.      
Rank

Total Posts: 2

Joined 2013-05-25

PM

usamak, thank you for the response.

What I need is the sample code containing the method to use how to set the USB simulator to receive the data from the HRM simulator using Ant+ Sensor application.

As you can see in my the code above, the device is initialized but I am not successful when I use
device0.requestMessage(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E); 
code. So basically, this request is asking for the "version", but what is the ID to use to just receive the data that is being passed by the HRM simulator?

I am not well versed in C++ and I am looking to use C# for this project. Any help is much appreciated.      
RankRankRankRank

Total Posts: 156

Joined 2013-01-07

PM

The received broadcast messages are accessed using the channel0 object, refer to demo.cs of the DEMO_NET project in the ANT_NET_Libraries for a code reference (check the ChannelResponse() method definition). I also recommend reading section 9.5.5.1 of ANT Message Protocol and Usage document (http://www.thisisant.com/resources/ant-message-protocol-and-usage/) for information on how to handle received ANT messages.

     
RankRankRankRank

Total Posts: 156

Joined 2013-01-07

PM

Also, I noticed you are using a network key of 0-0-0-0-0-0-0-0. To pair with ANT+ devices you would need to to use the ANT+ network key which can be found here: http://www.thisisant.com/developer/ant-plus/ant-plus-basics/network-keys (Note.: Please do not post any of these managed network keys in the forum)