Sample Application - C# or Java (HELP)

Post questions and issues with Concept2 PM3 SDK

Sample Application - C# or Java (HELP)

Postby y0rk1e » May 14th, 2011, 2:55 pm

I am wondering if somone has a sample application written in C# or Java which is able to detect a PM3 and send a single command to it. If somone would be kind enough to get me started then I am sure I will be able to move forward with what I am trying to achieve.

I am new to this interfacing with a device and have never written anything even remotely similar. Any advice or code snippets would be great.

I am running Windows 7 with VS2008 and 2010 for C# development and most of my Java work is done in Eclipse.

Thanks in advance
y0rk1e
Paddler
 
Posts: 8
Joined: May 14th, 2011, 9:56 am

Re: Sample Application - C# or Java (HELP)

Postby Citroen » May 14th, 2011, 5:39 pm

User avatar
Citroen
SpamTeam
 
Posts: 4991
Joined: March 16th, 2006, 3:28 pm
Location: Basingstoke, UK

Re: Sample Application - C# or Java (HELP)

Postby y0rk1e » May 15th, 2011, 3:32 pm

Thanks for the two links. The second looks promising, I will post any progress I make.

If there are any other resources that you come across, feel free to continue posting the links.
y0rk1e
Paddler
 
Posts: 8
Joined: May 14th, 2011, 9:56 am

Re: Sample Application - C# or Java (HELP)

Postby y0rk1e » May 15th, 2011, 5:59 pm

Well, after having read through the code, and set up a new VS2008 project, I have manged to get connected to the PM3 and get stroke by stroke informaton returned to the computer. I will be working more on this over the coming weeks and will post my progress.
y0rk1e
Paddler
 
Posts: 8
Joined: May 14th, 2011, 9:56 am

Re: Sample Application - C# or Java (HELP)

Postby y0rk1e » March 18th, 2013, 10:10 am

Hi,

Its been some time since I last posted, just to provide an update to this thread I successfully created a C# application which allows concept two rowing machines to race each other over the internet.

It allows for rowers to create different configured races which gets hosted in a race listing.
Other rowers logged in online are then able to see races that are soon to start and are able to join a race, which takes them to a race lobby where they can see who is taking part in the race.

Once everyone has marked themselves as ready the online server sends down the race configuration (ie: 2km, 10km), gives all the rowers a pre configured warmup time (5mins, 10min, etc) and the race starts as soon as warmup has finished.

The rowers can see the rowing statistics of the top 3 rowers in the race, as well as a top down graphical representation of the race to see the position of all boats, similare to the pace boat view on the PM3.

Regards

Chris
y0rk1e
Paddler
 
Posts: 8
Joined: May 14th, 2011, 9:56 am

Re: Sample Application - C# or Java (HELP)

Postby kdahlhaus » March 18th, 2013, 6:39 pm

Chris,

That sounds cool. Are you going to post some screen shots?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://powertwenty.com
'Do' or 'Do not', there is no 'Try' -Yoda
User avatar
kdahlhaus
500m Poster
 
Posts: 92
Joined: September 17th, 2006, 2:13 pm

Re: Sample Application - C# or Java (HELP)

Postby enki » March 25th, 2013, 12:31 pm

I'd be interested in y0rk1e's app too.

In trying to understand the c# code it seems like based on the code on theonlineoasis, it seems like the PMI is used as the way to connect to the rower including getting the number of rowers connected and then send commands to the rower which is an array of bytes with the data for the command following the command. (so it does all the wrapping like the start and stop flags, checksums, etc) A command is a single byte and the input data can be zero or more bytes. Information on what commands are available and how to interpret them is in Concept2 PM Communication Interface Definition 014.pdf in the SDK. Those assumptions correct?

I'm confused by "Update rate" in the document. Seems like the only way to get data out of the PM3/4 is to send a command asking for it and waiting for the response (i.e the PM3/4 never just sends the data on its own like an event) So does that mean that that is the rate that the value may change so its more to inform that polling something with an update rate of 1 Hz as a rate greater then 1Hz is pointless? Or is there a way to say "I want this data, please keep sending it to me" that just wasn't exposed in that sample c# code?

When it says "PM3 Specific Commands" what does that mean? Is that just an extension from the generic csafe commands? Do they also work on the PM4? (don't have a PM4 to test with)

The documentation seems to say the maximum frame length is 96 Bytes. I'm assuming that is the input size limit, not output? You can string commands together as long as the commands and their data all fit into the input array.

If I send a bad command and get the rower into a state I'm not sure about, I only have to unplug the battery and plug it back in to reset it?

The Ant protocol used by the PM4 isn't public information? (ok, still don't have a PM4 but I'm already using an Ant+ stick to get HR data as I want r-r info that I can't get from the rower, so this is more for future thinking)

