Coder Social home page Coder Social logo

s7netplus's Introduction

s7netplus

A .NET Library for Siemens S7 Connectivity

Overview

S7.Net Plus is a continuation of the work done on the S7.Net project by Juergen1969. I found the library simple and effective, but the project has languished unchanged since late 2009.

I was doing some automation work already and saw a few places where the code base could be improved. Because Juergen did not respond to my request for committing code, I decided to pick up where he left off here on GitHub.

Documentation

Check the Wiki and feel free to edit it: https://github.com/killnine/s7netplus/wiki

Supported PLC

  • Compatible S7 PLC (S7-200, S7-300, S7-400, S7-1200, S7-1500)

Supported frameworks

  • .NET Framework 4.5.2 and higher
  • .NET Standard 1.3 (.NET Core 1.0, UWP 10.0, Xamarin, ...)
  • .NET Standard 2.0 (.NET Core 2.0, .NET Framework 4.6.1)

Compile

You need at least Visual Studio 2017 (you can download the Community Edition for free).

Nuget

PM> Install-Package S7netplus

Latest build (Appveyor)

Build status https://ci.appveyor.com/project/mesta1/s7netplus

Running the tests

Unit tests use Snap7 server. On Windows, the DLL is included with the test project. On other platforms, Snap7 must be installed manually before running tests.

s7netplus's People

Contributors

abenedykt avatar argusmagnus avatar bonk-dev avatar chipsetsv avatar dagnutt avatar djwassink avatar falcogoodbody avatar gfoidl avatar himmelt avatar ismdiego avatar johnnyxy avatar killnine avatar lightbringor avatar marcosdvpereira avatar mbalous avatar mcpc10 avatar mesta1 avatar mycroes avatar rapha-dev avatar scamille avatar sevenmag avatar tatzemax avatar thoj avatar thomasbargetzkuenz avatar timverwaal avatar tomsoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

s7netplus's Issues

Problem with DB size bigger of 8200 byte

Hi team,
can you please let me know how we can read one DB with a size bigger of 8200 byte?

I read DB with ReadBytes(DataType.DataBlock, 1, 8200, 200);
I saw that the problem is by "package.Add(Types.Word.ToByteArray((ushort) ((startByteAdr)*8)));"

Best Regards

Continuous monitoring of isAvailable and isConnected

I am attempting to monitor the isAvailable and isConnected properties of the plc object using a timer running in a windows service.

The default of ping.send is a 1000ms timeout. My timer runs at 100ms to watch the plc connection and available properties. My plc logic runs on a 200ms timer so I want to be able to catch the lost connection between iterations of the plc logic.

I modified the isavailable property to use a shorter ping timeout value and so far testing seems to do okay with this but I am on a very short isolated network for testing. When I get to the warehouse to install this I worry that the distance between my panel and my server will be large enough to add in latency issues that may mess up my logic or create a near-race condition type of issue in the timer logic.

image

Can you suggest a better method of watching these properties? When you rely upon a plc connection in your own projects how do you handle it not being available? Since I am running a windows service I have no UI to alert my user of the issue. All I can do is log and continue looking or just stop the service.

S7-1500 Reading Datablocks - Always wrong # received bytes

I am converting a windows service which reads datablock values from a s7-300 to be able to work with s7-1500.

I am able to connect to the 1500 but each time I read from a datablock I receive back Errorcode.WrongNumberReceivedBytes.

Readbytes is called with **_(datablock, 10, 106, 2) _**and the bReceive[] response is always 19 bytes. Because the 21st byte is not 0xff I receive an errorcode that the wrong number of bytes was received and my read response is null. If I call the same exact thing on a s7-300 I get an object back from the readbytes call and am able to receive and store this integer value.

Do any of you use S7-1500 and datablocks with this library? Anything else I need to change? I read the maximum datablock size changed for 1500 and feel this is partially to contribute for the issue I am seeing.

Unit tests fail in x86 on .net 4.5.1 casting failures

