Hi!
I’m new here, but I’ve a problem which was maybe discussed a couple of times, but still wasn’t answered properly. At least I wasn’t able to find a suitable solution in the topics I got from using the search engine. Therefore I’m really sorry if this is an unnessary post.
Here is the thing:
I’m new to the ANT protocol and I’m trying to establish a very simple ANT connection between the Nordic USB ANT Stick (http://www.sparkfun.com/commerce/produc … ts_id=8840) and the Garmin Hearth Rate Monitor in C++/MFC using Microsoft Visual Studio 2008. I found the ant_dll.cpp, ant_dll.h and the ant_dll.dll on the http://www.thisisant.com site and managed to include them successfully into my project, so that I can compile the code.
Unfortunately nothing exciting happens from there. The “ProcessProtocolEvent” and “ProcessChannelEvent” routines (see code below) are never executed, that means there is no messaging happening between the USB stick and the HRM. To be honest I’m not quite sure, if the stick is installed properly, because it doesn’t appear in the device manager as “USB ANT Stick” in the “USB controllers” section, but instead appearas as “Unknown device” without attached drivers. I contacted the support from thisisant.com, but I only got this answer: “The USB stick you are using is designed by Sparkfun, uses different hardware than the Dynastream USB sticks and interface boards, and thus, is not compatible with our drivers.”. So maybe that’s the problem, that the stick is not installed properly, because I don’t have the right drivers. On the sparkfun product site of the stick it says that you need the FTDI driver and everything should work. I have these drivers and they are working fine. After plugging in, the “USB Serial Port” and the “USB Serial Converter” were installed. I tried the “Example VB Program for Garmin HRMs”, but the only thing working is the “Open” button, which opens the channel and acknowledges that by displaying “open” I think. But when I press the big button, which says “Check Heart Rate”, I get a couple of error popup messages saying bad parameters. I know that this problem was discussed in another topic, but there was not real solution given, except that someone mentioned that he could solve it without telling exactly how.
Here is the important part of the code:
...
#include "antdefines.h"
#include "antmessage.h"
#include "global.h"
#include "types.h"
#include "ant_dll.h"
#define ANT_CHANNEL ((UCHAR) 7) // My virtual COM port is 7
static UCHAR GARMIN_KEY[] = "...";
static UCHAR aucTxBuf[17]; ///< Buffer to hold messages that are sent to the ANT device
static UCHAR aucRxBuf[17]; ///< Buffer to hold channel specific RF messages and events received from the ANT device
static UCHAR aucResponseBuf[10]; ///< Buffer to hold the response to configuration commands
// CGarminHRMDlg message handlers
UCHAR ProcessChannelEvent(UCHAR ucChannel, UCHAR ucMessageCode)
{
switch(ucMessageCode)
{
case EVENT_RX_ACKNOWLEDGED:
break;
case EVENT_RX_BROADCAST: // A Broadcast message has been received sucessfully
break;
case EVENT_TX:
break;
case EVENT_TRANSFER_TX_COMPLETED: // A Acknowledged packet was sucessfully sent
break;
case EVENT_RX_FAIL_GO_TO_SEARCH: // If we ever go back to search we fail the test
break;
case EVENT_RX_SEARCH_TIMEOUT: // If we timeout on the search we faile the test
break;
case EVENT_RX_FAIL: // We failed to receive a message at the designated message period
break;
case EVENT_TRANSFER_TX_FAILED: // We failed to get a reply for the acknowledged packet we sent
break;
case EVENT_CHANNEL_CLOSED:
break;
}
return 1;
}
UCHAR ProcessProtocolEvent(UCHAR ucChannel, UCHAR ucMessageCode)
{
switch(ucMessageCode)
{
case MESG_CAPABILITIES_ID:
break;
case MESG_RESPONSE_EVENT_ID:
{
switch (aucResponseBuf[1])
{
case MESG_ASSIGN_CHANNEL_ID:
break;
case MESG_UNASSIGN_CHANNEL_ID:
break;
case MESG_CHANNEL_ID_ID:
break;
case MESG_CHANNEL_MESG_PERIOD_ID:
break;
case MESG_CHANNEL_RADIO_FREQ_ID:
break;
case MESG_OPEN_CHANNEL_ID:
break;
case MESG_CLOSE_CHANNEL_ID:
break;
case MESG_CHANNEL_SEARCH_TIMEOUT_ID:
default:
break;
}
break;
}
}
return 1;
}
BOOL CGarminHRMDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ANT_Load();
ANT_ResetSystem();
Sleep(20);
ANT_Init(ANT_CHANNEL, 4800);
ANT_AssignResponseFunction( (RESPONSE_FUNC)ProcessProtocolEvent, aucResponseBuf );
ANT_AssignChannelEventFunction( ANT_CHANNEL, (CHANNEL_EVENT_FUNC)ProcessChannelEvent, aucRxBuf );
// Trying to get a message
ANT_RequestMessage(ANT_CHANNEL, MESG_CHANNEL_ID_ID);
return TRUE;
}
void CGarminHRMDlg::OnBnClickedOpen()
{
// Rx channel
ANT_AssignChannel(ANT_CHANNEL, 0x00, 0);
Sleep(20);
// Using the Garmin parameters
ANT_SetChannelId(ANT_CHANNEL, 0, 0, 0);
Sleep(20);
ANT_SetNetworkKey(ANT_CHANNEL, GARMIN_KEY);
Sleep(20);
ANT_SetChannelSearchTimeout(ANT_CHANNEL, 255);
Sleep(20);
ANT_SetChannelPeriod(ANT_CHANNEL, 0x1f86);
Sleep(20);
ANT_SetChannelRFFreq(ANT_CHANNEL, 0x39);
Sleep(20);
ANT_OpenChannel(ANT_CHANNEL);
Sleep(1000);
// Again trying to get a message
ANT_RequestMessage(0,MESG_CAPABILITIES_ID);
}
void CGarminHRMDlg::OnClose()
{
ANT_CloseChannel(ANT_CHANNEL);
ANT_Close();
CDialog::OnClose();
}
void CGarminHRMDlg::OnCancel()
{
ANT_CloseChannel(ANT_CHANNEL);
ANT_Close();
CDialog::OnCancel();
}
It is a simple dialog-based application using MFC and the ANT commands are linked dynamicly using “GetProcAddress”. I have an “Open” button which calls the “OnBnClickedOpen” routine which should establish a connection. I have looked at many examples and they basicly look the same. But please correct me if I did something wrong. I trying for two days now to get that thing working and I’m quite desperate now. Actually right now it would be enough for me already, if I just manage receiving messages in my “ProcessChannelEvent” routine, meaning just establishing a basic connection without data processing.
As I said I’m quite helpless right now, because I don’t know if at least the stick it self is working, because none of the examples is working quite well. So please help me. :roll:
[Admin edit: ANT asked us to remove the Garmin key.]