Menu

sharp7 lirary input/outputs

2017-04-14
2017-04-14
  • Safa boumaiza

    Safa boumaiza - 2017-04-14

    hi, please i want some help, I wrote a simple code that have to write and read into a PLCsim (S71500) the I/O and the memory adress using sharp7 library and i used a block of cyclicintrrupt (OB30) / and timedelay(OB10) to repeat my function (just 50 times) , I tried at first to code it with multivars:
    i need to read I0.0//Q0.0// %MD0//%MD4,

    this what i found in the console application

    {Connected to PLC
    Error write: CPU : Function not available
    Error Read: ISO : Invalid PDU received }

    this is my code:

    {
    S7Client client = new S7Client();

            int result = client.ConnectTo("192.168.0.100", 0, 1);
            if (result == 0)
            {
                Console.WriteLine("Connected to PLC");
            }
    
            else
            {
                Console.WriteLine(client.ErrorText(result));
                return;
            }
             float y2;
             float x;
             bool Q,I;
             byte[] db1Buffer1 = new byte[10];
    
             TextWriter writer1 = new StreamWriter(@"C:\folder\saffae.txt");
    
               writer1.Write("les entrées        les sorties" );
               writer1.WriteLine ("");
                 // Write multivars  
                 var s7MultiVar = new S7MultiVar(client);
                 byte[]  db10 = new byte[10];
                 S7.SetBitAt(ref db10,0,0,true);
    
                 s7MultiVar.Add(S7Consts.S7AreaPE, S7Consts.S7WLBit, 0, 0, db10.Length, ref db10);
                 ;
    
                 int result0 = s7MultiVar.Write();
                 if (result0 != 0)
                 {
                     Console.WriteLine("Error: " + client.ErrorText(result0));
                 }
    
                 // Read multi vars
    
                 var s7MultiVar1 = new S7MultiVar(client);
                 byte[] db1 = new byte[1];
                s7MultiVar1.Add(S7Consts.S7AreaPE, S7Consts.S7WLBit, 0, 0, db1.Length, ref db1);
                byte[] db11 = new byte[1]
                s7MultiVar1.Add(S7Consts.S7AreaPA, S7Consts.S7WLBit, 0, 0, db10.Length, ref db11);
                byte[] db12 = new byte[8];  // i need tow real (%MD0 and %MD4)
                s7MultiVar1.Add(S7Consts.S7AreaMK, S7Consts.S7WLByte, 0, 0, db10.Length, ref db12);
                  int resultt = s7MultiVar1.Read();
                 if (resultt != 0)
                 {
                     Console.WriteLine("Error: " + client.ErrorText(resultt));
                 }
                  I = S7.GetBitAt(db1,0,0);
    
          if (I == true)
          {
              do
              {
                  x = S7.GetRealAt(db12, 10);
                  y2 = S7.GetRealAt(db12, 11);
                  Q = S7.GetBitAt(db11, 0, 1);
                  writer1.Write("\t" + x + "\t" + "||" + y2);
                  writer1.WriteLine("");
              }
    
              while (Q != true);
          }
           writer.Close();
          MessageBox.Show("saved");
          Console.ReadKey();
          }
              Please how can resolve it or code it inother ways??? ://
    
     
  • Davide Nardella

    Davide Nardella - 2017-04-14

    S7WLBit needs 1 as size, look at Snap7 reference manual.

     
  • Safa boumaiza

    Safa boumaiza - 2017-04-14
     

    Last edit: Safa boumaiza 2017-04-14
  • Safa boumaiza

    Safa boumaiza - 2017-04-14

    ok I'll take a look right now, thank you !! ^^

     
  • Safa boumaiza

    Safa boumaiza - 2017-04-14

    ok I'll take a look right now, thank you !! ^^

     
  • Safa boumaiza

    Safa boumaiza - 2017-06-15

    Hi Mr Nardella, i 'm actually able to read and write data with plcsim by the sharp7 library but i when i tried to use a real plc (1215C dc/dc/dc (new version)) the same error is shown for both the read and the write part ( error PDU passed to send/receive) , i configured the plc just like it mentionned on the documentation of the library..
    could you please tell me the cause of this error and how it could be fixed..
    please i'm waiting for your reply

     

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.