doing baseline testing for Dev studio 2013, using .Net 4.5.1 and X86 and getting several failures on casting results. only passed T00_TestSelectBit and T01_WriteAndReadInt16Variable, all the rest failed.
changed PLC constructor to talk to a real S7-300
plc = new Plc(CpuType.S7300, "127.0.0.1", 0, 2); // all tests pass
//plc = new Plc(CpuType.S7300, "192.168.0.1", 0, 2); // failures happen

Is there something that I need to configure on the PLC

has this been tested with 4.5.1 on Dev Studio 2013?

Bug : Have to connect with TIA to use library

Hello there,

I use the library for a project with ~10 S7-1212C. It works nearly fine, but it stills a bug :
The connection with the PLC works only if I was connected with it by TIA Portal at less one time. This means not to reboot the computer or I have to launch and connect each time with TIA.

I actually don't know why. If you have an answer or the same problem, please let me know right here.

Thank you

PS : sorry for my poor english

ReadMultiVars

I was wondering if there is a way to read data from different location at once. Of course it is faster to prepare a DB or a UDT and read it in one go, but since I can't modify the current program of the PLC to achieve this I am looking for a quick way to read different locations.

The only options right now seems to use the Read methode repeatability but sadly enough that is too slow for my usecase, is there already something in place to do this?

Good job on the library it's very nice!

Profibus

Hallo Killnine,
I'm trying to make a connection through profibus cable to my s7 plc. Do you have any tips to make this work?

Greetings,
Roy Gerritse

This library has no support for String data type

This library has no support for String data type although it is defined as VarType. It is not possible to read or write class or structure containing string data. Am I wrong? There is no case in switch staments for "String" data type for converting from byte array to struct/class in source codes. Otherwise how?

Besides, comments documentation like this
///

    /// Gets the size of the struct in bytes.
    /// </summary>


    /// <param name="structType">the type of the struct</param>
    /// <returns>the number of bytes</returns>
    public static int GetClassSize(Type classType)

