我手上有一个很大的问题,我认为它无法正常运行的原因在于我的 C 语言知识,也就是说,让我们面对它充其量是个新手......
void * KT_Indirect_CNS(int NumCNS, char *CNSDescr[], char *CNSTag[], int *CNSIsBit[], char* lpszPictureName){
#include "apdefap.h"
char TagNameEnable[255],
TagNameTrue[255],
TagNameFalse[255],
TagNameString[255],
TagNameCNS[255],
TagNameCNSString[255],
TagNameTemp[255];
int i,
count;
typedef struct
{
LONG x;
LONG y;
} tPOINT;
#pragma code ("user32.dll");
BOOL GetCursorPos( tPOINT* lpPoint);
#pragma code();
tPOINT pt;
GetCursorPos(&pt);
for (i=1; i<=NumCNS; i++)
{
sprintf(TagNameEnable, "CNS%d.Enabled", i);
SetTagBit(TagNameEnable, 1);
sprintf(TagNameCNS, CNSTag[i-1]);
sprintf(TagNameTrue, "CNS%d.True", i);
sprintf(TagNameFalse, "CNS%d.False", i);
if (CNSIsBit[i-1] == 17)
{
BOOL temp = GetTagBit(TagNameCNS);
if (temp==1)
{
SetTagBit(TagNameTrue, 1);
SetTagBit(TagNameFalse, 0);
count++;
}
else
{
SetTagBit(TagNameTrue, 0);
SetTagBit(TagNameFalse, 1);
}
}
if ((CNSIsBit[i-1] >= 0) && (CNSIsBit[i-1] <=16))
{
int *bits = GetBitsFromWord(GetTagWord(TagNameCNS));
int index = (int)CNSIsBit[i-1];
if (bits[index]==1)
{
SetTagBit(TagNameTrue, 1);
SetTagBit(TagNameFalse, 0);
count++;
}
if (bits[index]==0)
{
SetTagBit(TagNameTrue, 0);
SetTagBit(TagNameFalse, 1);
}
}
sprintf(TagNameString, "CNS%d.String", i);
SetTagChar(TagNameString, CNSDescr[i-1]);
}
if (NumCNS <16)
{
for (i=NumCNS+1; i<=16; i++)
{
sprintf(TagNameTrue, "CNS%d.True", i);
sprintf(TagNameFalse, "CNS%d.False", i);
sprintf(TagNameEnable, "CNS%d.Enabled", i);
SetTagBit(TagNameTrue, 0);
SetTagBit(TagNameFalse, 0);
SetTagBit(TagNameEnable, 0);
}
}
if (count != NumCNS)
{
sprintf(TagNameTemp, "CNS_Page_AllGood");
SetTagBit(TagNameTemp, 0);
SetVisible(lpszPictureName,"KT_CNS",TRUE);
sprintf(TagNameTemp, "CNS_PAGE_MOUSE_X");
SetTagSWord(TagNameTemp, pt.x-5);
sprintf(TagNameTemp, "CNS_PAGE_MOUSE_Y");
SetTagSWord(TagNameTemp, pt.y-150);
sprintf(TagNameTemp, "CNS_PAGE_HEIGHT");
SetTagSWord(TagNameTemp, 30*NumCNS);
}
if (count == NumCNS)
{
sprintf(TagNameTemp, "CNS_Page_AllGood");
SetTagBit(TagNameTemp, 1);
}
return ("Controller Initilized");}
int *GetBitsFromWord(WORD _word){
int bits[16];
bits[0] = (_word & 0x0001)?1:0;
bits[1] = (_word & 0x0002)?1:0;
bits[2] = (_word & 0x0004)?1:0;
bits[3] = (_word & 0x0008)?1:0;
bits[4] = (_word & 0x0010)?1:0;
bits[5] = (_word & 0x0020)?1:0;
bits[6] = (_word & 0x0040)?1:0;
bits[7] = (_word & 0x0080)?1:0;
bits[8] = (_word & 0x0100)?1:0;
bits[9] = (_word & 0x0200)?1:0;
bits[10] = (_word & 0x0400)?1:0;
bits[11] = (_word & 0x0800)?1:0;
bits[12] = (_word & 0x1000)?1:0;
bits[13] = (_word & 0x2000)?1:0;
bits[14] = (_word & 0x4000)?1:0;
bits[15] = (_word & 0x8000)?1:0;
return bits;}
这些是我用来收集工厂中设备的一般不运行原因的脚本......我认为它在我测试它时有效,我会愚蠢地添加......我认为我的指针使用知识足够低我想一个会让我丧命的错误......基本上我需要从我的PLC(s7-400)收集一个WORD类型的数据(16位),我需要从所说的字中提取位以确定对象的状态WinCC 中的画面。事情是我没有得到我期望的值......它编译没有问题但是......有人有一些建议吗?如何改进我的代码?