Menu

Sharp7. Invalid buffer passed to Send/Receive.

jacken
2016-11-29
2019-11-26
  • jacken

    jacken - 2016-11-29

    Hi there, I'm a newbie when it comes to programming in C# with VS2015. I use S7-1200, all actions related with compability ( full acces, put/get, unchecked optimized block) were performed. The connection with PLC was made succesfully but i can't use other functions like DBRead. I'm always getting the same error as in the topic. I've made a simple DB in my PLC with 8 integer variables. Here's my very simple code:

    //-------------- Connection
                var client = new S7Client();
                int result = client.ConnectTo("192.168.0.1", 0, 0);
                if (result == 0)
                {
                    Console.WriteLine("Connected to 192.168.0.1");
                }
                else
                {
    
                   Console.WriteLine(result);
                   Console.WriteLine(client.ErrorText(result));
                   Console.ReadKey();
                   return;
                }
                //-------------- Read DB5
                Console.WriteLine("\n---- Read DB 5");
                int test1, test2, test3, test4, test5, test6, test7, test8;
                byte [] db5Buffer = new byte[16];
                result=client.DBRead(5, 0, 16, db5Buffer) ;
                test1 = S7.GetIntAt(db5Buffer, 0);
                test2 = S7.GetIntAt(db5Buffer, 2);
                test3 = S7.GetIntAt(db5Buffer, 4);
                test4 = S7.GetIntAt(db5Buffer, 6);
                test5 = S7.GetIntAt(db5Buffer, 8);
                test6 = S7.GetIntAt(db5Buffer, 10);
                test7 = S7.GetIntAt(db5Buffer, 12);
                test8 = S7.GetIntAt(db5Buffer, 14);
                if (result != 0)
                {
                    Console.WriteLine("Error: " + client.ErrorText(result));
                }
                Console.WriteLine("Test3: " + test3);
                Console.WriteLine("Test4: " + test4);
    

    So the question is what size of my Buffer should be? In my opinion 8 integers equal 16 bytes so do you have any idea what's wrong with the buffer?
    Regards,
    jacken

     

    Last edit: jacken 2016-11-29
  • Davide Nardella

    Davide Nardella - 2016-11-29

    Hi,
    maybe the message is wrong :(
    the issue is not related to your parameters but to the telegram received.

    could you insert a brekpoint at line 2217 of Sharp7.cs ?

                    SendPacket(PDU, Size_RD);
                    if (_LastError == 0)
                    {
                        Length = RecvIsoPacket();
                        if (_LastError == 0)      // <--Insert breakpoint here
                        {
                            if (Length<25)
                                _LastError = S7Consts.errIsoInvalidDataSize;
                            else
    

    I need to know the value of Length.
    And, if possible, the dump of PDU[] (only 100 bytes).

    Which firmware has your CPU ?

    Could you make the same test using ClientDemo.exe ? (you should download Snap7 package)

     

    Last edit: Davide Nardella 2016-11-29
  • jacken

    jacken - 2016-12-06

    Hello again,
    I had a short break so sorry for responding just now.
    I inserted the breakpoint as you mentioned and the value of Length is equal 19. So that's why this condition (Length<25) is true. I analyzed the RecvIsoPacket() method but couldn't find any solution for my problem. CPU firmware: 4.1.3. I made the same test with ClientDemo but when tried to use Data read/write option there was the following response: "CLI:function refused by CPU (unknown reason)". I don't know if that's what you mentioned about PDU dump but i made a screenshot of PDU when i used the breakpoint. Every byte after position 27 is equal 0. Any suggestions?

     
  • Davide Nardella

    Davide Nardella - 2016-12-07

    Hi,
    "Cli:CLI:function refused by CPU" is an error raised by S71200/1500 CPU when a client cannot access either due to "protocol not enabled" or DB optimized.

    Did you read this (the S71200/1500 chapter) ?
    http://snap7.sourceforge.net/snap7_client.html#target_compatibility

    DB must not be optimized.
    GET/PUT must be enabled.

    After the modifications remember to download the configuration into the PLC.

    I tested Sharp7 with a CPU whit the same firmware and works.

     
  • jacken

    jacken - 2016-12-07

    Omg, I didn't download the hardware configuration to my plc. That fixed my problems. Thank you

     
  • Chtitmaxou

    Chtitmaxou - 2019-10-17

    I know that this post is very old.
    But do you remember how you found a solution?
    Because i have exactly the same problem.
    Length is equal to 19, so i can't read anything...

    Thank you

     
    • muhammed kurt

      muhammed kurt - 2019-11-26

      Hi,
      I got rid of the same problem by applying what Davide Nardella suggested. In my case the error message was "Bad data size passed to send/recv buffer is invalid" and length was always 19. Follow instructions on the link http://snap7.sourceforge.net/snap7_client.html#target_compatibility if you have a S71200/1500 device.

      HTH

       
  • Chtitmaxou

    Chtitmaxou - 2019-11-26

    finalement j'ai du downgrader le firmware vers 1.8.2 (à partir du 1.8.3 ça ne marche pas)
    Merci quand-même

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.