在modbusTCP.h中,我将数组变量设置为静态变量。
static USHORT usRegInputBuf[REG_INPUT_NREGS];在此之后,我将包括modbusTCP.h并在main.c中使用它。
usRegInputBuf[0] = 1;
usRegInputBuf[1] = 4; ...但是,存在一个问题,即变量值不会改变。
pritnf("%u, %u\n", usRegInputBuf[0], usRegInputBuf[1]);=> 0,0
你怎么能解决这个问题?
发布于 2022-07-13 09:46:46
,
pritnf("%u, %u\n", (unsigned)usRegInputBuf[0], (unsigned)usRegInputBuf[1]);其次,
usRegInputBuf实例。相反,在标头中,您应该只声明它为extern,并在modbusTCP代码所在的C文件中定义:modbusTCP.h:
extern USHORT usRegInputBuf[REG_INPUT_NREGS];modbusTCP.c
USHORT usRegInputBuf[REG_INPUT_NREGS];https://stackoverflow.com/questions/72962539
复制相似问题