{....

should be corrected, because it is a class type not a struct type for
public static class Class

send/recive S7 project

Hy I'm quite new to S7 programming but we do a project in school which contains a S7-300. I have a CPU312C and a CP 343-1 LEAN. I tried to send an recive a struct but it didn't work. Do i have to use the FC6 and the FC5 in the S7 program to make it work?
Does anyone have an excample of an S7 program?
Please oversee any spelling or grammar mistakes, I usually speak German.
Thank you very much

PLC.IsConnected

PLC.IsConnected should be an Property like this:

public bool IsConnected
{ 
    get 
        { 
            if(_msocket != null)
            {
                return _msocket.Connected; 
            }
            else
            {
                return false;
            }
        } 
} 

VarType.Bit

Read Data with VarType.Bit is it not possible;

object data = plc.Read("M0.0");

This Type is not defined in the switch instruction on the method "public object Read(DataType dataType, int db, int startByteAdr, VarType varType, int varCount)"

Number of PLC variable read at same time

Hello everybody,
i use recently netplus for create an scada application under C#.So i want to know if i can create a polling program with a timer that poll for example 100 PLC variable at same time and display it in Windows form label.
The maximum bytes number that i what to read is 200 bytes.
What is the reliability of S7.NET for doing a something like that?
I never use this libray before i used SNAP7 library.
Thanks

GetClassSize return zero

Read class with four bool properties, for example, result on index out of range exception.
Adding, on Types.Class.GetClassSize before return, the code below works.
Just a workaround until bit types are pendent.

if (numBytes < 2 && properties.Any())
    numBytes = 2; 

Interface for PLC

Hi,
I can see that there is a branch where a interface for the PLC have been added.
Is it by any chance possible to get that interface on the master branch, as it will be much easier to mock the PLC for unit testing?

No license

Can you add a license to this software? I'm finishing an installer for my software that includes S7.NET+ and would like to have a license giving me the right to use this code :)

BTW - Jürgen was using a MIT License for his original work.

Ping IsDisposable

Im Sorry cant push pull request from here.

Ping is Disposable and should implement in using Statement:

        public bool IsAvailable
        {
            get
            {
                using (Ping ping = new Ping())
                {
                    PingReply result;

                    try
                    {
                        result = ping.Send(IPAdress);
                    }
                    catch (PingException)
                    {
                        result = null;
                    }

                    return result != null && result.Status == IPStatus.Success;
                }
            }
        }

ping.Send could be result in PingException so better use an try catch block

Reading / Writing DB1 block

Hi There !

I have done a few projects using this codebase and mostly it works pretty well. I have been able to read / write all tags with Markers So anything like MW20 or M5.3 is no problem. I have not been able to address Datablocks however. DB1.DBX.0.1 for example. I'm using a S71214. Is it an addressing issue on my part ? Could you possibly help me out ?

Kind Regards,
Fordirk

Can't get it to work with Logo!

Hello!

Is there anyone out there that has got it to work with Siemens Logo! ?
I've tried different setups but can't get it to work. I would be pleased with help with this!

Best regards
Daniel Blixt
Sweden

Reading Bool variable from DB

Hello,

please I am trying to read a Boolean variable from DB by using ( S7NETPLUS ) as in below method but I couldn't

try reading FIRST BIT DB1.DBX4.0

var VAR_byt = pl.Read(S7.Net.DataType.DataBlock, 1, 4, S7.Net.VarType.Byte,1);
byte[] x = VAR_byt as byte[];
x = new byte[7];
Console.WriteLine("db1.dbx4.0 = {0}", x[0].ToString());

i am kind of new in c# as well .

Thanks in advance.

Maher

Stability issue - wrong bytes WrongNumberReceivedBytes

I am using the library for continuous reading of data from 1200 PLC. Often I run into state, where I can not successfully open connection to the PLC because I keep getting wrong number of bytes in the first test.
_mSocket.Send(bSend1, 22, SocketFlags.None); if (_mSocket.Receive(bReceive, 22, SocketFlags.None) != 22) { throw new Exception(ErrorCode.WrongNumberReceivedBytes.ToString()); }

The problem is usually solved after some time and without my intervention. Any suggestion, what might be the issue?

Read Class Issue

While playing around I tried reading a DB into a class. The DB only had 2 boolean values. This caused the size measurement of the class to return 0 and it threw an exception for index being out of range.

I added this before numBytes is converted to int:

if (numBytes - Math.Round(numBytes) != 0) numBytes = Math.Ceiling(numBytes);

Is that an appropriate fix for a DB containing only boolean that is less or more than a byte?

`///

    /// Gets the size of the struct in bytes.
    /// </summary>


    /// <param name="classType">the type of the class</param>
    /// <returns>the number of bytes</returns>
    public static int GetClassSize(Type classType)
    {
        double numBytes = 0.0;       
        var properties = classType.GetProperties();
        foreach (var property in properties)
        {
            switch (property.PropertyType.Name)
            {
                case "Boolean":
                    numBytes += 0.125;
                    break;
                case "Byte":
                    numBytes = Math.Ceiling(numBytes);
                    numBytes++;
                    break;
                case "Int16":
                case "UInt16":
                    numBytes = Math.Ceiling(numBytes);
                    if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0)
                        numBytes++;
                    numBytes += 2;
                    break;
                case "Int32":
                case "UInt32":
                    numBytes = Math.Ceiling(numBytes);
                    if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0)
                        numBytes++;
                    numBytes += 4;
                    break;
                case "Float":
                case "Double":
                    numBytes = Math.Ceiling(numBytes);
                    if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0)
                        numBytes++;
                    numBytes += 4;
                    break;
                default:
                    numBytes += GetClassSize(property.PropertyType);
                    break;
            }
        }

        if (numBytes - Math.Round(numBytes) != 0)
          numBytes = Math.Ceiling(numBytes);

        return (int)numBytes;
    }`

Universal Windows Platform - How to?

Hi,

I tried S7.Net example and it just worked great, but i saw it is possible to run it also on a raspberry pi using UWP.
I found the S7.Net.Core project but i am not sure how to apply this.

I created a new project, copied the S7.Net.Core folder into the project folder and added it to the project. But i dont know how to continue :/

Read Limitations

Good morning,

I just started to study the library s7Net, but I noticed that there are limitations to read to a maximum of 222 bytes. Has anyone solved the problem, or knows why, while communicating via socket you have this problem?

thanks a lot
Best Regards

Push based change notification

Would it be possible (probably depends on hardware being used) to let the PLC send updates about register changes automatically to listeners?

As far as I know, if I want to monitor all the DB's in a PLC, we have to poll for the db values. So is there a way to turn this around? If so, could we implement such a 'listener'?

WrongVarFormat (WrongNumberReceivedBytes)

Hi,
I have an issue when trying to read from my S7 1212C PLC. When I try to read ANY variable, I get the error message "WrongVarFormat". When i go through the code i see, that the WrongNumberReceivedBytes exception is thrown.

public class S7_VARIABLE { public string ADDRESS; public object VALUE; public bool IS_DOUBLE; }

S_EST_IN = new S7_VARIABLE(); S_EST_IN.ADDRESS = "DB1.DBX0.0"; S_EST_IN.IS_DOUBLE = false;

public object READ_DB(S7_VARIABLE VAR) { if (VAR.IS_DOUBLE) { double result = ((uint)Convert.ChangeType(plc.Read(VAR.ADDRESS), typeof(uint))).ConvertToDouble(); return Math.Round(result, 3); } else { var bytes = plc.Read(VAR.ADDRESS); return (object)bytes; } }

Do you see where the issue is?

[S7-200]Reading information from the Variable Memory.

Hello.

I've noticed that there is no code in the library for reading information stored in the Variable Memory of the PLCs. I have done some research inside the code and noticed that when reading the memory, all you have to do is send an array of bytes through the comunnication socket, and then read the data sent back from the PLC.

I have the hypothesis that reading from the Memory is analog to reading from the Variable Memory. So the Array of bytes sent to the PLC must be just slightly different.

Does anyone know why the array of bytes, created in the ReadBytes() method have to have that format?
Where can I find documentation involving this kind of ethernet comunication with an S7200 PLC?

Thanks for reading.

Okalmas

Negotiated PDU Size

This is my modified Open-code which supports negotiated PDU size. The original code hardcodes an effective 222-byte PDU size (240-18). S7-400 supports 480-18 and I believe S7-1500 supports 960-18.
This code requests highest possible PDU size and PLC will respond with its highest supported size which is saved to the PDUSize property.

I am using this code successfully with 300 and 400 PLCs and I've briefly tested with 1500 but I don't remember if I got a 480 or 960 PDU.

PS. Sorry for posting code here instead of contributing :)

    public ErrorCode Open()
    {
        byte[] bReceive = new byte[256];

        if (OnlyConnectIfRespondsToPing && !Ping())
        {
            LastErrorCode = ErrorCode.IPAddressNotAvailable;
            LastErrorString = string.Format("Destination IP-Address '{0}' is not available!", IP);
            return LastErrorCode;
        }

        try {
            // open the channel
            if (_mSocket != null)
                _mSocket.Dispose();

            _mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            _mSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, ReceiveTimeout);
            _mSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, SendTimeout);

            IPEndPoint server = new IPEndPoint(IPAddress.Parse(IP), Port);
            IAsyncResult result = _mSocket.BeginConnect(server, null, null);
            result.AsyncWaitHandle.WaitOne(1000, true);
            if (!_mSocket.Connected)
                throw new TimeoutException();
        }
        catch (TimeoutException ex)
        {
            LastErrorCode = ErrorCode.ConnectionTimeout;
            LastErrorString = ex.Message;
            return ErrorCode.ConnectionError;
        }
        catch (Exception ex)
        {
            LastErrorCode = ErrorCode.ConnectionError;
            LastErrorString = ex.Message;
            return ErrorCode.ConnectionError;
        }

        try 
        {
            byte[] bSend1 = { 3, 0, 0, 22, 17, 224, 0, 0, 0, 46, 0, 193, 2, 1, 0, 194, 2, 3, 0, 192, 1, 9 };
            // 0 = version number (for S7 communication always 0x03) 
            // 1 = reserved (always 0x00) 
            // 2-3 = size of ISO-TCP message (including this header) in byte 
            // 4 = length (in byte) of TPDU header  (without this byte and possible user data)
            // 5 = CR code (1110) & credit (always 0000)
            // 6-7 = destination reference 
            // 8-9 = source reference 
            // 10 = class option (always class 0)
            // 11 = 0xC1 (code: calling TSAP-ID) 
            // 12 = 0x02 (number of bytes following)
            // 13 = 0x02 (unknown function; part of TSAP-ID)
            // 14 = TSAP-ID (rack & slot) 
            // 15 = 0xC2 (code: called TSAP-ID)
            // 16 = 0x02 (number of bytes following)
            // 17 = 0x02 (unknown function; part of TSAP-ID)
            // 18 = TSAP-ID (rack & slot)
            // 19 = 0xC0 (code: TPDU size)
            // 20 = 0x01 (number of bytes following)
            // 21 = TPDU size (as exponent to base of 2)

            switch (CPU) {
                case CpuType.S7200:
                    //S7200: Chr(193) & Chr(2) & Chr(16) & Chr(0) 'Eigener Tsap
                    bSend1[11] = 193;
                    bSend1[12] = 2;
                    bSend1[13] = 16;
                    bSend1[14] = 0;
                    //S7200: Chr(194) & Chr(2) & Chr(16) & Chr(0) 'Fremder Tsap
                    bSend1[15] = 194;
                    bSend1[16] = 2;
                    bSend1[17] = 16;
                    bSend1[18] = 0;
                    break;
                case CpuType.S7300:
                    //S7300: Chr(193) & Chr(2) & Chr(1) & Chr(0)  'Eigener Tsap
                    bSend1[11] = 193;
                    bSend1[12] = 2;
                    bSend1[13] = 1;
                    bSend1[14] = 0;
                    //S7300: Chr(194) & Chr(2) & Chr(3) & Chr(2)  'Fremder Tsap
                    bSend1[15] = 194;
                    bSend1[16] = 2;
                    bSend1[17] = 3;
                    bSend1[18] = (byte)(Rack * 2 * 16 + Slot);
                    break;
                case CpuType.S7400:
                    //S7400: Chr(193) & Chr(2) & Chr(1) & Chr(0)  'Eigener Tsap
                    bSend1[11] = 193;
                    bSend1[12] = 2;
                    bSend1[13] = 1;
                    bSend1[14] = 0;
                    //S7400: Chr(194) & Chr(2) & Chr(3) & Chr(3)  'Fremder Tsap
                    bSend1[15] = 194;
                    bSend1[16] = 2;
                    bSend1[17] = 3;
                    bSend1[18] = (byte)(Rack * 2 * 16 + Slot);
                    break;
                //case CpuType.S71200:
                case CpuType.S71500:
                    // Eigener Tsap
                    bSend1[11] = 193;
                    bSend1[12] = 2;
                    bSend1[13] = 0x10;
                    bSend1[14] = 0x2;
                    // Fremder Tsap
                    bSend1[15] = 194;
                    bSend1[16] = 2;
                    bSend1[17] = 0x3;
                    bSend1[18] = 0x0;
                    break;
                default:
                    return ErrorCode.WrongCPU_Type;
            }


            //Console.WriteLine("> " + string.Join(" ", bSend1.Select(b => b.ToString("x2"))));
            _mSocket.Send(bSend1, 22, SocketFlags.None);
            int receiveCount = _mSocket.Receive(bReceive, 22, SocketFlags.None);

            /*
            0-3 ISO-TCP header 
            4 length (in byte) of TPDU header (without this byte and possible user data) 
            5 CC code (1101) & credit (always 0000) 
            6-7 destination reference 
            8-9 source reference 
            10 class option (always class 0) 
            11 0xC0 (code: TPDU size) 
            12 0x01 (length of bytes following) 
            13 TPDU size (as exponent to base of 2) 
            14 0xC1 (code: calling TSAP-ID) 
            15 0x02 (length of id) 
            16 0x02 (unknown function; part of TSAP-ID) 
            17 TSAP-ID (rack & slot) 
            18 0xC2 (code: called TSAP-ID) 
            19 0x02 (length of id) 
            20 0x02 (unknown function; part of TSAP-ID) 
            21 TSAP-ID (rack & slot) 
             * 
             * More about data structurs can be found on http://www.bj-ig.de/147.html
            */

            //Console.WriteLine("< " + string.Join(" ", bReceive.Take(receiveCount).Select(b => b.ToString("x2"))));
            //Console.WriteLine("PDU: " + bReceive[13] + " (" + Math.Pow(2, bReceive[13]) + ")");
            if (receiveCount != 22)
            {
                throw new Exception(ErrorCode.WrongNumberReceivedBytes.ToString());
            }

            byte[] bsend2 = { 3, 0, 0, 25, 2, 240, 128, 50, 1, 0, 0, 255, 255, 0, 8, 0, 0, 240, 0, 0, 3, 0, 3, 0x3, 0xC0 };
            //Console.WriteLine("> " + string.Join(" ", bsend2.Select(b => b.ToString("x2"))));
            _mSocket.Send(bsend2, 25, SocketFlags.None);
            receiveCount = _mSocket.Receive(bReceive, 27, SocketFlags.None);
            //Console.WriteLine("< " + string.Join(" ", bReceive.Take(receiveCount).Select(b => b.ToString("x2"))));
            if (receiveCount == 27)
            {
                PDUSize = IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(bReceive, 25));
            }
            else
            {
                //Console.WriteLine("< " + string.Join(" ", bReceive.Select(b => b.ToString("x2"))));
                throw new Exception(ErrorCode.WrongNumberReceivedBytes.ToString());
            } 
        }
        catch 
        {
            LastErrorCode = ErrorCode.ConnectionError;
            LastErrorString = string.Format("Couldn't establish the connection to {0}!", IP);
            return ErrorCode.ConnectionError;
        }

        return ErrorCode.NoError;
    }

