Interfacing PLC - PC via ethernet using c# - environment .NET

Declarations in the Class

// libnodave communication channels

public libnodave.daveOSserialType fd
// libnodave interface settings

public libnodave.daveInterface di;
///
/// libnodave connection structure
///

public libnodave.daveConnection dc;
// Rack and Slot are part of the PLC Hardware configuration
// we do not need to change this, since all our PLCs are built
// wuth this standard setup

private const int RACK = 0;

private const int SLOT = 2;

// The TCP port for talking “ISO over TCP” to the PLC
private const int TCP_PORT = 102;

public void connect()
{
//Connection
fds.rfd = libnodave.openSocket(TCP_PORT, myPLC.IP);
fds.wfd = fds.rfd; // read and write-channels are the same
if (fds.rfd == 0)
{
//if error, do somenthing
}
if (fds.rfd != 0) // continue only if openSocket was ok
{

// initialise interface di = new libnodave.daveInterface(fds, “IF1″, 0, libnodave.daveProtoISOTCP, libnodave.daveSpeed187k);

di.setTimeout(200*1000); // comunication timeout in microseconds
di.initAdapter();

// initialise and establish connection

dc = new libnodave.daveConnection(di, 0, RACK, SLOT);
result = dc.connectPLC();


if (result != 0)
{
//if error, do somenthing
}

}}

Read 10319 times Last modified on Domenica, 20 Aprile 2014 22:20

socialshare

share on facebook share on linkedin share on pinterest share on youtube share on twitter share on tumblr share on soceity6