Page 1 of 1

Sample Application - C# or Java (HELP)

Posted: May 14th, 2011, 2:55 pm
by y0rk1e
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

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

Posted: May 14th, 2011, 5:39 pm
by Citroen

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

Posted: May 15th, 2011, 3:32 pm
by y0rk1e
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.

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

Posted: May 15th, 2011, 5:59 pm
by y0rk1e
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.

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

Posted: March 18th, 2013, 10:10 am
by y0rk1e
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

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

Posted: March 18th, 2013, 6:39 pm
by kdahlhaus
Chris,

That sounds cool. Are you going to post some screen shots?

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

Posted: March 25th, 2013, 12:31 pm
by enki
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

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

Posted: April 16th, 2013, 6:57 am
by bb07
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.

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

Posted: April 16th, 2013, 4:39 pm
by haboustak
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.
http://www.c2forum.com/viewtopic.php?f=15&t=7651

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

Posted: April 17th, 2013, 7:32 am
by bb07
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.
http://www.c2forum.com/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!

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

Posted: February 1st, 2017, 8:50 am
by fisk
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