I have copied some of the code from another thread in this forum, and the important parts of my code are here:
Code: Select all
class Program {
static void Main(string[] args) {
Program prog = new Program();
Console.Title = "PM3 Test Program";
prog.wl("Running program 'PM3Test'...", true);
prog.runprog();
prog.wl("Closing...", true);
prog.wl("Press [Enter] to exit", true);
Console.ReadLine();
}
//Set Enums & Consts
enum StrokeState {
Idle = 0,
Catch = 1,
Drive = 2,
Dwell = 3,
Recovery = 4
}
const Int16 NO_ERR = 0;
//Init Variables
Int16 ecode = NO_ERR;
UInt16 device_count = 0;
//Dll Imports
[DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 tkcmdsetDDI_init();
[DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 tkcmdsetDDI_discover_pm3s(String product_name, UInt16 starting_address, ref UInt16 num_units);
[DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 tkcmdsetDDI_fw_version(UInt16 unit_address, ref string ver_ptr);
[DllImport("PM3DDICP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void tkcmdsetDDI_shutdown(UInt16 port);
[DllImport("PM3CSAFECP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern UInt16 tkcmdsetCSAFE_init_protocol(UInt16 timeout);
[DllImport("PM3CsafeCP.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 tkcmdsetCSAFE_command(UInt16 unit_address,
UInt16 cmd_data_size, UInt32[] cmd_data, ref UInt16 rsp_data_size,
UInt32[] rsp_data);
public void runprog() {
//Init DDI Interface
wl("Initialising DDI interface...");
ecode = tkcmdsetDDI_init();
if (ecode == NO_ERR) {
wl("Done");
//Look for PM3s
wl("Looking for PM3s...");
ecode = tkcmdsetDDI_discover_pm3s("Concept2 Performance Monitor 3 (PM3)", 0, ref device_count);
if (ecode == NO_ERR) {
wl("Done");
//init CSAFE communication
wl("Initialising CSAFE Communication");
ecode = (short) tkcmdsetCSAFE_init_protocol(1000);
if (ecode == NO_ERR) {
wl("Done");
//Success
wl("PM3 Comms established");
wl("Found " + device_count + " device(s)");
}
}
}
wl("Program finished");
}
public void wl(string lin) {
wl(lin, false);
}
public void wl(string lin, bool isMain) {
if (isMain) {
Console.WriteLine("Main > " + lin);
}
else {
Console.WriteLine(" > " + lin);
}
}
}
Code: Select all
ecode = (short) tkcmdsetCSAFE_init_protocol(1000);
Thanks in advance.