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

   

VB.NET ANT+ USB Read HR

Rank

Total Posts: 6

Joined 2013-10-08

PM

Hello vb.ne use to read your heart rate with ant-usb (GARMIN) and range (Garmin). Using this code, you connect na not read the heartbeat, I'm new to VB.NET, someone could correct the code?Thanks to all for the help.

sorry for the bad english

Rino.


Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports ANT_Managed_Library

Namespace ANT__Sample_Application
Friend Class Program
Private Shared device As ANT_Device
'Private Shared ReadOnly networkKey() As Byte = {&H0;, &H0;, &H0;, &H0;, &H0;, &H0;, &H0;, &H0;}
Private Shared ReadOnly networkKey() As Byte = {0, 0, 0, 0, 0, 0, 0, 0}
Private Shared ReadOnly deviceType As Byte = 120 ' Device type
Private Shared transType As Byte = 0 ' Transmission type

Private Shared ReadOnly radioFreq As Byte = 57 ' RF Frequency + 2400 MHz
Private Shared ReadOnly channelPeriod As UShort = 8070 ' Message period possible values 8070 = 4.06 Hz, 16140 = 2.03Hz, 32280 = 1.02Hz
Private Shared channelType As ANT_ReferenceLibrary.ChannelType = ANT_ReferenceLibrary.ChannelType.BASE_Master_Transmit_0x10

Private Shared lastRunNo As Integer = 0

Public Shared Sub Main(ByVal args() As String)
Console.WriteLine("Connecting to HRM, PRESS ENTER TO TERMINATE PROGRAM")

device = New ANT_Device()
device.setNetworkKey(0, networkKey, 500)

Dim Channel As ANT_Channel = device.getChannel(0)
Channel.assignChannel(channelType, 0, 500)
Channel.setChannelID(0, False, deviceType, transType, 500)
Channel.setChannelFreq(radioFreq, 500)
Channel.setChannelPeriod(channelPeriod, 500)
AddHandler Channel.channelResponse, AddressOf HandleHeartRateTest


Channel.setProximitySearch(3) ' Is set to limit the search range
Channel.openChannel(500)
Console.ReadLine()

Channel.closeChannel()
End Sub

Public Shared Sub HandleHeartRateTest(ByVal response As ANT_Response)
Select Case CType(response.responseID, ANT_ReferenceLibrary.ANTMessageID)

Case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E
Console.WriteLine("Message: ")
Case ANT_ReferenceLibrary.ANTMessageID.ACKNOWLEDGED_DATA_0x4F
Console.WriteLine("Message: ")

Case ANT_ReferenceLibrary.ANTMessageID.BURST_DATA_0x50


Case ANT_ReferenceLibrary.ANTMessageID.EVENT_0x01

Dim runNo As Integer = response.messageContents(7)
If runNo <> lastRunNo Then
lastRunNo = runNo
'Console.WriteLine("Message: " & BitConverter.ToString(response.messageContents))
Console.WriteLine(" Beat count: " & lastRunNo.ToString() & " HR: " & response.messageContents(8).ToString())
End If
Exit Select

Case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40
Console.WriteLine("Message: " & ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40)
Console.WriteLine(response.messageContents(8).ToString())

Case ANT_ReferenceLibrary.ANTMessageID.CHANNEL_MESG_PERIOD_0x43
Console.WriteLine("Message: 0x4F")
Case Else
Console.WriteLine("Message: 0x4F")
End Select
End Sub

End Class      

File Attachments

Avatar
RankRankRankRank

Total Posts: 235

Joined 2012-08-31

PM

Hi Rino,

I've moved this post to the ANT+ Heart Rate Forum - and you should find plenty more advice in this forum.

Sorry we can't debug code for you, as our support resources are limited.

Your channel parameters look right, so it could be worth checking the heart rate strap is active (the best way is to wear it and wet the sensors). The standard troubleshooting advice is here: http://www.thisisant.com/developer/resources/tech-faq/category/basic-troubleshooting/ - look at "why won't my devices connect".

Good luck!

Kat      
Rank

Total Posts: 1

Joined 2013-09-25

PM

Hi,

I don't know it you have already solved this but I used your code as a base to start of my application.

I got mine receiving from the ANT+ Sensor Simulator by altering the code in 2 places:

HR_channel.assignChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x000500);
            
//HR_channel.assignChannel(ANT_ReferenceLibrary.ChannelType.BASE_Master_Transmit_0x10, 0x00, 500); 


And also moving the if statement from the EVENT_0x01 case to the BROADCAST_DATA_0x4E case.

My app is C# WPF.

Hope this helps.
John      
Avatar
RankRankRankRank

Total Posts: 296

Joined 0

PM

Channel type ...MasterTransmit... for sure was nonsense - this would mean to open a channel that transmits, not one that receives. So this is a crucial improvement.      
Avatar
RankRankRankRank

Total Posts: 235

Joined 2012-08-31

PM

The ANT+ Sensor Simulator is designed to mimic ANT+ sensors, hence being set up as a master channel. You should find that the ANT+ Display simulator (contained in the same zip file) is already configured to receive from ANT+ Sensors and doesn't need modification.      
Rank

Total Posts: 5

Joined 2014-11-25

PM

Where is the channel number assigned?