Sending floating point values from outstation

95 views
Skip to first unread message

Jay Desai

unread,
Jul 25, 2018, 7:27:06 PM7/25/18
to open-dnp3
Hello All,

I am very new to C# and DNP3 comms.
The task at hand is very simple.
The DNP3 Slave(outstation) sends floating point numbers to the master.
I have used C# example from the "dotnet" folder to establish a master.
For outstation, I have edited C# example to accept user entered data (which are float values) and pass them along to the master.

However, master only receives the integer part of that number.
I have used "OPC" client master as well but I get the same integer part of that number. Thus, I assume the issue is with the outstation code.

Example:
outstation analog value: 2.2
master value: 2

outstation analog value: 5.38
master value: 5

Code for outstation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Automatak.DNP3.Adapter;
using Automatak.DNP3.Interface;

namespace DotNetOutstationDemo
{
class Program
{
static int Main(string[] args)
{
IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, new PrintingLogAdapter());

var channel = mgr.AddTCPServer("server", 1, ChannelRetry.Default, "10.10.1.8", 50000, ChannelListener.Print());

var config = new OutstationStackConfig();

// configure the various measurements in our database
config.databaseTemplate = new DatabaseTemplate(4, 1, 1, 1, 1, 1, 1, 0);
config.databaseTemplate.binaries[0].clazz = PointClass.Class2;
// ....
config.outstation.config.allowUnsolicited = true;

// Optional: setup your stack configuration here
config.link.localAddr = 10;
config.link.remoteAddr = 1;

var outstation = channel.AddOutstation("outstation", RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, config);

outstation.Enable(); // enable communications

Console.WriteLine("Press <Enter> to change a value");
bool binaryValue = true;
double analogValue = 0;
while (true)
{
var enteredValue = Console.ReadLine();
var command = enteredValue.Split(',')[0];
var data = Convert.ToDouble(enteredValue.Split(',')[1]);
switch (command)
{
case ("x"):
return 0;
default:
{
if (data == 1.0)
{
binaryValue = true;
analogValue = 33333;
}
else
{
binaryValue = false;
analogValue = data;
}


// create a changeset and load it
var changeset = new ChangeSet();
changeset.Update(new Binary(binaryValue, 1, DateTime.Now), 0);
//changeset.Update(new Analog(analogValue, 3, DateTime.Now), 0);
//changeset.Update(new Analog(analogValue, 3, DateTime.Now), 65535);
changeset.Update(new Analog(analogValue, 3, DateTime.Now),65535);

outstation.Load(changeset);
}
break;
}
}
}
}
}

Any guidance is welcomed.

Thanks,
Jay.

Reply all
Reply to author
Forward
0 new messages