Start / stop CPU

Is it possible to stop / start a SIMATIC CPU programmatically using this library, or could that be implemented?

Connection error on valid Ip Address

Hello!
I have a problem regarding establishing a connection with a S7-1500. Whenever I attempt a connection (no data sent/received, just connect to the right IP Address), the method returns the error "ConnectionError".
I've tried debugging the code to understand the issue, but I cannot get any more information. The most I could find out was that the error returned from the connect method specifies "Message: An existing connection was forcibly closed by the remote host".
I've made the necessary settings in TIA Portal v13 to allow full access and allow PUT/GET requests.
Also, when I try connecting to a wrong IP Address, I get the error that the IP Address doesn't exists, and I can ping the correct Address, so there is a connection between the PLC and my computer. The problem is only that I cannot establish a connection between my program and the PLC.

Thank you very much!

*EDIT: I've fixed the isssue. The CPU slot was on 1 and in the code I specified it was 2. Fixed it and now it is working (duh).

Problem with S7-312C with CP343-1 Lean

Hi!

I have used S7.Net for several projects now and it works great.

But now I have a project where I need to communicate with a 312C equipped with a CP313-1 Lean card (tried both version 2.2 and a 3.0 card), and I cant get it to work.

When I try with the example I only get "ERROR: Device is available but connection was unsuccessful!". I cant find any problem in the setup for the CP-card or CPU.

