The problem with the error code [-166] does not seem to be a problem i think. the commands execute just fine with it.
I can now put the PM4 into the standard 2000m rowing program.
When I want to get the time the user is rowing, I simply send the command 0xA1
When done in the PMSDKDemo.exe, it returns the time. This is to prove that the functions works with my system and dll.
it returns:
Code: Select all
000000A0H 00000003H 00000000H 00000000H 00000009H
first the command that was send (a0), then the length of the responds (03), then the responds (00 00 09) the time in hours, minutes and seconds.
The Demo program adds the first 2 bytes (a0 and 03) to the displayed value, according to the documentation it should return 3 bytes of data.
In my own program I use the following to call a command to the dll:
Code: Select all
[DllImport("PM3CsafeCP", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?tkcmdsetCSAFE_command@@YAFGGQAKPAG0@Z")]
public static extern short tkcmdsetCSAFE_command(
ushort unit_address,
ushort cmd_data_size,
uint[] cmd_data,
ref ushort rsp_data_size,
uint[] rsp_data);
When i call this from another object, for instance to set the standard 2000m program I use the follwing:
(this is ofcourse done after initializing and discovering and setting the Csafe protocol)
Code: Select all
public void start_2000()
{
uint[] cmd_data = new uint[1];
ushort cmd_data_size;
uint[] rsp_data = new uint[64];
ushort rsp_data_size = 0;
cmd_data_size = 0;
// Reset.
cmd_data[cmd_data_size++] = 0x81;
Debug.Log("81 send");
Debug.Log(USBErgInterfaceWrapper.tkcmdsetCSAFE_command(0, cmd_data_size, cmd_data, ref rsp_data_size, rsp_data));
}
public void set_distance()
{
uint[] cmd_data = new uint[5];
ushort cmd_data_size;
uint[] rsp_data = new uint[64];
ushort rsp_data_size = 0;
cmd_data_size = 0;
cmd_data[cmd_data_size++] = 0x21;
cmd_data[cmd_data_size++] = 0x03;
cmd_data[cmd_data_size++] = 0x02;
cmd_data[cmd_data_size++] = 0x00;
cmd_data[cmd_data_size++] = 0x21;
Debug.Log("Set distance");
Debug.Log("data: " + cmd_data[0] + ":"+ cmd_data[1] + ":"+ cmd_data[2]);
Debug.Log(USBErgInterfaceWrapper.tkcmdsetCSAFE_command(0, cmd_data_size, cmd_data, ref rsp_data_size, rsp_data));
}
public void set_progam()
{
uint[] cmd_data = new uint[4];
ushort cmd_data_size;
uint[] rsp_data = new uint[64];
ushort rsp_data_size = 0;
cmd_data_size = 0;
cmd_data[cmd_data_size++] = 0x24;
cmd_data[cmd_data_size++] = 0x02;
cmd_data[cmd_data_size++] = 0x00;
cmd_data[cmd_data_size++] = 0x00;
Debug.Log("Set program");
Debug.Log(USBErgInterfaceWrapper.tkcmdsetCSAFE_command(0, cmd_data_size, cmd_data, ref rsp_data_size, rsp_data));
}
public void go_in_use()
{
uint[] cmd_data = new uint[1];
ushort cmd_data_size;
uint[] rsp_data = new uint[64];
ushort rsp_data_size = 0;
cmd_data_size = 0;
cmd_data[cmd_data_size++] = 0x85;
Debug.Log("go in use");
Debug.Log(USBErgInterfaceWrapper.tkcmdsetCSAFE_command(0, cmd_data_size, cmd_data, ref rsp_data_size, rsp_data));
}
This code seems to work, and sets the PM4 into the row 200 meter program. I splited the code into 4 functions, so I can easily call the whole routine, or just a piece of it.
I only log the errorcodes, because these call dont get any data back.
The error codes returned are [253], a code I can not seem to find in the Interface Definitons (unlike the former [-166])
I dont know what this error means, but all commands seem to come through.