我主要使用 National Instruments 的 Labwindows CVI 作为编译器。
我必须为设备创建一个接口,并开始为所有不同的寄存器寻找结构。
// Interface.h
typedef enum Color{
White,
Black,
Blue
};
typedef struct Register1{
int Bit1:1;
int Bit2:2;
Color col;
} Register1;
// Interface.c
BuildSendMessage(Register1 temp)
{
unsigned int iTemp;
iTemp = temp.Bit1 << 7 + temp.Bit2 << 5 + temp.col;
}
// sample.c
Register1 reg1;
reg1.Bit1 = 0;
reg1.Bit2 = 1;
reg1.col = White;
// Pass to function where message is built up
BuildSendMessage(reg1);
然后我在调用函数中填充结构,然后将结构传递到一个函数中,在该函数中我执行所有位移,将地址等附加到消息上,并通过 comm 接口将其发送出去。
这可以改进吗?我应该隐藏更多信息并让函数填充结构吗?我一直在做很多阅读,这肯定可以使用一些改进。