writeBytes returning -1025 using LibNoDave

libnodave dll c#
s7 net

I have a weird problem with my Connection from C# to my Simatic S7-1200. I am using LibNoDave to connect and i want to set bits of my SPS with the C#-program. This is working just fine but it only works 9 times and then the writeBytes(..) function returns -1025 and not 0 as it should and it is not setting the byte anymore. I then have to restart the application and it will work 9 times again.

This is my LibNoDave class.

static class LibNoDave
{

    static libnodave.daveConnection dc;
    static bool connection = false;

    public static bool CreateConnection()
    {
        const string IP = "192.168.1.250";
        const int Rack = 0;
        const int Slot = 0;
        libnodave.daveOSserialType fds;
        libnodave.daveInterface di;

        try
        {
            fds.rfd = libnodave.openSocket(102, IP);
            fds.wfd = fds.rfd;

            if (fds.rfd > 0)
            {
                di = new libnodave.daveInterface(fds, "IF1",
                              0, libnodave.daveProtoISOTCP,
                              libnodave.daveSpeed187k);

                di.setTimeout(1000000);
                int res = di.initAdapter();
                if (res == 0)
                {

                    dc = new libnodave.daveConnection(di, 0,
                                                       Rack, Slot);
                    res = dc.connectPLC();
                    if (res == 0)
                    {
                        connection = true;
                        return true;
                    }
             }
        }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        return false;
    }


    public static void DisconnectPLC()
    {
        if (connection)
        {
            dc.disconnectPLC();
            libnodave.closeSocket(102);
            connection = false;
        }

    }

    public static void WritePLC(int anfangswert, byte wert)
    {
        if (connection)
        {
            byte[] buf = new Byte[1];
            buf[0] = wert;
            int res = dc.writeBytes(libnodave.daveFlags, 0, anfangswert, 1, buf);
            MessageBox.Show(res.ToString());
        }

    }
}

Here I am calling the functions:

private void frmAuslagerung_Load(object sender, EventArgs e)
    {
        if (!LibNoDave.CreateConnection())
        {
            finished = true;
            this.Close();
        }

        LibNoDave.WritePLC(1, Byte.Parse(auto.Position.Lade.ToString()));

    }

    private void frmAuslagerung_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!finished)
        {
            //e.Cancel = true; //Not in code for testing
            LibNoDave.DisconnectPLC(); //Only for testing
        }            
        else
            LibNoDave.DisconnectPLC();
    }

I don´t see any problem in code and I don´t know neither your device nor LibNoDave, but the problem may be related to:

1- Is some receiver an "One single digit" (like 0 to 9) address or container ?

2- The position is being truly reseted as I see in WritePLC function?

3- The "LibNoDave.WritePLC" is incrementing its pointer?

Good luck.

VB.Net – exchange data with Siemens PLC, You need copy libnodave.net.dll file in the your PC and add references in the VB. NET project writeBytes(libnodave.daveFlags, 0, 4, 4, buf) When I disconnect cable and connect again communication return, but not always. Sometimes I� C# (CSharp) libnodave.resultSet - 2 examples found.These are the top rated real world C# (CSharp) examples of libnodave.resultSet extracted from open source projects. You can rate examples to help us improve the quality of examples.

it can be problem closing the connection try with:

    public static void DisconnectPLC()
    {
        if (connection)
        {
          dc.disconnectPLC();
          di.disconnectAdapter();
          libnodave.closePort(fds.rfd);
          connection = false;
         }
}

Using LibNoDave libraries in Android, always receive 0 from PLC , Your problem is the slot in 1200 slot=1 in s7-300 and 400 slot=2. I was looking to some C# examples for libnodave and you're using same system in your code. I think that will be important for you to check values of 'return' variables, then you can better check if some commands are working ok.

It's old, but for others to find: in my case it was the declaration of fds and di: they had to be class members and not local to the connect method, or the timeout value was being lost later on.

Someone with a Siemens S7 1200 who wants to test ? [Text], If you have the time, could you test this program in communication with the S71200 ? Mashing together Advanced HMI and Libnodave was my one and only writeBytes(libnodave. Print("Return from Write = {0:d}", result)� I am using LibNoDave to connect and i want to set bits of my SPS with the C#-program. This is working just fine but it only works 9 times and then the writeBytes(..) function returns -1025 and not 0 as it should and it is not setting the byte anymore. I then have to restart the application and it will work 9 times again. This is my LibNoDave class.

libnodave.daveConnection.readBytes C# (CSharp) Code Examples , These are the top rated real world C# (CSharp) examples of libnodave. disconnectAdapter(); // does nothing in ISO_TCP. But call it to WriteLine(" Couldn't open TCP connaction to "+args[0]); return -1; } return 0; } writeBytes( libnodave. Stack Overflow Public questions and answers; Teams Private questions and answers for your team; Enterprise Private self-hosted questions and answers for your enterprise; Jobs Programming and related technical career opportunities

libnodave communication C# and PLC - Entries - Forum, I have some problem with C# project and plc simulator SIEMENS. Therefore use that checks after every return of command like in examples� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Help with the libnodave library [Archiv], Hi, I am new in this forum, as I am new at using libnodave and C++. could help me figure out how to use the writebytes class to write into a S7-300's Datablocks. but my output does not change the values, it returns this: C# (CSharp) libnodave.daveConnection.stop - 1 examples found. These are the top rated real world C# (CSharp) examples of libnodave.daveConnection.stop extracted from open source projects. You can rate examples to help us improve the quality of examples.

Comments
  • 1 - The Byte that I am setting with the address 1 is of the datatype byte and it's value should always jsut be overridden by the buf byte array. That is working 9 times. Not sure if that is what you meant. 2- What position do you mean? 3- Not sure how i check that and would it be a problem?
  • @LukasN., the fact of the program crashes after 9 times can be related in the space 0 to 9 (one single digit) utilized in SOME variable or in SOME position. It´s too specific the routine crashes after 9 times, since the 10th will require 2 digits (if in a decimal notation, not BYTE notation). Are you sure about the number be a byte (or informed as a byte) and not a BCD or decimal?
  • Ops! You mentioned above "...returns -1025 and not 0 as it should and it is not setting the bit anymore.". Are you working with bits? Remember: 9 times can be interpreted as bit 0 to bit 7 (8 times) + 1... And after this, if the space is really ONE byte, we have only 8 bits, so your program may be writing each bit position in an incremented way until try the 9th bit...
  • Sry, I acutally meant to write byte there since it is definitely writing the full byte. The values That I am setting are between 1 and 100 and it is working so it should be bytes.
  • Thanks anyways :) Maybe I find out tomorrow