mycroes / Sally7

C# implementation of Siemens S7 connections with a focus on performance
MIT License
56 stars 22 forks source link

XML-comments #8

Closed SmackyPappelroy closed 3 years ago

SmackyPappelroy commented 3 years ago

Do think you can include the comments in the next release? Best regards!

scamille commented 3 years ago

@mycroes Can you add a XML comment to S7Connection constructor, giving a short example for setting up the connection parameters?

I understand that you don't want to add any additional layers on top of what the S7 protocol itself does, but I think that entry hurdle is a bit steep.

Or in other words: I need to know how to plug my S7 Type, Slot and Rack number into those TSAP objects :)

SmackyPappelroy commented 3 years ago

@scamille I tried it out a while ago. Here is a small code snippet I used to connect. "ConnectioStatus" is a selfmade enum, not included in Sally7

class Program { public static S7Connection S7Connection; public static ConnectionStatus ConnectionStatus;

static async Task Main(string[] args) { if (S7Connection is null) S7Connection = Sally7.Plc.ConnectionFactory.GetConnection("192.168.50.115", Sally7.Plc.CpuType.S7_1500, 0, 1);

        try
        {
            ConnectionStatus = ConnectionStatus.Connecting;
            await S7Connection.OpenAsync();
            ConnectionStatus = ConnectionStatus.Connected;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Lyckas ej ansluta: " + Environment.NewLine + ex.Message);
            ConnectionStatus = ConnectionStatus.Disconnected;
            Console.ReadLine();
        }

        if (ConnectionStatus == ConnectionStatus.Connected)
        {
            while (true)
            {
                DataBlockDataItem<float[]> dataBlockDataItem = new DataBlockDataItem<float[]>();
                dataBlockDataItem.DbNumber = 201;
                dataBlockDataItem.StartByte = 1004;
                dataBlockDataItem.Length = 3;

                await S7Connection.ReadAsync(dataBlockDataItem);
            }
        }
scamille commented 3 years ago

Thanks a lot! I didn't see the connection factory at all yesterday. With this I am sure that I can pull this off.

I guess I'll just offer what I learned here as a small "How to get started" example to the readme.

mycroes commented 3 years ago

I'll mention the ConnectionFactory in a comment as well.

mycroes commented 3 years ago

image

This is the comment from 0.9.0. Thanks for your comments guys!