回复:在用GetTagRaw()时老是返回0是怎么回事?

万泉河

  • 帖子

    10900
  • 精华

    132
  • 被关注

    1008

论坛等级:至圣

注册时间:2003-06-06

钻石 钻石 如何晋级?

发布于 2008-05-06 19:19:39

0楼

This is the code I use to receive an array of OPC floating point numbers and display on a picture.
I could not find a clean way of accessing WinCC internal tags as an array, so it is messy at the bottom. Glad I have only 40 elements. The code window, while very pretty, did not like something in this file, it interpreted some of the HTML as literals. This will paste directly into C Action, and with the colors, it is easier to read.


#include "apdefap.h"

int gscAction( void )
{

// global function name check for compiler, list of all valid functions
// SZ88 "QcsWt.pas" last revised 26 April 2008 RonW
#define PROFILE_SIZE 40 // 40 cross machine boxes is the view we see on WinCC Screen
#define DATA_SIZE 220 // (220) 32 bit floating point numbers, 4 bytes each, from OPServer OPC.HS-QCS
float Profile[PROFILE_SIZE]; // build this temporary storage to allow the code to process the byData array from 220 to 40 to in a small for loop.
float a=0 ; // working value, start at zero
float sum=0 ; // working value, start at zero
int i,J ; // i and j are integers for counters
int k; // k is the index into the 40 element array
float AVG_count=5.5; // AVG is an floating point, with a value of 5.5, to average 220 elements into 40
float L, M, R; // Left, middle right count of non-zero values for Profile Zone aggregation
float wtL, wtM, wtR; // Left, middle right sum of values for Profile Zone aggregation
int index; // subs cript of the first element in a given profile control zone
float temp; // working value to test for zero in mid control zone

// Create a union called DataArray that can be accessed as an array of bytes, or floating point numbers

union DataArray {
BYTE raw[DATA_SIZE *4]; // the byte array receives the data from the OPC QCS, 4 bytes for every float
float value[DATA_SIZE]; // the same data in the array described as floating point
} byData; // the name for each member of the array is ByData, accessed as byData.value for the float #

// "SatScanner3BwSensor_DryWeight_220bwt" is the raw OPC data tag from HS-QCS, 220 elements 32 bit
// FP array, calculated from Basis Weight in GSM, corrected to OD weight using moisture information.
// grab the current value of the OPC floating point array, it updates every 20 seconds

GetTagRaw("SatScanner3BwSensor_DryWeight_220bwt", byData.raw, DATA_SIZE*4 );


// Now we have the array as 220 new floating point values, accessed as byData.value[0 through 219]

k=0; //Start at the 1st profile box for the WinCC screen, in Profile[0]
J=0; //Start at the first element sent from the QCS, in byData.value[0]
index=0;
for(k=0;k{

//Profile Zone WT_1,3,5,7... (Array Element = WT_1 minus 1 = 0)

sum=0; // initialize weight raw sum of the 5.5 zones
// index leads into left hand element of raw data array, per zone
// six weight values are evaluated,
wtL = byData.value[index]; // pick up the left hand value

if(wtL>0) // find any zero values at start of control zone, so not averaged
L=1; // not a zero value
else
L=0; // zero value


wtM=0;
M=0; // initialize middle count of control zone values, count non-zero values
for(i=1;i<4+1;i++) // do 4 iterations
{
temp = byData.value[index+i]; // pick up the 4 middle values,
if (temp > 0) M++; // test for zero, count up the number of non-zero values
wtM=temp+wtM; // sum the values, wtM now has the sum of the middle values
};

wtR = byData.value[index+5]/2; // pick up the right hand value, divide by two, to split the zone with the next one


if(wtR>0) // find any zero values at end of control zone, so not averaged
R=1;
else
R=0; // R tells us if we need to average in a value from the right

sum=wtL+wtM+wtR; // add up all the values of oven dry weight in gsm

AVG_count = M + L + R/2; // add up the quantity of non-zero values, split the end zone for the 5.5 zones

if(AVG_count>0) // if there is any weight value in the profile zone group
a=sum/AVG_count; // calculate the control zone average
else
a=0; // have not found edge of sheet yet

Profile[k] = a; // set the 5.5 1st zone value in the holding Profile Array. At the end, we'll send it to the WinCC
// internal tag

// Profile Zone WT_2,4,6,8,10... (Array Element = WT_2 minus 1 = 1)

sum=0; // initialize weight raw sum of the 5.5 zones
k=k+1; // increment the receiving profile zone, WinCC buffer

J=J+1; // increment the received profile zone
index=index + 5; // index leads into left hand element of raw data array, per zone
// six weight values are evaluated,
wtL = byData.value[index]/2; // pick up the left hand value, divide by 2 to share with previous zone

if(wtL>0) // find any zero values at start of control zone, so not averaged
L=1; // not a zero value
else
L=0; // zero value

wtM=0;
M=0; // initialize middle count of control zone values, count non-zero values
for(i=1;i<4+1;i++) // do 4 iterations
{
temp = byData.value[index+i]; // pick up the 4 middle values,
if (temp > 0) // test for zero, count up the number of non-zero values
M++;
wtM=temp+wtM; // sum the values
};

wtR = byData.value[index+5]; // pick up the right hand value

if(wtR>0) // find any zero values at end of control zone, so not averaged
R=1;
else
R=0;

sum=wtL+wtM+wtR; // add up all the values of oven dry weight in gsm

AVG_count = L/2 + M + R; // add up the quantity of non-zero values, split the end zone for the 5.5 zones

if(AVG_count>0) // if there is any weight value in the profile zone group
a=sum/AVG_count; // calculate the control zone average
else
a=0; // have not found edge of sheet yet, do not do a divide by zero

Profile[k] = a; // set the 5.5 1st zone value in the holding Profile Array. At the end, we'll send it to the WinCC
// internal tag
index=index+6;
J=J+1 ;
}; // go back and do the next pair of zones
// now we should be done aggregating all the 220 elements into the 40, so update the WinCC tags
SetTagFloat("WT_1", Profile[0]);
SetTagFloat("WT_2", Profile[1]);
SetTagFloat("WT_3", Profile[2]);
SetTagFloat("WT_4", Profile[3]);
SetTagFloat("WT_5", Profile[4]);
SetTagFloat("WT_6", Profile[5]);
SetTagFloat("WT_7", Profile[6]);
SetTagFloat("WT_8", Profile[7]);
SetTagFloat("WT_9", Profile[8]);
SetTagFloat("WT_10", Profile[9]);
SetTagFloat("WT_11", Profile[10]);
SetTagFloat("WT_12", Profile[11]);
SetTagFloat("WT_13", Profile[12]);
SetTagFloat("WT_14", Profile[13]);
SetTagFloat("WT_15", Profile[14]);
SetTagFloat("WT_16", Profile[15]);
SetTagFloat("WT_17", Profile[16]);
SetTagFloat("WT_18", Profile[17]);
SetTagFloat("WT_19", Profile[18]);
SetTagFloat("WT_20", Profile[19]);
SetTagFloat("WT_21", Profile[20]);
SetTagFloat("WT_22", Profile[21]);
SetTagFloat("WT_23", Profile[22]);
SetTagFloat("WT_24", Profile[23]);
SetTagFloat("WT_25", Profile[24]);
SetTagFloat("WT_26", Profile[25]);
SetTagFloat("WT_27", Profile[26]);
SetTagFloat("WT_28", Profile[27]);
SetTagFloat("WT_29", Profile[28]);
SetTagFloat("WT_30", Profile[29]);
SetTagFloat("WT_31", Profile[30]);
SetTagFloat("WT_32", Profile[31]);
SetTagFloat("WT_33", Profile[32]);
SetTagFloat("WT_34", Profile[33]);
SetTagFloat("WT_35", Profile[34]);
SetTagFloat("WT_36", Profile[35]);
SetTagFloat("WT_37", Profile[36]);
SetTagFloat("WT_38", Profile[37]);
SetTagFloat("WT_39", Profile[38]);
SetTagFloat("WT_40", Profile[39]);


return 0;

}
微信公众号:PLC标准化编程,ZHO6371995
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32566条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。