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 ====== | ||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 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 //" | ||
+ | |||
+ | **Wichtig!** Das Programm verwendet die direkte Adressierung in der //" | ||
+ | |||
+ | **Wichtig!** Bitte überprüfen Sie auch den Parameter " | ||
+ | |||
+ | 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. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 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 //" | ||
+ | |||
+ | **Important!** The program uses direct addressing in the //" | ||
+ | |||
+ | **Important!** Please check //" | ||
+ | |||
+ | After installation, | ||
+ | |||
+ | |{{ : | ||
+ | |Simatic S7-1500 - IntesisBox Modbus Kommunikation|LinkBoxMB zeigt Kommunikation|Kommunikationssicht in TIA 16| | ||
+ | |||
+ | |||
+ | <WRAP center round download 80%> | ||
+ | **SCL-Programm download:** {{ : | ||
+ | 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. | ||
+ | </ | ||
+ | |||
+ | From file (from 2020.10.30) **{{dlcounter> | ||
+ | |||
+ | <hidden Klicken Sie hier, um den Code anzuzeigen - Click here to view the code> | ||
+ | <code pascal> | ||
+ | FUNCTION_BLOCK " | ||
+ | { S7_Optimized_Access := ' | ||
+ | VERSION : 0.1 | ||
+ | | ||
+ | nrOfReadGroup : Int := 23; // number of group of read from Intesis | ||
+ | nrOfIntesisDB : ULInt := 1; // DB Number of intesisDB | ||
+ | modbusParameters {InstructionName := ' | ||
+ | mbIntesis {InstructionName := ' | ||
+ | tme {InstructionName := ' | ||
+ | tmeQ { S7_SetPoint := ' | ||
+ | tmeChg { S7_SetPoint := ' | ||
+ | pos : Int := 1; | ||
+ | rec : Array[0..22] of Word; | ||
+ | addr : LInt := 30113; | ||
+ | step : Int := 0; | ||
+ | busy : Bool; | ||
+ | read : Bool; | ||
+ | stepTm4 {InstructionName := ' | ||
+ | stepTm6 {InstructionName := ' | ||
+ | tm4Q { S7_SetPoint := ' | ||
+ | byteOffset : Int; | ||
+ | bitOffset : Int; | ||
+ | offset : Int; | ||
+ | bit1 : Bool; | ||
+ | bit2 : Bool; | ||
+ | | ||
+ | |||
+ | | ||
+ | done : Bool; | ||
+ | error : Bool; | ||
+ | status : Word; | ||
+ | no : Bool; | ||
+ | tempw : Word; | ||
+ | rest : Time; | ||
+ | | ||
+ | |||
+ | |||
+ | 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 " | ||
+ | // | ||
+ | // Important! The program uses direct addressing in the " | ||
+ | // DB Properties / Attributes / Optimized block access parameter must be switched off, | ||
+ | // otherwise it will NOT display error messages. | ||
+ | // | ||
+ | // Important! Please check " | ||
+ | // | ||
+ | // After installation, | ||
+ | // in which case The PLC (stop-run) must be restarted. | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // # | ||
+ | // # | ||
+ | // #addr (LInt, def: 30113): Start address for read from IntesisBox (113: first error status) | ||
+ | // # | ||
+ | // # | ||
+ | // # | ||
+ | // # | ||
+ | |||
+ | |||
+ | |||
+ | // 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 | ||
+ | // | ||
+ | |||
+ | # | ||
+ | PT := t#1s, | ||
+ | Q => #tm4Q, | ||
+ | ET => #rest); | ||
+ | |||
+ | # | ||
+ | PT := t#200ms, | ||
+ | | ||
+ | |||
+ | IF #step = 0 THEN // first step (only by newstart): init | ||
+ | #read := FALSE; | ||
+ | # | ||
+ | #pos := 1; | ||
+ | #step := 1; | ||
+ | GOTO end; | ||
+ | END_IF; | ||
+ | |||
+ | IF #step = 1 THEN // step1 : set ID, addr | ||
+ | # | ||
+ | #addr := 30013 + #pos * 100; | ||
+ | #step := 2; | ||
+ | GOTO end; | ||
+ | END_IF; | ||
+ | |||
+ | IF #step = 2 THEN // step2 : est 0-> 1 | ||
+ | # | ||
+ | #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: | ||
+ | #bitOffset := #offset - (# | ||
+ | | ||
+ | #bit1 := WORD_TO_BOOL(# | ||
+ | #bit2 := WORD_TO_BOOL(# | ||
+ | |||
+ | POKE_BOOL(area := 16# | ||
+ | dbNumber := # | ||
+ | byteOffset := # | ||
+ | bitOffset := #bitOffset, | ||
+ | value := #bit1); | ||
+ | | ||
+ | POKE_BOOL(area := 16# | ||
+ | dbNumber := # | ||
+ | byteOffset := # | ||
+ | bitOffset := #bitOffset + 1, | ||
+ | value := #bit2); | ||
+ | | ||
+ | #step := 6; | ||
+ | GOTO end; | ||
+ | END_IF; | ||
+ | |||
+ | IF #step = 6 THEN // step6: est 1-> 0 | ||
+ | # | ||
+ | # | ||
+ | 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 > # | ||
+ | #pos := 1; | ||
+ | END_IF; | ||
+ | #step := 1; | ||
+ | GOTO end; | ||
+ | END_IF; | ||
+ | |||
+ | end: | ||
+ | ; | ||
+ | |||
+ | // call modbus modul mit multi-instants | ||
+ | # | ||
+ | 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 := # | ||
+ | |||
+ | // 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 " | ||
+ | // 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 " | ||
+ | { S7_Optimized_Access := ' | ||
+ | VERSION : 0.1 | ||
+ | NON_RETAIN | ||
+ | | ||
+ | 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 | ||
+ | | ||
+ | |||
+ | |||
+ | BEGIN | ||
+ | |||
+ | END_DATA_BLOCK | ||
+ | |||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | {{page> | ||
+ | |||