// The check method takes a canStatus (which is an enumerable) and the method // name as a string argument. If the status is an error code, it will print it. // Most Canlib method return a status, and checking it with a method like this // is a useful practice to avoid code duplication. private static void CheckStatus(Canlib.canStatus status, string method) { if (status < 0) { string errorText; Canlib.canGetErrorText(status, out errorText); Debug.WriteLine(method + " failed: " + errorText); } }
/* * Updates the status bar, prints error message if something goes wrong */ private void CheckStatus(String action, Canlib.canStatus status) { if (status != Canlib.canStatus.canOK) { String errorText = ""; Canlib.canGetErrorText(status, out errorText); statusText.Text = action + " failed: " + errorText; } else { statusText.Text = action + " succeeded"; } }
private void CheckStatus(String action, Canlib.canStatus status) { if (status != Canlib.canStatus.canOK) { String errorText = ""; Canlib.canGetErrorText(status, out errorText); ECULog.Info(action + " failed: " + errorText); } else { ECULog.Info(action + " succeeded"); } }
static private void ErrorControl(int handle = 1, Canlib.canStatus status = Canlib.canStatus.canOK, string location = "\0") { if (handle < 0) { //get the error message Canlib.canGetErrorText((Canlib.canStatus)handle, out string msg); //write the error message and the location it occurred. Console.WriteLine("Handle error: " + msg + " \nThe location is: " + location); //close this interface Close(); } if (status != Canlib.canStatus.canOK) { Console.WriteLine("A Can operation has failed: " + location); System.Windows.Forms.MessageBox.Show("A Can operation has failed: " + location, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
public KvaserCAN(MainWindow wnd) //public constructor { this.wnd = wnd; Canlib.canInitializeLibrary(); hcan = Canlib.canOpenChannel(channel, Canlib.canOPEN_REQUIRE_INIT_ACCESS); if (hcan < 0) { string error; Canlib.canGetErrorText((Canlib.canStatus)hcan, out error); send2Terminal(error); } else { Canlib.canSetBusParams(hcan, bitr, 0, 0, 0, 0, 0); //parameters set by dafault based on bitr Canlib.canBusOn(hcan); send2Terminal("Can liin avatud"); //DumpMessageLoop(hcan); } }