No one has defined how the data from a rowing session should be saved in a FIT file yet? I understand using subsport "indoor_rowing" under "Fitness Equipment" and SPM goes under cadence, but don't see where drag factor is stored. Should it be stored as a possibly continuously changing data point as it's updated per stroke,once per row, or not at all? (doesn't seem like rowpro saves it) How about if you are using slides or not? (want to avoid creating my own way of formatting a FIT file if there is some existing standard)

Thanks,
Eli
enki
Paddler
 
Posts: 12
Joined: January 2nd, 2013, 12:55 pm

Re: Sample Application - C# or Java (HELP)

Postby bb07 » April 16th, 2013, 6:57 am

Hi guys,

I've tried implementing a C# app in VS2012 Express using the code from the following url:
http://www.theonlineoasis.co.uk/projects/erg.html

Initially I tried using RPPM3DDI.dll and RPPM3Csafe.dll as specified in the code but I got the following exception"An unhandled exception of type 'System.Runtime.InteropServices.SEHException' ".

So I then tried using the PM3DDICP.dll and PM3CsafeCP.dll and it discovers the PM3 ok, but in HighResolutionUpdate() the following line always returns an error code of 65370 which doesn't appear anywhere in the documentation:

Code: Select all
ushort ecode = USBErgInterfaceWrapper.tkcmdsetCSAFE_command(this.performanceMonitor.deviceNumber, cmd_data_size, cmd_data, ref rsp_data_size, rsp_data);


Any ideas would be really appreciated.

Thanks,
Brad.
bb07
Paddler
 
Posts: 2
Joined: April 16th, 2013, 6:09 am

Re: Sample Application - C# or Java (HELP)

Postby haboustak » April 16th, 2013, 4:39 pm

The C# code that tends to circulate always imports ERRCODE_T as an unsigned 16-bit integer (ushort), but in the C headers it's always been defined as a normal signed short. Two's complement of 65370 results in the actual error value of -166. I'm not sure if the error codes are documented well in the SDK or not, but it will be harder to identify them with a ushort value.

The sample code you linked to initializes rsp_data_size to 0. I've always initialized rsp_data_size to the size of the allocated buffer and I've always used 120 bytes, which is the largest size USB report available from page 22 of the docs.

Here's another topic about the 166 error.
viewtopic.php?f=15&t=7651
haboustak
500m Poster
 
Posts: 77
Joined: March 17th, 2006, 3:02 pm
Location: Cincinnati

Re: Sample Application - C# or Java (HELP)

Postby bb07 » April 17th, 2013, 7:32 am

haboustak wrote:The C# code that tends to circulate always imports ERRCODE_T as an unsigned 16-bit integer (ushort), but in the C headers it's always been defined as a normal signed short. Two's complement of 65370 results in the actual error value of -166. I'm not sure if the error codes are documented well in the SDK or not, but it will be harder to identify them with a ushort value.

The sample code you linked to initializes rsp_data_size to 0. I've always initialized rsp_data_size to the size of the allocated buffer and I've always used 120 bytes, which is the largest size USB report available from page 22 of the docs.

Here's another topic about the 166 error.
viewtopic.php?f=15&t=7651


You're a genius. Changing the ushort's to just "short" in the DLL import references and setting rsp_data_size = 120 in both LowResolutionUpdate() and HighResolutionUpdate() did the trick!! I never would have worked that out in a million years...

Code: Select all
[DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern short tkcmdsetDDI_init();

        [DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern short tkcmdsetDDI_discover_pm3s(
           string product_name,
           ushort starting_address,
           ref ushort num_units);

        [DllImport("PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern short tkcmdsetCSAFE_init_protocol(ushort timeout);

        [DllImport("PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern short tkcmdsetCSAFE_command(
           ushort unit_address,
           ushort cmd_data_size,
           uint[] cmd_data,
           ref ushort rsp_data_size,
           uint[] rsp_data);


Thanks, I really appreciate your help!
bb07
Paddler
 
Posts: 2
Joined: April 16th, 2013, 6:09 am

Re: Sample Application - C# or Java (HELP)

Postby fisk » February 1st, 2017, 8:50 am

Hi.
Is it possible for anyone to upload the project on http://www.theonlineoasis.co.uk, a C# project using the concept2sdk or anything similar.
Im in the same possition as bb07 were, and just need a little help to get started.

Thanks.
Best regards
A Danish rower
fisk
Paddler
 
Posts: 2
Joined: February 1st, 2017, 8:47 am


Return to SDK Questions

Who is online

Users browsing this forum: No registered users and 1 guest