de:project_s7:modbus_intensisbox_s7_1500

Differences

This shows you the differences between two versions of the page.

de:project_s7:modbus_intensisbox_s7_1500 [2022/04/21 15:01] ()
 1:  1:
 +====== Simatic S7-1500 - IntesisBox Modbus Kommunikationsprogramm ======
 +{{:de:project_s7:uk.png?16|english}} Simatic S7-1500 - IntesisBox Modbus communication program \\
 +
 +{{:de:project_s7:de.png?16|deutsch}} Das Programm kommuniziert mit der **intesisBox** und **S7-1500** über **Modbus**. Der **intesisBox Modbus-Server** besteht aus Modbus-Modulgruppen, eine Modulgruppe ist auf 22 Wörter festgelegt. Die Anzahl der zu lesenden Gruppen kann parametriert werden.
 +
 +Da das Programm die Modbus-Blöcke einzeln abfragen muss, ist die Aktualisierungszeit ziemlich langsam (bis zu 40-50 Sekunden). Aber zumindest funktioniert es.
 +
 +Die aktuelle Version von Das Programm liest pro Block zwei Parameter aus der intesisBox:
 +(Der Bereich der Lesesignale kann auf alle 22 Parameter erweitert werden.)
 +
 + - Fehlerstatus (0: ok, 1: Fehler)
 + - Kommunikationsfehlergruppe (0: ok, 1: Fehler)
 +
 +Die gelesenen Fehlersignale sind in der DB //"intesisDB"// im Format //"Bool"// zusammengefasst.
 +
 +**Wichtig!** Das Programm verwendet die direkte Adressierung in der //"intesisDB"//, daher muss der Parameter //DB-Eigenschaften / Attribute / Optimierter Blockzugriff// deaktiviert werden, da sonst KEINE Fehlermeldungen angezeigt werden.
 +
 +**Wichtig!** Bitte überprüfen Sie auch den Parameter "nrOfIntesisDB"!
 + 
 +Nach der Installation stürzt das Programm manchmal beim ersten Start ab. In diesem Fall muss die SPS (Stop-Run) neu gestartet werden.
 +
 +Das Programm wurde mit **TIA Portal 16** getestet. 
 +
 +{{:de:project_s7:uk.png?16|english}} The program communicates with the **S7-1500** and **intesisBox** via **modbus**. The intesisBox modbus-server consists of modbus module groups, a module group is fixed at 22 words. The number of groups to be read can be parameterized.
 +
 +Because the program has to query the modbus blocks one by one, the update time is quite slow (up to 40-50s). But at least it works.
 +
 +The current version of The program reads two parameters from the intesisBox per block:
 +(The range of read signals can be expanded up to all 22 parameters)
 +
 + - error status (0: ok, 1: error)
 + - Communication error Group (0: ok, 1: error)
 +
 +The readed error signals are summarized in The //"intesisDB"// DB in //"Bool"// format.
 +
 +**Important!** The program uses direct addressing in the //"intesisDB"//, so the //DB Properties / Attributes / Optimized block access parameter// must be switched off, otherwise it will NOT display error messages.
 +
 +**Important!** Please check //"nrOfIntesisDB"// parameter, too!
 + 
 +After installation, the program sometimes crashes during the first start-up, in which case The PLC (stop-run) must be restarted.
 +
 +|{{ :de:project:intesis_01.png?250 |}}|{{ :de:project:intesis_02.png?250 |}}|{{ :de:project:intesis_03.png?250 |}}|
 +|Simatic S7-1500 - IntesisBox Modbus Kommunikation|LinkBoxMB zeigt Kommunikation|Kommunikationssicht in TIA 16|
 +
 +
 +<WRAP center round download 80%>
 +**SCL-Programm download:** {{ :de:project:intesisprgv10.scl |intesisPrgv10.scl}} \\ \\ 
 +Der Quellcode enthält eine Beschreibung eines scl-Codes und einer Datenbank (siehe Quellcode unten). Der Code kann im TIA-Portal geöffnet und übersetzt werden.
 +</WRAP>
 +
 +From file (from 2020.10.30) **{{dlcounter>file?de:project_s7:intesisPrgv10.scl}}** downloads.
 +
 +<hidden Klicken Sie hier, um den Code anzuzeigen - Click here to view the code>
 +<code pascal>
 +FUNCTION_BLOCK "call_modbus_intesis"
 +{ S7_Optimized_Access := 'TRUE' }
 +VERSION : 0.1
 +   VAR 
 +      nrOfReadGroup : Int := 23;   // number of group of read from Intesis
 +      nrOfIntesisDB : ULInt := 1;   // DB Number of intesisDB
 +      modbusParameters {InstructionName := 'TCON_IP_v4'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TCON_IP_v4 := (64, 16#1, 16#0B, TRUE, ([16#C0, 16#A8, 16#00, 16#5F]), 502, 503);
 +      mbIntesis {InstructionName := 'MB_CLIENT'; LibVersion := '4.1'} : MB_CLIENT;
 +      tme {InstructionName := 'TON_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TON_TIME;
 +      tmeQ { S7_SetPoint := 'True'} : Bool;
 +      tmeChg { S7_SetPoint := 'True'} : Bool;
 +      pos : Int := 1;
 +      rec : Array[0..22] of Word;
 +      addr : LInt := 30113;
 +      step : Int := 0;
 +      busy : Bool;
 +      read : Bool;
 +      stepTm4 {InstructionName := 'TON_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TON_TIME;
 +      stepTm6 {InstructionName := 'TON_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TON_TIME;
 +      tm4Q { S7_SetPoint := 'True'} : Bool;
 +      byteOffset : Int;
 +      bitOffset : Int;
 +      offset : Int;
 +      bit1 : Bool;
 +      bit2 : Bool;
 +   END_VAR
 +
 +   VAR_TEMP 
 +      done : Bool;
 +      error : Bool;
 +      status : Word;
 +      no : Bool;
 +      tempw : Word;
 +      rest : Time;
 +   END_VAR
 +
 +
 +BEGIN
 + // Simatic S7-1500 - IntesisBox Modbus communication program
 + // Sándor Vámos / 2020
 + // 
 + // The program communicates with the intesisBox via modbus. The intesisBox modbus-server consists of
 + // modbus module groups, a module group is fixed at 22 words.
 + // The number of groups to be read can be parameterized (see below)
 + // 
 + // Because the program has to query the modbus blocks one by one,
 + // the update time is quite slow (up to 40-50s). But at least it works.
 + // 
 + // The current version of The program reads two parameters from the intesisBox per block:
 + // (The range of read signals can be expanded up to all 22 parameters)
 + // 
 + // - error status (0: ok, 1: error)
 + // - Communication error Group (0: ok, 1: error)
 + // 
 + // The readed error signals are summarized in The "intesisDB" DB in "Bool" format.
 + // 
 + // Important! The program uses direct addressing in the "intesisDB", so the
 + // DB Properties / Attributes / Optimized block access parameter must be switched off,
 + // otherwise it will NOT display error messages.
 + // 
 + // Important! Please check "nrOfIntesisDB" parameter, too!
 + // 
 + // After installation, the program sometimes crashes during the first start-up,
 + // in which case The PLC (stop-run) must be restarted.
 + //     
 + //     ------- Parameters TO be set -------------------
 + //     
 + //     #nrOfReadGroup (Int, def: 23): Number OF Intesis blocks to Read (cf. number of climas)
 + //     #nrOfIntesisDB (ULInt, def:1, -> DB1): Number of generated DB, see: intesisDB[DBxx]      
 + //     #addr (LInt, def: 30113): Start address for read from IntesisBox (113: first error status)
 + //     #modbusParameters.InterfaceId (HW_ANY, def: 64): modbus HW module ID
 + //     #modbusParameters.RemoteAddress.ADDR (def: C0, A8,00,5F - 192.168.0.95): intesisBox IP
 + //     #modbusParameters.RemoteAddress.RemotePort (def: 502): The modbus PORT OF The intesisBox
 + //     #modbusParameters.RemoteAddress.RemotePort (def: 502): modbus PORT OF The Simatic S7
 +
 +
 +
 + // Steps for state-machine for read:
 + // step0: init; est:0, pos:1
 + // step1 : set ID, addr
 + // step2 : est 0-> 1
 + // step3: wait for busy
 + // step4: wait for end of busy
 + // step5: copy data
 + // step6: est 1-> 0
 + // step7: next pos
 + // 
 +
 + #stepTm4(IN := (#step = 4),  // waiting time in step 4
 +          PT := t#1s,
 +          Q => #tm4Q,
 +          ET => #rest);
 +
 + #stepTm6(IN := (#step = 6), // waiting time in step 6
 +          PT := t#200ms,
 +          ET=>#rest);
 +
 + IF #step = 0 THEN   // first step (only by newstart): init
 +     #read := FALSE;
 +     #modbusParameters.ActiveEstablished := FALSE;  // ActiveEstablished lock
 +     #pos := 1;
 +     #step := 1;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 1 THEN  // step1 : set ID, addr
 +     #modbusParameters.ID := INT_TO_WORD(#pos);
 +     #addr := 30013 + #pos * 100;
 +     #step := 2;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 2 THEN // step2 : est 0-> 1
 +     #modbusParameters.ActiveEstablished := TRUE;  // ActiveEstablished enable
 +     #step := 3;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 3 THEN // step3: wait for busy
 +     #read := TRUE;     // read from Intesisbox start
 +     IF #busy THEN      // wait for busy (modbus modul works)
 +         #step := 4;
 +     END_IF;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 4 THEN         // step4: wait for end of busy
 +     IF  #tm4Q THEN        // wait a little bit 
 +         #step := 5;
 +     END_IF;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 5 THEN // step5: copy data
 + // copy data
 + // 
 +     #offset := (#pos * 2) - 2;                  // write offset in intesisDb in bits
 +     #byteOffset := SHR (IN:=#offset, N:=3);     // offset in byte (bit / 8)
 +     #bitOffset := #offset - (#byteOffset * 8);  // rest bits
 +     
 +     #bit1 := WORD_TO_BOOL(#rec[0]);             // error status (word) from modbus
 +     #bit2 := WORD_TO_BOOL(#rec[4]);             // communcation error (word) from modbus
 +
 +     POKE_BOOL(area := 16#84,                    // write error status (bit) to intesisDb
 +               dbNumber := #nrOfIntesisDB,       // dbNumber from intesisDB
 +               byteOffset := #byteOffset,        // byte and bit offset
 +               bitOffset := #bitOffset,
 +               value := #bit1);
 +     
 +     POKE_BOOL(area := 16#84,                    // write communication error (bit) to intesisDb
 +               dbNumber := #nrOfIntesisDB,       // dbNumber from intesisDB
 +                 byteOffset := #byteOffset,      // byte and bit offset + 1
 +               bitOffset := #bitOffset + 1,
 +               value := #bit2);
 +     
 +     #step := 6;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 6 THEN   // step6: est 1-> 0
 +     #modbusParameters.ActiveEstablished := FALSE;   // ActiveEstablished lock
 +     #read:=FALSE;
 +     IF #stepTm6.Q THEN                              // wait a little bit
 +         #step := 7;
 +     END_IF;
 +     GOTO end;
 + END_IF;
 +
 + IF #step = 7 THEN   // step7: next pos
 +     #pos := #pos + 1;
 +     IF #pos > #nrOfReadGroup THEN                  // read loop start again
 +         #pos := 1;
 +     END_IF;
 +     #step := 1;
 +     GOTO end;
 + END_IF;
 +
 + end:
 + ;
 +
 + // call modbus modul mit multi-instants
 + #mbIntesis(REQ := #read,
 +             DISCONNECT := FALSE,
 +             MB_MODE := 0,
 +             MB_DATA_ADDR := #addr,
 +             MB_DATA_LEN := 6,
 +             DONE => #done,
 +             BUSY => #busy,
 +             ERROR => #error,
 +             STATUS => #status,
 +             MB_DATA_PTR := #rec,
 +             CONNECT := #modbusParameters);
 +  
 + // monitor for pos and step 
 + #pos:= #pos;
 + #step := #step;
 +
 + // monitor for readed data
 + #tempw := #rec[0];
 + #tempw := #rec[1];
 + #tempw := #rec[2];
 + #tempw := #rec[3];
 + #tempw := #rec[4];
 + #tempw := #rec[5];
 + #tempw := #rec[6];
 + #tempw := #rec[7];
 +
 + // Status error codes:
 +
 + // 0000: Instruction executed without errors.
 + // 0001: Connection established.
 + // 0003: Connection terminated.
 + // 7000: #no job active AND no connection established (REQ=0, DISCONNECT=1).
 + // 7001: Connection establishment triggered.
 + // 7002: Intermediate call. Connection is being established.
 + // 7003: Connection is being terminated.
 + // 7004: Connection established AND monitored. No job processing active.
 + // 7005: data is being sent.
 + // 7006: data is being received.
 + // 80BB: Invalid value at ActiveEstablished parameter
 + // 80C8: #no response OF the server in the defined period.
 + // 8187: the MB_HOLD_REG parameter has an Invalid Pointer. Data area is too small.
 + // 8380: received Modbus frame has incorrect format OR too few bytes were received.
 + // 8381: Function code is NOT supported.
 + // 8382: the length OF the Modbus frame in the frame header does NOT match the number OF received bytes.
 + // 8383: #error reading OR writing data OR access outside the address area
 + // 8384: Invalid exception code received.
 + // 8385: Diagnostics code NOT supported.
 + // 8386: received function code does NOT match the one sent originally.
 + // 8387: the protocol ID OF the Modbus TCP frame received BY the server is NOT "0".
 + // 8388: the Modbus server sent a different data length than was requested.
 + // 8389: Invalid data area definition
 + // 80B6: Invalid connection type, only TCP connections are supported.
 + // 80BB: Invalid value at ActiveEstablished parameter
 + // 8188: the MB_MODE parameter has an Invalid value.
 + // 8189: Invalid addressing OF data at the MB_DATA_ADDR parameter.
 + // 818A: Invalid data length at the MB_DATA_LEN parameter.
 + // 818B: the MB_DATA_PTR parameter has an Invalid Pointer.
 + // 818C: Timeout at parameter BLOCKED_PROC_TIMEOUT OR RCV_TIMEOUT
 + // 8200: A different Modbus request is currently being processed via the PORT.
 +END_FUNCTION_BLOCK
 +
 +DATA_BLOCK "intesisDB"
 +{ S7_Optimized_Access := 'FALSE' }
 +VERSION : 0.1
 +NON_RETAIN
 +   STRUCT 
 +      meld00 : Bool;   // MBAddr: 113, Klimadeckengerät 1 Raum 2 
 +      meld01 : Bool;   // MBAddr: 117, Klimadeckengerät 1 Raum 2 
 +      meld02 : Bool;   // MBAddr: 213, Klimadeckengerät 1 Raum 3 
 +      meld03 : Bool;   // MBAddr: 217, Klimadeckengerät 1 Raum 3 
 +      meld04 : Bool;   // MBAddr: 313, Klimadeckengerät 2  Raum 3 
 +      meld05 : Bool;   // MBAddr: 317, Klimadeckengerät 2  Raum 3 
 +      meld06 : Bool;   // MBAddr: 413, Klimaschrank 1 Raum 6 
 +      meld07 : Bool;   // MBAddr: 417, Klimaschrank 1 Raum 6 
 +      meld08 : Bool;   // MBAddr: 513, Klimaschrank 2 Raum 7 
 +      meld09 : Bool;   // MBAddr: 517, Klimaschrank 2 Raum 7 
 +      meld10 : Bool;   // MBAddr: 613, Klimaschrank 1 Raum 8 
 +      meld11 : Bool;   // MBAddr: 617, Klimaschrank 1 Raum 8 
 +      meld12 : Bool;   // MBAddr: 713, Klimaschrank 2 Raum 9
 +      meld13 : Bool;   // MBAddr: 717, Klimaschrank 2 Raum 9
 +      meld14 : Bool;   // MBAddr: 813, Klimaschrank 3 Raum 10
 +      meld15 : Bool;   // MBAddr: 817, Klimaschrank 3 Raum 10
 +      meld16 : Bool;   // MBAddr: 913, Klimaschrank 4 Raum 11
 +      meld17 : Bool;   // MBAddr: 917, Klimaschrank 4 Raum 11
 +      meld18 : Bool;   // MBAddr: 1013, Klimadeckengerät 1 Raum 12
 +      meld19 : Bool;   // MBAddr: 1017, Klimadeckengerät 1 Raum 12
 +      meld20 : Bool;   // MBAddr: 1113, Klimadeckengerät 2 Raum 13
 +      meld21 : Bool;   // MBAddr: 1117, Klimadeckengerät 2 Raum 13
 +      meld22 : Bool;   // MBAddr: 1213, Gebäudeklima Kühler 1 Dach 
 +      meld23 : Bool;   // MBAddr: 1217, Gebäudeklima Kühler 1 Dach 
 +      meld24 : Bool;   // MBAddr: 1313, Gebäudeklima Kühler 2 Dach 
 +      meld25 : Bool;   // MBAddr: 1317, Gebäudeklima Kühler 2 Dach 
 +      meld26 : Bool;   // MBAddr: 1413, Gebäudeklima Kühler 3 Dach 
 +      meld27 : Bool;   // MBAddr: 1417, Gebäudeklima Kühler 3 Dach 
 +      meld28 : Bool;   // MBAddr: 1513, Gebäudeklima Kühler 4 Dach 
 +      meld29 : Bool;   // MBAddr: 1517, Gebäudeklima Kühler 4 Dach 
 +      meld30 : Bool;   // MBAddr: 1613, Gebäudeklima Kühler 5 Dach 
 +      meld31 : Bool;   // MBAddr: 1617, Gebäudeklima Kühler 5 Dach 
 +      meld32 : Bool;   // MBAddr: 1713, Gebäudeklima Kühler 6 Dach 
 +      meld33 : Bool;   // MBAddr: 1717, Gebäudeklima Kühler 6 Dach 
 +      meld34 : Bool;   // MBAddr: 1813, Gebäudeklima Kühler 7 Dach 
 +      meld35 : Bool;   // MBAddr: 1817, Gebäudeklima Kühler 7 Dach 
 +      meld36 : Bool;   // MBAddr: 1913, Gebäudeklima Kühler 8 Dach 
 +      meld37 : Bool;   // MBAddr: 1917, Gebäudeklima Kühler 8 Dach 
 +      meld38 : Bool;   // MBAddr: 2013, Gebäudeklima Kühler 9 Dach 
 +      meld39 : Bool;   // MBAddr: 2017, Gebäudeklima Kühler 9 Dach 
 +      meld40 : Bool;   // MBAddr: 2113, Gebäudeklima Kühler 10 Dach 
 +      meld41 : Bool;   // MBAddr: 2117, Gebäudeklima Kühler 10 Dach 
 +      meld42 : Bool;   // MBAddr: 2213, Gebäudeklima Kühler 11 Dach 
 +      meld43 : Bool;   // MBAddr: 2217, Gebäudeklima Kühler 11 Dach 
 +      meld44 : Bool;   // res
 +      meld45 : Bool;   // res
 +      meld46 : Bool;   // res
 +      meld47 : Bool;   // res
 +   END_STRUCT;
 +
 +
 +BEGIN
 +
 +END_DATA_BLOCK
 +
 +
 +</code>
 +</hidden>
 +
 +{{page>de:project_s7:foot}}
 +
  
  • de/project_s7/modbus_intensisbox_s7_1500.txt
  • 2022/04/21 15:01
  • ()