How to access Modbus TCP Conection Status/IP via C in WinCC

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Post Reply
mmohamadian
Posts: 10
Joined: Sun Dec 14, 2014 12:10 pm

How to access Modbus TCP Conection Status/IP via C in WinCC

Post by mmohamadian » Sat Aug 13, 2016 7:45 am

Hi dear experts. According to the attached picture I want to access the status and connection driver IP address of my Modbus TCPIP channel drivers via C-Script in WinCC. Can anyone suggest me a function or a script code.
Image

Schtiel
Site Admin
Posts: 1121
Joined: Wed Sep 06, 2006 12:03 pm
Location: CIS

Post by Schtiel » Mon Aug 15, 2016 12:47 pm


mmohamadian
Posts: 10
Joined: Sun Dec 14, 2014 12:10 pm

Re: How to access Modbus TCP Conection Status/IP via C in Wi

Post by mmohamadian » Tue Aug 16, 2016 7:17 am

Thanks a lot for the reply but this link is not about accessing that parameter via c-script.

Schtiel
Site Admin
Posts: 1121
Joined: Wed Sep 06, 2006 12:03 pm
Location: CIS

Post by Schtiel » Tue Aug 16, 2016 6:22 pm

It is about getting status of connection via C-sctipt

Code: Select all

#include "apdefap.h"
int gscAction(void)
{
DWORD dwState = 0;
GetTagSWordState ("External_tag_1", &dwState);
if (dwState == 0)
{
//Tag status OK
printf ("Tag status Ok: [Statuscode (hex):%X]\r\n",dwState);
SetTagBit ("Trigger", FALSE);
SetTagBit ("Trigger_connection_interrupted", FALSE);
}
else if (dwState&0X0001)
{
SetTagBit ("Trigger_connection_interrupted", TRUE);
}
else
{
//Tag status deviant
printf ("Tag status deviant: [Statuscode (hex):%X]\r\n",dwState);
SetTagBit ("Trigger", TRUE);
SetTagBit ("Trigger_connection_interrupted", FALSE);
}
return (0);
}

mmohamadian
Posts: 10
Joined: Sun Dec 14, 2014 12:10 pm

Re: How to access Modbus TCP Conection Status/IP via C in Wi

Post by mmohamadian » Wed Aug 17, 2016 5:04 am

Thanks dear Schtiel.
Do you have any idea about changing IP address of modbus TCPIP driver ia C-script?

Schtiel
Site Admin
Posts: 1121
Joined: Wed Sep 06, 2006 12:03 pm
Location: CIS

Post by Schtiel » Wed Aug 17, 2016 6:24 am

This is a sample of changing IP address of connection to CP 443-1. May be it would give an idea how to to do the same for Modbus TCP

Code: Select all

#include "apdefap.h"

int gscAction( void )
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
#define TAG_0 "@NewConnection_1@AlternateConnectionAddress"
#define TAG_1 "@NewConnection_1@ConnectionEstablishMode"
#define TAG_2 "@NewConnection_1@ConnectionState"
#define TAG_3 "@NewConnection_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, "NewConnection_1" );
SetTagChar( TAG_0, "IP,192.168.1.12,,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 );
}
return 1;
}
}

Post Reply