DATA_BLOCK "ModbusComm" { S7_Optimized_Access := 'FALSE' } VERSION : 0.1 STRUCT comm_client {InstructionName := 'TCON_IP_v4'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TCON_IP_v4; END_STRUCT; BEGIN comm_client.InterfaceId := 64; comm_client.ID := 16#0002; comm_client.ConnectionType := 16#000B; comm_client.ActiveEstablished := TRUE; comm_client.RemoteAddress.ADDR[1] := 192; comm_client.RemoteAddress.ADDR[2] := 168; comm_client.RemoteAddress.ADDR[3] := 178; comm_client.RemoteAddress.ADDR[4] := 44; comm_client.RemotePort := 502; comm_client.LocalPort := 503; END_DATA_BLOCK DATA_BLOCK "mbRead" { S7_Optimized_Access := 'FALSE' } VERSION : 0.1 NON_RETAIN STRUCT liveBeat : Byte; // liveBeat data : Array[0..9] of Word; // data from Sensor END_STRUCT; BEGIN END_DATA_BLOCK FUNCTION_BLOCK "testFB" { S7_Optimized_Access := 'TRUE' } VERSION : 0.1 VAR ston {InstructionName := 'TON_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TON_TIME; stonb { S7_SetPoint := 'True'} : Bool; start : Bool; disc : Bool; done : Bool; busy : Bool; error : Bool; status : Word; temp : Real; hum : Real; END_VAR BEGIN // LAMAplc program, UICPAL humidity / temperature sensor Modbus communication with S7-1500 // https://lamaplc.com/doku.php?id=com:s7_uicpal_modbus_communication#the_uicpal_unit_and_the_s7-1500 // The sensor communicates slowly (9600 baud), time must be allowed for transmission. // The program runs with a 2-second clock, the data is updated every 4 seconds // // Author: Sandor Vamos - lamaPLC, 2023 #ston(IN:=NOT(#stonb), PT:=t#2s); #stonb := #ston.Q; IF #stonb THEN IF #start THEN #start := FALSE; ELSE #start := TRUE; END_IF; "mbRead".liveBeat := "mbRead".liveBeat + 1; END_IF; //#start := FALSE; "MB_CLIENT_DB".MB_Unit_ID := 1; "MB_CLIENT_DB"(REQ := #start, DISCONNECT := NOT(#start), MB_MODE := 0, MB_DATA_ADDR := 40001, MB_DATA_LEN := 10, DONE=>#done, BUSY=>#busy, ERROR=>#error, STATUS=>#status, MB_DATA_PTR := P#DB6.DBX2.0 WORD 10, CONNECT := "ModbusComm".comm_client); #temp := "mbRead".data[1] / 10.0; #hum := "mbRead".data[0] / 10.0; END_FUNCTION_BLOCK