发布于 2006-12-20 11:43:53
0楼
TO万版,就是增加我在5楼的那一段代码解决的问题1,具体问题1产生的原因我也搞不明白,我的C太菜,看得似懂非懂,我一会在下面把动作@CPU1的脚本代码全部贴出来。
昨天的调试对现象2有进一步的发现,我采用硬切换方式(即直接将CPU1或CPU2 打到STOP)这时2台WINCC站均能自动切换到与另一块还在运行的CPU通讯,无论在哪一台WINCC站上都能写入,但是如果采用软切换方式(在WINCC上做一按钮,按下后置切换控制位DB5.DBX10.0为1,释放按钮后置0)切换CPU后,通讯并没有随之切换,这时就出现了WINCC站不能写入的情况,正如万版所说的切换的时候WINCC并不切换通讯对象,但查看CPU的状态字均表明主系统已被切换,搞不懂为什么会这样,请大家继续指教,我也想找出根本原因,这样能加深自己对软冗余的理解。
WINCC中的冗余连接脚本@CPU1全部代码如下:
#include "apdefap.h"
int gscAction( void )
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
#define TAG_0 "@CPU1@AlternateConnectionAddress"
#define TAG_1 "@CPU1@ConnectionEstablishMode"
#define TAG_2 "@CPU1@ConnectionState"
#define TAG_3 "@CPU1@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, "CPU1" );
SetTagChar( TAG_0, "H1,08 00 06 9C ED 62,,0,2,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 );
if ( GetTagDWordWait( "@CPU_1@ConnectionState" ) == 0 )
{
SetTagDWord( "@CPU_1@ForceConnectionState", 1 );
}
else
{
if ( GetTagBitWait( "SWR.Standby" ) == TRUE )
{
SetTagDWord( "@CPU_1@ForceConnectionState", 0 );
}
}
}
return 1;
}
}