If I try with our HMI-software that we normally use (Beijer iX) the communication works great with the CPU.

Any ideas?

Reading Boolean and String

I have string and bool values inside of a datablock and am unable to read them. The read method accepts an integer byte offset but my string and bool values are decimal based offsets. How do I read these?

s7netplus strings and bools

Duplicated code and S7.Net.Core

I would like to unify the source files and use #ifdef NETFX_CORE to check if use the .Net socket or the custom one.
Also we can use #ifdef to define the correct behaviour for the properties IsAvailable and IsConnected.
Any idea ?

Performance estimate?

Sorry to post here but did not find anywhere to post general questions.

Anyway, do you have an estimate on how long a read cycle and write cycle of a byte in the PLC will require? Does it vary a lot and if so do you have any ideas as to why?

I am currently using a OEM library from Siemens to read and write to the PLC but the communication speed is not that good. We are using a Sinumerik system (I have pretty poor knowledge on the PLC/NC side of things but I can specify in detail if needed) which isn't as fast as we'd like it to be. We have used S7.net prior for test-purpose so I know it is possible to use it for our system. Just wanted to know what to expect before starting to investigate any further on my own.

Missing method ClearLastErrorCode

Currently once the LastErrorCode is set e. g. because of a read error you have to disconnect and connect again to continue.

