コード例 #1
0
 // 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);
     }
 }
コード例 #2
0
 /*
  * 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";
     }
 }
コード例 #3
0
 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");
     }
 }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
            }
        }