Ejemplo n.º 1
0
//---------------------------------------------------------------------------
void __fastcall TframTag::btnWriteDeviceClick(TObject *Sender)
{
	AnsiString value;
	pmc_value_t strVal, val;
	value = InputBox(
		"输入要写的数值",
		(char*)CTagName(m_TagName.sname.tag),
		""
		);
	if(value.Length() == 0){
		return;
	}
    set_value_type(strVal.Flags, dt_string);
    strVal.Value.str = value.c_str();
    val.Flags = m_Tag.s.Flags;
    pmc_type_cast(&strVal, &val);
	if(proxy_write_tags(1, &m_TagName, &val.Value) ){
		m_Hint = "写入成功";
	}else{
		m_Hint = "写入失败";
	}
}
Ejemplo n.º 2
0
/*
功能:将pmc_value_t实时值写入设备
参数:
      name    待写入实时值对应的   组名.标签名
	  value   待写入的实时值
返回:即设备驱动导出函数write_device()的返回值
*/
IO_API __bool PMC_API io_write_device_ex(
	PCSHORT_TAG_NAME name, 
	PCpmc_value_t value
	)
{
	pmc_value_t value2;
	__bool retval = __false;

	if(!lock_rtdb(__false, 100)){
		return __false;
	}
	PRTK_TAG p = query_tag(HNODE_LOCAL_MACHINE, name);
	if(p && !(p->d.Value.Flags & TF_ReadOnly)){
		ZeroMemory(&value2, sizeof(value2));
		set_value_type(value2.Flags, get_value_type(p->s.Flags));
		if(pmc_type_cast(value, &value2)){
			retval = _writeDevice(p, &value2.Value);
		}
	}
	unlock_rtdb();

	return retval;
}
Ejemplo n.º 3
0
void __fastcall TframTag::tmrUpdaterTimer(TObject *Sender)
{
	pmc_value_t value;
	AnsiString txtValue;
	char buf[64];
	FILETIME ft;
	SYSTEMTIME st;

	proxy_read_tags(1, &m_TagName, &value, 0);
	if(value.Flags & TF_Valid){
    	pmc_value_t strVal;
        set_value_type(strVal.Flags, dt_string);
        pmc_type_cast(&value, &strVal);
        txtValue = strVal.Value.str;
        pmc_clear(&strVal);
	}else{
		txtValue = "N.A.";
	}
	edtValue->Text = txtValue;

	RTK_TAG * p = query_tag_f(&m_TagName);
	if(p){
		AnsiString s;
		FILETIME   lft;
		SYSTEMTIME st;
		FileTimeToLocalFileTime((LPFILETIME)&p->d.CachedTime, &lft);
		FileTimeToSystemTime(&lft, &st);
		s = "";
		s.cat_printf(
			"%d年%d月%d日  %02d:%02d:%02d",
			st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond
			);
		lblStatus->Caption = s;
	}else{
		lblStatus->Caption ="";
	}
}
Ejemplo n.º 4
0
double CExpression::vexp ( arbore a )
{
	double v;
	SYSTEMTIME tm;
	
	GetSystemTime(&tm);

	if (a->operatie==NULL) {error_code=10;return 0;}
	switch(a->operatie){
	case '+' : return( vexp(a->left)+vexp(a->right) );
	case '-' : return( vexp(a->left)-vexp(a->right) );
	case '*' : return( vexp(a->left)*vexp(a->right) );
	case '%':
		{
			v = vexp(a->right);
			if(v == 0){
				error_code = DIVISION_BY_0;
				return 0;
			}
			return (int)vexp(a->left) % (int)v;
		}
	case '/' : v=vexp(a->right) ;
		if (v==0){
			error_code=DIVISION_BY_0;
			return -vexp(a->left)/0.001;
		}else{
			return(vexp(a->left)/v);
		}
	case 150 : return(sin(vexp(a->left)));
	case 151 : return(cos(vexp(a->left)));
	case 152 : return(exp(vexp(a->left)));
	case 153 : v=vexp(a->left) ;
		if (v<0) {error_code=INVALID_DOMAIN;return 0;}
		else return(sqrt(v));
	case 154 : v=vexp(a->left) ;
		if (v<=0) {error_code=INVALID_DOMAIN;return 0;}
		else return(log(v));
	case 155 : return (tan (vexp(a->left)));
	case 156 : return (1 / tan (vexp(a->left)));
	case 157 : return (asin (vexp(a->left)));
	case 158 : return (acos (vexp(a->left)));
	case 159 : return (atan (vexp(a->left)));
	case 173 : return (fabs (vexp(a->left)));
	case 160 : return tm.wYear;
	case 161 : return tm.wMonth;
	case 162 : return tm.wDay;
	case 163 : return tm.wHour;
	case 164 : return tm.wMinute;
	case 165 : return tm.wSecond;
	case 166 : return max(vexp(a->left),vexp(a->right));
	case 167 : return min(vexp(a->left),vexp(a->right));
	case 168 : return rng_rand(0,RAND_MAX)*vexp(a->left)/RAND_MAX;
	//case '|' : return(fabs(vexp(a->left)));
	case '^' : return(pow(vexp(a->left),vexp(a->right)));
	case '@' : return (a->valoare);
		//logical operations evaluation
	case '<' : return( vexp(a->left) < vexp(a->right) );
	case '>' : return( vexp(a->left) > vexp(a->right) );
	case '!' : return(!vexp(a->right)) ;
	// added by chenj, @2008-5-22
	case '=' : return( vexp(a->left) == vexp(a->right) );
	case '&' : return (int)(vexp(a->left)) & (int)(vexp(a->right));
	case '|' : return (int)(vexp(a->left)) | (int)(vexp(a->right));
		
	case 169:
		{
			RTK_TIME t;
			rtk_time_mark(&t);
			return (double)(__int64)t.Data / 1e7;
		}
		
	case 170:
		{
			/* last update time */
			PRTK_TAG tte;
			__r8 retval = 0;
			
			tte  = (PRTK_TAG)a->left->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					PRTK_TIME pTime = (PRTK_TIME)&tte->d.BinaryAddress[8];
					retval = (double)(__int64)pTime->Data / 1e7;
					rtk_time_mark(pTime);
				}
			}

			return retval;
		}

	case 171  : 
		{
			// a database tag
			PRTK_TAG tte;
			__r8 retval = 0;
			tte = (PRTK_TAG)a->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					pmc_value_t dblVal;
					set_value_type(dblVal.Flags, dt_real8);
					pmc_type_cast(&tte->d.Value, &dblVal);
					retval = dblVal.Value.dbl;
				}
			}
			return retval;
		}
	
	case 172:
		{
			/* span time */
			PRTK_TAG tte;
			RTK_TIME now;
			__r8 retval = 0;
			
			tte  = (PRTK_TAG)a->left->pvObj;
			if(!tte){
				error_code=UNDEFINED_VARIABLE;
				retval = 0;
			}else{ 
				if(!(tte->d.Value.Flags & TF_Valid)){
					error_code=UNDEFINED_VARIABLE;
					retval = 0;
				}else{
					PRTK_TIME pTime = (PRTK_TIME)&(tte->d.BinaryAddress[8]);
					rtk_time_mark(&now);
					if(pTime->Data != 0){
						/* yes, the field is previouly stored with a resonable value,
						thus valid for a sub-operation to get a duration time */
						retval = rtk_time_diff(&now, pTime);
					}else{
						/* this might be the first time that a time-span was requested
						for this tag
						*/
						retval = 0;
					}
					
					*pTime = now;
				}
			}

			return retval;
		}

	}

	return 0;
}
Ejemplo n.º 5
0
void CText::Draw(CDC *pDC)
{
    long x1,y1,x2,y2;
    if(m_DnyAttr.m_Linked && m_DnyAttr.m_na) {
        CPen *pop=(CPen*)(pDC->SelectStockObject(BLACK_PEN));
        CBrush *pob=(CBrush*)(pDC->SelectStockObject(WHITE_BRUSH));
        UPtoLP(m_lox1,m_loy1,&x1,&y1);
        UPtoLP(m_lox2,m_loy2,&x2,&y2);
        pDC->Rectangle(x1,y1,x2,y2);
        /*
        pDC->MoveTo(x1, y1);
        pDC->LineTo(x1 + 10, y1 + 10);
        pDC->MoveTo(x1 + 10, y1);
        pDC->LineTo(x1, y1 + 10);
        */
        pDC->SelectObject(pop);
        pDC->SelectObject(pob);
        pDC->DrawIcon(x1,y1,ghNA);
        return;
    }

    if(m_DnyAttr.m_Linked && !m_DnyAttr.m_vi) return;

    LOGFONT tFont;
    tFont=m_font;
    UPtoLP(tFont.lfHeight,tFont.lfWidth,&tFont.lfHeight,&tFont.lfWidth);
    CFont font;
    font.CreateFontIndirect(&tFont);
    CFont *pOldFont=pDC->SelectObject(&font);

    int i,iWidth;
    long lTemp,lUWidth=0;
    UINT nTemp;
    i=0;
    while(i<m_text.GetLength()) {
        nTemp=(UCHAR)m_text[i];
        if(IsDBCSLeadByte(nTemp)) {
            nTemp=nTemp*256+(UCHAR)m_text[i];
            i++;
        }
        ::GetCharWidth(pDC->GetSafeHdc(),nTemp,nTemp,&iWidth);
        //CMeatFileDC没有属性DC,下面这句话就不灵了。
        //pDC->GetCharWidth(nTemp,nTemp,&iWidth);
        CElement::LPtoUP(iWidth,iWidth,&lTemp,0);
        lUWidth+=lTemp;
        i++;
    }

    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(m_FaceColor);

    UPtoLP(m_lx1,m_ly1,&x1,&y1);

    CString sTemp;
    sTemp=m_text;
    if(m_DnyAttr.m_ValueA.m_Used) {
        pmc_value_t d;
        set_value_type(d.Flags, dt_real4);
        pmc_type_cast(&m_DnyAttr.m_ValueA.m_TagValue, &d);
        sTemp.Format(m_DnyAttr.m_ValueA.m_Format, d.Value.flt);
    } else if(m_DnyAttr.m_ValueD.m_Used) {
        if(m_DnyAttr.m_ValueD.action_proc && m_DnyAttr.m_ValueD.action_proc != (void*)-1) {
            char * s;
            s = ((char * (WINAPI*)())m_DnyAttr.m_ValueD.action_proc)();
            sTemp = s;
            free_buffer(s);
        } else {
            if(m_DnyAttr.m_ValueD.m_TagValue.Value.iValue) {
                sTemp=m_DnyAttr.m_ValueD.m_OnMsg;
            } else {
                sTemp=m_DnyAttr.m_ValueD.m_OffMsg;
            }
        }
    }
    pDC->TextOut(x1,y1,sTemp);
    pDC->SelectObject(pOldFont);
}