I would like to poll different variables from the S7 plc periodically and avoid to reconnect after a bad ReadBytes call. Is it possible to add a ClearLastErrorCode method for that? Thank you!

Reading from address higher than 8096

Hi,

I am trying to read a data from a DB on S7-1200 station. I ran into problem and so far wasn't able to solve it. Apparently there is some problem, when I am reading data from position higher then 8096. Is it possible or am I doing something wrong?

ushort address = (ushort) (StackAdress + 2*RecPtr); var o = _plc.Read(DataType.DataBlock, DataBlockIndex,address, VarType.Int, RecSize);¨

Thanks,
Martin.

ReadMultipleVars issue

Reading multiple USInt vars only the first one read ok.
Adding the code bellow fix my problem, but not sure if it is the right solution.

PLC.ReadMultipleVars(List):

int offset = 25;
foreach (var dataItem in dataItems)
{
    int byteCnt = VarTypeToByteLength(dataItem.VarType, dataItem.Count);
    byte[] bytes = new byte[byteCnt];

    for (int i = 0; i < byteCnt; i++)
    {
        bytes[i] = bReceive[i + offset];
    }

    offset += byteCnt + 4;

    //this code
    if (byteCnt == 1)
        offset++;

    dataItem.Value = ParseBytes(dataItem.VarType, bytes, dataItem.Count);
}

Issues on Read / Write S71200

Hi, i have a problem.
I have a problem on reading / writing on S71200.
For example Read: on S7300 the method Read("DB5.DBW2") address the communication on datablock 5, db word 2... and it works sugar,

S71200 works differently becouse i have not address but memory names...so i'm not able to find a correct addressing.
Like: i have DB5 with named: int_0, int_1 (integers) ... how to read them with S71200?? i get always WrongVarExecption using Read("DB5.int_0")

WrongVarFomat

Hi,

I have already used the old s7 library in the past and worked really fine.
Now we are going to connect to an s7-1200 plc and with this library it connects just fine.
The problem occurs when i try to read from the plc.

The var location is : DB1.DBW2
C# code: object s = plc1.Read("DB1.DBW2");
And i get WrongVarFormat.

Can you please help me out. Is there something new in this version that maybe i am missing?

Regards,

Universal Windows Platform support (iot)

Hi

I already test this lib on windows 10 x32, work very nice, but on windows 10 core (raspberry pi) don't allow me to install it by nuget.

It's possible to build an uwp version?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.