Lib usage

WARNING: i'm not going to cover IEC103 reference. Buy the documents and study!

This is not a real library. You have to drop in the source code in your project.
At first, the library makes all communication throught an abstract class, that must be derived in order to get it working.
Usually communicaton happens on a serial port. However, is very usual to use serial gateway converter that have to work on ethernet Tcp port.
Based on your need, create a CommunicationPort implementation that fits your use.

The .NET binding contains a simple SerialCommunicationPort implementation. You can use it as start point. Here is the code.

#pragma once
#include "communicationport.h"
#include <Windows.h>

class SerialCommPort :
	public CommunicationPort
{
public:
	SerialCommPort(string name)
	{
		port = CreateFile(name.c_str(),GENERIC_READ|GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0);
		if (port == NULL)
		{

		}

	}
	virtual int Read(unsigned char* thePacket, int maxlen)
	{
		DWORD dw;
		ReadFile(port,thePacket,maxlen,&dw,0);
		return dw;
	}

	virtual int Write(unsigned char* thePacket, int len)
	{
		DWORD dw;
		WriteFile(port,thePacket,len,&dw,0);
		return dw;
	}

	virtual ~SerialCommPort(void)
	{
		if (port != NULL)
			CloseHandle(port);

		port = NULL;
	}

private:
	HANDLE port;
};


Once you have got your code working, you should usual start with a StationInit function (see IEC103 reference) and then enter into the loop and start grabbing messages from protection using the GetNextAsdu function

Then you are able to manage the message, get your data and respond, if needed, to the protection.

Last edited Sep 21, 2013 at 9:22 PM by XVincentX, version 3