Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

ANT_AssignChannelEventFunction - callback does not work

RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

hello,

i have a problem with the ANT_AssignChannelEventFunction function (using c#).
the callback to my function ChannelEventFunction does not work.

i hope that anyone can tell me whats wrong with my code.

the functioncalls before and the broadcast are working correctly.

public partial class Form1 Form
    {


        [DllImport
("ANT_DLL.dll")]
        
public static extern bool ANT_Init(byte Param1UInt16 Param2);
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_ResetSystem();
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_SetNetworkKey(byte Param1byte[] Param2);
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_AssignChannel(byte Param1byte Param2byte Param3);
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_SetChannelId(byte Param1byte Param2byte Param3byte Param4);
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_SetChannelPeriod(byte Param1UInt16 Param2);
        
[DllImport("ANT_DLL.dll")]
        
public static extern bool ANT_SetChannelRFFreq(byte Param1byte 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 Param1byte[] Param2);


        public 
delegate bool CHANNEL_EVENT_FUNC(byte ucChannelbyte ucEvent);
        
[DllImport("ANT_DLL.dll")]
        
public static extern void ANT_AssignChannelEventFunction(byte ucChannelCHANNEL_EVENT_FUNC pfChannelEventbyte[] pucRxBuffer);
        private 
CHANNEL_EVENT_FUNC iChannelEventFunction;
        public 
byte[] aucRxBuf = new byte[17];

        public 
Form1()
        
{
            InitializeComponent
();
        
}

        
private void button1_Click(object senderEventArgs e)
        
{
            
try
            
{
                
if (ANT_Init(057600) != truereturn; }

                
if (ANT_ResetSystem() != truereturn; }

                
//C [42][00][00][00]     // Assign Channel Slave on ANT chanel 0 on network 0
                
byte[] garminheartstrapnetworkkey { 0x010x020x030x040x050x060x070x08 };
                if (
ANT_SetNetworkKey(0garminheartstrapnetworkkey) != truereturn; }

                
if (ANT_AssignChannel(00x000) != truereturn; }
                
//C [51][00][31][00][01][01]     // Assign Channel ID 0, Dev. Num = 49, Dev. Type = 1, Trans. Type = 1
                
if (ANT_SetChannelId(04911) != truereturn; }
                
//C [43][00][00][80]     // Set ANT Channel 0 Message Period to  1.00 Hz
                
if (ANT_SetChannelPeriod(08192) != truereturn; }
                
//C [45][00][42]     // Set ANT Channel 0 RF Frequency to 2466 MHz
                
if (ANT_SetChannelRFFreq(066) != truereturn; }
                
//C [4B][00]     // Open ANT chanel 0
                
if (ANT_OpenChannel(0x00) != truereturn; }
                
//E      // End Sector

                
iChannelEventFunction = new CHANNEL_EVENT_FUNC(Slave2.Form1.ChannelEventFunction);
                
ANT_AssignChannelEventFunction(0iChannelEventFunctionaucRxBuf);

            
}
            
catch
            
{
                Debug
.WriteLine("Fehler"e);
            
}
        }

        
public static bool ChannelEventFunction(byte ucChannelbyte ucEvent)
        
{

            MessageBox
.Show("OK");
            
Debug.WriteLine(ucChannel);

            return 
true;
        
}

        
private void Form1_FormClosed(object senderFormClosedEventArgs e)
        
{
            
try
            
{
                ANT_CloseChannel
(0x00);
            
}
            
catch
            
{
                Debug
.WriteLine("Fehler"e);
            
}
        }

        
private void button2_Click(object senderEventArgs e)
        
{
            byte[] b 
{ 123 };
            
ANT_SendBroadcastData(0b);
        
}
    }
     
Avatar
RankRankRankRank

Total Posts: 662

Joined 2012-10-09

PM

The ANT DLL is unmanaged code, and can not be imported directly into the .NET environment. We will be releasing soon a Managed DLL that takes care of all the marshaling needed to integrate the unmanaged code into the .NET managed environment.