CAPL uint32 到 dword 的无效类型转换

CAPL invalid type cast of uint32 to dword

请听我说说。设 sysAUint32 类型的系统变量(结构成员),用于存储四字节长的唯一十六进制 ID。 在我的 CAPL 脚本中,我想在这个 UUID 和一个整数之间执行检查,我通过来自消息的四个字节的组合重新定义。我采用了这种方法:

variables
{
    dword uuid;
}

on message myMsg
{
    uuid = (this.byte(0)<<24) | (this.byte(1)<<16)| (this.byte(2)<<8) | this.byte(3);
    if (@sysA == uuid)
    {
        // do something
    }
}

此代码触发错误,因为类型 dwordUint32 不兼容。然后我尝试将 sysA 转换为 dwordinvalid type cast。我不确定为什么在 CAPL 语言中会出现这种情况。根据文档:

byte (unsigned, 1 Byte)

word (unsigned, 2 Byte)

dword (unsigned, 4 Byte)

int (signed, 2 Byte)

long (signed, 4 Byte)

int64 (signed, 8 Byte)

qword (unsigned, 8 Byte)

我无法将 Uint32 系统变量类型转换为 intint i = 32768 超出范围并且 int i = 32768LL 无效。但是 dword,在这种情况下,严格来说是 4 个字节的 unsigned int

在这种情况下,我应该将什么类型正确用作我的 uuid,为什么?

我也试过你的代码片段。当您尝试使用系统变量时,您也应该尝试定义适当的命名空间。

variables
{
  dword uuid;
}

on message * 
{
  uuid = ((this.byte(0) << 24) | (this.byte(1) << 16) | (this.byte(2) << 8) | (this.byte(3)));

  if ((dword)@namespace::sysA == uuid)
  {
    write ("Hello World!");
  }
}