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:错误#1167:&quot 的无效属性;struct <unnamed >"

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1010358/launchxl-f280025c-error-1167-invalid-attribute-for-struct-unnamed

器件型号:LAUNCHXL-F280025C

我们希望实现 liblightmodbus -轻量级多平台 Modbus 库(版权所有(C) 2017 Jacek Wieczorek )、但我们在移植 parser.h 文件时遇到了一些问题

parser.h 文件定义了用于解析标准 Modbus 请求和构建响应的大型结构联合体、如下所示:

typedef union modbusParser

   uint8_t frame[256];

(**)   结构__attribute__(__packed__)
   {
      uint8_t 地址;
      uint8_t 函数;
   }基址;//基址共享字节,适用于所有帧,其含义始终相同

   (笑声)

} ModbusParser;

在尝试编译时 、我们在 code composer 中遇到错误:

(**)错误#1167:"struct "

我们尝试通过如下修改宏__packed__来使其正常工作,但现在却向我们发出警告

typedef union modbusParser

   uint8_t frame[256];

(*)   struct __attribute((__packed))
   {
      uint8_t 地址;
      uint8_t 函数;
   }基址;

   (笑声)

} ModbusParser;

(*)警告#1173-D:未知属性“__attribute__”

您对如何在 Code Composer Studio 上正确实施和使用该联合体有什么建议吗?

此致、

Wilson

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

    遗憾的是、C28x 编译器不支持 packed 属性。

    谢谢、此致、

    乔治

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

    乔治

    您知道吗?我如何在1字节边界上按如下方式封装结构的联合体、以便没有填充?

    typedef union modbusParser

       uint8_t frame[256];

       struct __attribute__(__packed__)
       {
          uint8_t 地址;
          uint8_t 函数;
       }基址;//基址共享字节,适用于所有帧,其含义始终相同

       (笑声)

    } ModbusParser;

    此致、

    Wilson

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

    您好 Wilson、

    C28x CPU 没有8位寻址功能、然后我们继续讨论 packed 属性。

      有关更多详细信息、请参阅 software-dl.ti.com/.../c2000_byte-accesses-with-the-c28x-cpu.html。

    如果您有更多问题、请告知我们。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="486976" URL"~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1010358/launchxl-f280025c-error-1167-invalid-attribute-for-struct-unnamed "]我们要实现 liblightmodbus -一种轻量级、多平台 Modbus 库[/quot]

    几年前、一位社区成员在 F2833x 系统上发布了他们的 MODBUS-RTU 端口。  请参阅下面的链接、获取该 E2E 帖子。  C2000不能声称这是一种好的实施方案还是无故障的实施方案、或者它与 lightmodbus 有多相似、但它可以为您提供良好的起点。
    https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/380010

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

    谢谢 Lori!