找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4197|回复: 0
打印 上一主题 下一主题
收起左侧

wincc 冗余连接的代码

[复制链接]
跳转到指定楼层
楼主
ID:140343 发表于 2016-9-24 20:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "apdefap.h"

int gscAction( void )
{

#pragma option(mbcs)

// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
#define TAG_0 "@S7-Programm(1)@AlternateConnectionAddress"
#define TAG_1 "@S7-Programm(1)@ConnectionEstablishMode"
#define TAG_2 "@S7-Programm(1)@ConnectionState"
#define TAG_3 "@S7-Programm(1)@ForceConnectionAddress"
// WINCC:TAGNAME_SECTION_END

// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END


#pragma code("msrtcli.dll")
#include "msrtapi.h"
#pragma code()

#pragma code( "kernel32.dll" )
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);
#pragma code()


static int Mld_Main = 0;
static int Mld_Res = 0;

DWORD ServiceID = 0;
static BOOL InitFirst = TRUE;

static MSG_RTCREATE_STRUCT  MsgCreate;
CMN_ERROR Error;



if ( InitFirst == TRUE )
{
    memset( &MsgCreate, 0, sizeof (MSG_RTCREATE_STRUCT) );
    MsgCreate.dwMsgState = MSG_STATE_COME;
    MsgCreate.wTextValueUsed = 1;
    sprintf( MsgCreate.mtTextValue[0].szText, "S7-Programm(1)" );
    SetTagChar( TAG_0, "MPI,3 0,,1,3,02" );
     InitFirst = FALSE;
}

if (  GetTagDWordWait( TAG_1 ) == 0  )
{
    Mld_Main = 0;
    Mld_Res = 0;
    return 0;
}
else
{
    GetLocalTime( &MsgCreate.stMsgTime );
    MSRTStartMsgService ( &ServiceID, NULL, NULL, MSG_NOTIFY_MASK_ARCHIV, NULL, &Error );

    if (  GetTagDWordWait( TAG_2 ) == 0  )
    {
             if (  GetTagDWordWait( TAG_3 ) == 0  )
        {
            if ( Mld_Main == 0 )
            {
                MsgCreate.dwMsgNr = 1012222;
                MSRTCreateMsg( ServiceID, &MsgCreate, &Error );
                Mld_Main = 1;
            }
         }
        else
        {
            if ( Mld_Res == 0 )
            {
                MsgCreate.dwMsgNr = 1012224;
                MSRTCreateMsg( ServiceID, &MsgCreate, &Error );
                Mld_Res = 1;
            }
        }

          if (  GetTagDWordWait( TAG_2 ) == 0  )
        {
            if (  GetTagDWordWait( TAG_3 ) == 0  )
            {
                  SetTagDWord( TAG_3, 1 );
            }
            else
            {
                SetTagDWord( TAG_3, 0 );
            }
        }
    }     
    else
    {
        if (  ( Mld_Main != 0 )  ||  ( Mld_Res != 0 )  )
        {
            Mld_Main = 0;
            Mld_Res = 0;

            if (  GetTagDWordWait( TAG_3 ) == 0  )
            {
                MsgCreate.dwMsgNr = 1012223;
                MSRTCreateMsg( ServiceID, &MsgCreate, &Error );
            }
            else
            {
                MsgCreate.dwMsgNr = 1012225;
                MSRTCreateMsg( ServiceID, &MsgCreate, &Error );
            }
        }
    }     
    if ( ServiceID != 0 )
    {
        MSRTStopMsgService ( ServiceID, &Error );
    }
     return 1;
}
}



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表