Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

frame length not plausible #5

Open
rekkel opened this issue Jul 19, 2019 · 0 comments
Open

frame length not plausible #5

rekkel opened this issue Jul 19, 2019 · 0 comments

Comments

@rekkel
Copy link

rekkel commented Jul 19, 2019

hello,

My analyzer says that the
'frame length not plausible"

is this a known problem?

using System;
using System.IO;
using System.ServiceProcess;
using System.Text;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using IEC60870.SAP;
using IEC60870.Enum;
using IEC60870.IE;
using IEC60870.IE.Base;
using IEC60870.Object;
using System.Timers;

namespace FPL104Service
{
public partial class FPL104Service : ServiceBase
{

    System.Timers.Timer timer = new System.Timers.Timer();

    MqttClient client;
    string clientId;

    string BrokerAddress = "127.0.0.1";
    
    private ServerSAP server;

    private int cnt = 1;

    public FPL104Service()
    {
        InitializeComponent();

 


    }

    protected override void OnStart(string[] args)
    {
        try
        {
            WriteToFile("Start 104 server " + DateTime.Now);
            //104 start en settings
            server = new ServerSAP("127.0.0.1", 2404);
            server.StartListen(10);
            
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            WriteToFile("Cannot start 104 rtu " + DateTime.Now);
        }


        WriteToFile("Service is started at " + DateTime.Now);
        timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
        timer.Interval = 5000; //number in milisecinds  
        timer.Enabled = true;

        client = new MqttClient(BrokerAddress);

        // register a callback-function (we have to implement, see below) which is called by the library when a message was received
        client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

        // use a unique id as client id, each time we start the application
        clientId = Guid.NewGuid().ToString();

        client.Connect(clientId);

        string Topic = "FPL104/Test";

        // subscribe to the topic with QoS 2
        client.Subscribe(new string[] { Topic }, new byte[] { 2 });





        // this code runs when a message was received
        void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string ReceivedMessage = Encoding.UTF8.GetString(e.Message);
            WriteToFile(ReceivedMessage);
            



        }

    }


    protected override void OnStop()
    {
        WriteToFile("Service is stopped at " + DateTime.Now);
        client.Disconnect();

    }

    private void OnElapsedTime(object source, ElapsedEventArgs e)
    {
        WriteToFile("Service is recall at " + DateTime.Now);
        InformationElement ielem_value1;
        if (cnt == 1)
        { 
            ielem_value1 = new IeShortFloat(1);
            
            cnt = 0;
        }
        else
        {
            ielem_value1 = new IeShortFloat(0);
            cnt = 1;
        }
        WriteToFile("Service is recall at " + cnt +" " + DateTime.Now);
        InformationElement ielem_quality1 = new IeQuality(false, false, false, false, false);
        InformationElement[][] ielem1 = new InformationElement[1][] { new InformationElement[2] { ielem_value1, ielem_quality1 } };
        InformationObject[] iobj1 = new InformationObject[1] { new InformationObject(1, ielem1) };
        ASdu asdu2 = new ASdu(TypeId.M_ME_NC_1, false, CauseOfTransmission.SPONTANEOUS, false, false, 1, 1, iobj1);
        //                                                                               common address,  IOA
        server.SendASdu(asdu2);


    }

another question. How do i set the iec time ?

I hope you can help me.

greets Rick

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant