This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] LAUNCHXL-F280025C:与 Jetson Orin Nano 进行 CAN 通信

Guru**** 2618835 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1584478/launchxl-f280025c-can-communication-with-jetson-orin-nano

器件型号: LAUNCHXL-F280025C

我当前正在运行 CAN_EX5_TRANSMIT_RECEIVE 示例、并将 LaunchPad 用作接收器。  我正在使用 Jetson USB 中连接的 CAN USB 收发器

并使用他们的 CAN 库编写了程序。   请参阅随附的文件。  Interface_Function_Library_User_Instruction.pdf 

当我运行 python 程序时、代码编写器中会触发中断、但它不会点击代码来读取值、因为我知道我传递的 ID 不正确



 我不熟悉 CAN、并且正在学习它的工作原理。  如果有人可以向我指出在传输功能中传递哪些内容的正确方向、我将非常感激。   

这是我的 python 脚本

from ctypes import *

VCI_USBCAN2 = 4
STATUS_OK = 1


class VCI_INIT_CONFIG(Structure):
    _fields_ = [("AccCode", c_uint),
                ("AccMask", c_uint),
                ("Reserved", c_uint),
                ("Filter", c_ubyte),
                ("Timing0", c_ubyte),
                ("Timing1", c_ubyte),
                ("Mode", c_ubyte)
                ]


class VCI_CAN_OBJ(Structure):
    _fields_ = [("ID", c_uint),
                ("TimeStamp", c_uint),
                ("TimeFlag", c_ubyte),
                ("SendType", c_ubyte),
                ("RemoteFlag", c_ubyte),
                ("ExternFlag", c_ubyte),
                ("DataLen", c_ubyte),
                ("Data", c_ubyte * 8),
                ("Reserved", c_ubyte * 3)
                ]


CanDLLName = './ControlCAN.dll'  # Put the DLL in the corresponding directory
# canDLL = windll.LoadLibrary('./ControlCAN.dll')
# Under the Linux system, use the following statement to compile the command: python3 python3.8.0.py
canDLL = cdll.LoadLibrary('./libcontrolcan.so')

print(CanDLLName)

ret = canDLL.VCI_OpenDevice(VCI_USBCAN2, 0, 0)
if ret == STATUS_OK:
    print('Call VCI_OpenDevice successfully\r\n')
if ret != STATUS_OK:
    print('Error calling VCI_OpenDevice\r\n')

# Initial 0 channel
vci_initconfig = VCI_INIT_CONFIG(0x80000008, 0xFFFFFFFF, 0,
                                 0, 0x03, 0x1C, 0)  # baud rate 125k, normal mode
ret = canDLL.VCI_InitCAN(VCI_USBCAN2, 0, 0, byref(vci_initconfig))
if ret == STATUS_OK:
    print('Call VCI_InitCAN1 successfully\r\n')
if ret != STATUS_OK:
    print('Error calling VCI_InitCAN1\r\n')

ret = canDLL.VCI_StartCAN(VCI_USBCAN2, 0, 0)
if ret == STATUS_OK:
    print('Call VCI_StartCAN1 successfully\r\n')
if ret != STATUS_OK:
    print('Error calling VCI_StartCAN1\r\n')

# channel 1 send data
ubyte_array = c_ubyte * 8
a = ubyte_array(1, 2, 3, 4, 5, 6, 7, 8)
ubyte_3array = c_ubyte * 3
b = ubyte_3array(0, 0, 0)
vci_can_obj = VCI_CAN_OBJ(0x1, 0, 0, 1, 0, 0, 8, a, b)  # Single send

#ret = canDLL.VCI_Transmit(VCI_USBCAN2, 0, 0, byref(vci_can_obj), 1)
ret = canDLL.VCI_Transmit(VCI_USBCAN2, 0, 0, byref(vci_can_obj), 1)
if ret == STATUS_OK:
    print('CAN1 channel sent successfully\r\n')
if ret != STATUS_OK:
    print('CAN1 channel sending failed\r\n')

# closure
canDLL.VCI_CloseDevice(VCI_USBCAN2, 0)
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Charlie、

    抱歉、我们无法在 CAN 分析仪接口上调试您的 python 脚本。  从以下文件开始将是有益的:

          ti.com/lit/an/sprace5a/sprace5a.pdf (DCAN 模块的编程示例和调试策略)

          https://www.ti.com/lit/pdf/spracq3 (用于控制器局域网的可配置错误发生器)

    第一份应用手册介绍了这些示例的工作原理。  第二个示例介绍了 CAN 帧生成的基础知识。  希望这些文档能帮助您开始使用 CAN。

    此致、

    Joseph

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您的文档。  我会看一下。