You are here: Forum Home → ANT Developers Forums → ANT General Questions → Thread
public partial class Form1 : Form
{
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_Init(byte Param1, UInt16 Param2);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_ResetSystem();
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_SetNetworkKey(byte Param1, byte[] Param2);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_AssignChannel(byte Param1, byte Param2, byte Param3);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_SetChannelId(byte Param1, byte Param2, byte Param3, byte Param4);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_SetChannelPeriod(byte Param1, UInt16 Param2);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_SetChannelRFFreq(byte Param1, byte Param2);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_OpenChannel(byte Param1);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_CloseChannel(byte Param1);
[DllImport("ANT_DLL.dll")]
public static extern bool ANT_SendBroadcastData(byte Param1, byte[] Param2);
public delegate bool CHANNEL_EVENT_FUNC(byte ucChannel, byte ucEvent);
[DllImport("ANT_DLL.dll")]
public static extern void ANT_AssignChannelEventFunction(byte ucChannel, CHANNEL_EVENT_FUNC pfChannelEvent, byte[] pucRxBuffer);
private CHANNEL_EVENT_FUNC iChannelEventFunction;
public byte[] aucRxBuf = new byte[17];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (ANT_Init(0, 57600) != true) { return; }
if (ANT_ResetSystem() != true) { return; }
//C [42][00][00][00] // Assign Channel Slave on ANT chanel 0 on network 0
byte[] garminheartstrapnetworkkey = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
if (ANT_SetNetworkKey(0, garminheartstrapnetworkkey) != true) { return; }
if (ANT_AssignChannel(0, 0x00, 0) != true) { return; }
//C [51][00][31][00][01][01] // Assign Channel ID 0, Dev. Num = 49, Dev. Type = 1, Trans. Type = 1
if (ANT_SetChannelId(0, 49, 1, 1) != true) { return; }
//C [43][00][00][80] // Set ANT Channel 0 Message Period to 1.00 Hz
if (ANT_SetChannelPeriod(0, 8192) != true) { return; }
//C [45][00][42] // Set ANT Channel 0 RF Frequency to 2466 MHz
if (ANT_SetChannelRFFreq(0, 66) != true) { return; }
//C [4B][00] // Open ANT chanel 0
if (ANT_OpenChannel(0x00) != true) { return; }
//E // End Sector
iChannelEventFunction = new CHANNEL_EVENT_FUNC(Slave2.Form1.ChannelEventFunction);
ANT_AssignChannelEventFunction(0, iChannelEventFunction, aucRxBuf);
}
catch
{
Debug.WriteLine("Fehler", e);
}
}
public static bool ChannelEventFunction(byte ucChannel, byte ucEvent)
{
MessageBox.Show("OK");
Debug.WriteLine(ucChannel);
return true;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
ANT_CloseChannel(0x00);
}
catch
{
Debug.WriteLine("Fehler", e);
}
}
private void button2_Click(object sender, EventArgs e)
{
byte[] b = { 1, 2, 3 };
ANT_SendBroadcastData(0, b);
}
}
}