/python_CANape

Python Module for Vector CANape API

Primary LanguageC

Da Liegt der Hund beraben.

Entwicklungsgeschichte

Unternehmen, die CANape (einschließlich Vector) verwenden, sind mit Open Source sehr konservativ.

Bei Caterpillar (ca. 2015-2016) wurde eine Alpha-Version entwickelt. Es war gut. Es automatisierte Stunden des dSpace HIL-Testens! Es befindet sich in der Firewall von Caterpillar.

Bei Eaton (ca. 2017) wurde eine Beta-Version entwickelt. Es war gut gut. Es befindet sich in der Firewall von Eaton.

Code hier wurde mit der Demo-Version von Vector entwickelt. Es hat Einschränkungen. Ich kann mir keine Vector-Hardware leisten.

Zukunft

Python ist die Zukunft. ADAS5 benötigt viele Tests. Python ist gut in Tests. CANape braucht Python.

  • Vector könnte dies entwickeln. Hören Sie auf Ingenieure, nicht auf Management. Niemand mag COM.
  • Jemand spendet eine CANape-Lizenz für die Entwicklung.
  • Jemand gabelt und setzt diese Arbeit fort.

PyCANape

Pythonic CFFI wrapper for CANape. This is a full Pythonic wrapper using the CANape ASAM-MCD3 Interface (CANapeAPI). It has an identical feature set to the CANape® and MATLAB® interface.

Examples

Create CANape object.

import CANape
canape = CANape.CANape()

CANape can be initialized via the init(), init2(), init3(), init4(), or init5() functions. Any one of these functions can be used to initialize CANape depending upon need. Each function requires a different set of parameters that need to be passed in. If init5 is being used, the function can be called like this:

canape.init5(timeout = 20000,
             m_WorkingDir = r"C:\Vector\Data\Experiment1",
             fifo_size = 1000,
             sample_size = 1,
             debug = True,
             clear_device_list)

After initializing the ASAP3 connection, a new module/device has to be created and a database file has to be attached. If a connection is being made to a CCP device and an ASAP2 description file is available, the AttachAsap2() function is used.

canape.attach_asap(a2l=r"C:\Vector\Data\Experiment1\TopSecret.a2l",
                    channel = 2);

To create a connection to a CAN device, the module can to be created like this:

canape.create_module (name = "CAN",
                      database= r"C:\Vector\Data\Experiment1\TopSecret.dbc",,
                      driverType=CANape(CCP,
                      channel = 1);

To use a MDF file in Python or Matlab.

canape.matlab_conversion(mdf = r"C:\Vector\Data\Experiment1\NDA_Data.mdf",
                         mat = r"C:\Vector\Data\Experiment1\NDA_Data.mat)

To list all devices currently connected to CANape:

devices = canape.get_devices()
for device in devices:
    print(device)

Create a new module, add a measurement channel, record data, process it with numpy.

canape.attach_asap(a2l=r"C:\Vector\Data\Experiment1\TopSecret.a2l",
                   channel = 2);
canape.module[0].add_measurement(name='channel2',
                                 task_index =3,
                                 save=0)
canape.start_measurement()
while True:
    data = canape.get_fifo_data(0, 2)
    if np.magic(data):
        print("Eureka!")
        break

Read and display calibration 2D Calibration Map. (Can return any calibration object data type like scalar, string, map and curve.)

data = canape.read_calibration_object(0, 'TopSecretCalibration', 1)
plt.plot(data[:,0], data[:,1])
plt.xlabel("Top Secret Dependent Axis")
plt.ylabel("Top Secret Independent Axis")
plt.title("Top Secret Calibration")
plt.show()

To close the CANape connection, the exit() function is used:

canape.exit()

Why?

Exposes all of CANape's features to the Python ecosystem.

Motivation

  • Me: "So are you guys going to ever release a Python interface?"
  • Vector Sales Rep: "Everyone loves our COM interface? Is the COM interface not good enough? Why would anyone want to use Python when there is a COM interface? I can give you the e-mail address of an engineer if you need help with our COM interface."
  • Me: Shocked Pikachu