Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Message receiver app (C#) using a USB stick on a PC

RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi,

I am developing a simple C# application to display messages which are received (at random time intervals) by the ANT USB stick connected to a PC.

Should I use continuous scanning mode since power is not an issue?

For now thats what my code does:

-> Initializes and tries to connect to any available ANT devices
device = new ANT_Device(); 


-> Selects the channel type...
channel ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00


-> Resets the system followed by delay

-> Can I now start listening for incoming messages using device.requestMessage(MessageID);
If so, what would be the message ID?
What is the difference between "requestMessage" and "requestMessageAndResponse"?

thanks for your time!      
RankRankRank

Total Posts: 95

Joined 2010-05-03

PM

Hi,

The first step into communicating with an ANT device is to establish an ANT channel. An ANT channel is established by configuring the following parameters:

- Setting the network key
- Assigning the channel
- Setting the channel ID
- Setting the channel frequency
- Setting the channel period
- Opening the channel

You can find the ANT command messages for setting the above parameters in section 9.3 "ANT Message Summary" of the "ANT Message Protocol and Usage" document.

One thing to note is that when the system is reset after configuring the channel, it would result in resetting the channel parameters as well. Therefore, there is no need to reset the system after configuring the channel.

Once the channel is open, the ANT device can then receive messages. Also, the ANT device notifies the application of messages received through channel event messages which should be handled by the application.

For more information about channel configuration and how messages are transmitted or received by an ANT device, please have a look at the "ANT_Library_Windows_Package" in the ANT website. This package has examples on how to open an ANT channel, receive and transmit messages.

As for the difference between "requestMessage" and "requestMessageAndResponse" commands is that with "requestMessageAndResponse" command, a response is returned. However, with "requestMessage" command, it is not necessary to have a response and if there is one then it is processed as a message from ANT that should also be handled by the application.      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi,

Thank you for your prompt reply.

I have dont the following coding...
void main()
{

             
//Initialization...
            
device0 = new ANT_Device();

           
//Set the network key
 
           //Assigned the channel

           //Set the channel ID

           //Set the channel frequency
           
channel0.setChannelFreq(057); //RF Freq + 2400MHz

           //Set the channel period
           
           //Opened the channel
           
channel0.openChannel(57);

            
//Assign callback function
            
channel0.channelResponse += new   ANT_Channel.ChannelResponseHandler(this.ChannelResponse);
      
}


//Called whenever a channel event is received
void ChannelResponse(ANT_Response newResponse)
        
{
                   StringBuilder stringToPrint
;   

           
//When something is received, display the ID and contents
            
stringToPrint = new StringBuilder("Received "100);
                
stringToPrint.AppendLine(((ANT_ReferenceLibrary.ANTMessageID)newResponse.responseID).ToString());

            
//Always print the raw contents in hex, with leading '::' for easy visibility/parsing
            
stringToPrint.Append("  :: ");
            
stringToPrint.Append(Convert.ToString(newResponse.responseID16));
            
stringToPrint.Append(", ");
            
stringToPrint.Append(BitConverter.ToString(newResponse.messageContents));

            
txtRcvdData.Text stringToPrint.ToString();




Please advise me....am I even on the right track?
It is pretty basic but how would we make so the program continuously monitor for any incoming data packets and display when needed.

For opening a channel...which one is correct....openChannel() OR openChannel(57)?

I believe I would be printing Hex format in above code....I woud like to print the actual content of the message. anyway...

please advise me. thanks!      
RankRankRank

Total Posts: 95

Joined 2010-05-03

PM

Hi,

You are on the right track. Just minor things that need to be fixed.

Overall your code is right; channel configuration and setting channel response handler are implemented almost correctly.

Notes on your code:

- Setting the channel response handler should be done before channel configuration

- The arguments for both "setChannelFreq" and "openChannel" functions are not correct

- "ChannelResponse" function needs to handle the different channel events received from ANT

I strongly recommend going through "DEMO_NET" project in "ANT_Library_Windows_Package". In this project you can find the following:

1) How channel response handler is set in "Init()" function

2) How to configure an ANT channel using ANT command messages with arguments set correctly in "Start" function

3) How to handle the different cases of channel events in "ChannelResponse" function; how to display incoming data packets...etc.



Good luck!      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Thanks for your input!

You mentioned that arguments for my "setChannelFreq" and "openChannel" are not correct. I went through the development guide and basically the arguments they used (though I will change them later on).

So basically ChannelResponse function would be responsible for displaying the rcvd messages..right?

I will go through the Demo_NET example.

Thanks for your help!