Produal MIO 12-PT
Detaljer
- Typ
- Drivrutin
- Upplaggd av
- Marcus Willander, Abelko Innovation
- Version
- 1
- Uppdaterad
- 2017-02-06
- Skapad
- 2017-02-06
- Kategori
- Allmän automation, IO enheter, Mätare, Modbus
- Visningar
- 2381
Beskrivning
Modbusskript för Produals MIO 12-PT modul. Allt. Fungerar inte i WMPro endast Ultra
Bruksanvisning
.
Juridisk information
Alla skript tillhandahålls i befintligt skick och all användning sker på eget ansvar. Felaktig använding kan leda till skadad eller förstörd utrustning.
Skript kod
DEVICETYPE MIO_12_PT NAMED "Produal MIO 12-PT" IS
PARAMETER
Id : "Adress"INT;
V25 : "DO1 - manual mode" INT;
V26 : "DO2 - manual mode" INT;
V27 : "DO3 - manual mode" INT;
V28 : "DO4 - manual mode" INT;
V29 : "AO1 value" ["%"]DEC1;
V30 : "AO2 value" ["%"]DEC1;
V31 : "AO3 value" ["%"]DEC1;
V32 : "AO4 value" ["%"]DEC1;
V33 : "3P MOTOR1 VALUE or THERM1 out" ["%"]DEC1;
V34 : "THERM2 out" ["%"]DEC1;
V35 : "3P MOTOR2 VALUE or THERM3 out" ["%"]DEC1;
V36 : "THERM4 out" ["%"]DEC1;
PUBLIC
V1 : "DO1 - manual mode" INT;
V2 : "DO2 - manual mode" INT;
V3 : "DO3 - manual mode" INT;
V4 : "DO4 - manual mode" INT;
V5 : "AI1 Digital Input" INT;
V6 : "AI2 Digital Input" INT;
V7 : "AI3 Digital Input" INT;
V8 : "AI4 Digital Input" INT;
V9 : "AO1 value" ["%"]DEC1;
V10 : "AO2 value" ["%"]DEC1;
V11 : "AO3 value" ["%"]DEC1;
V12 : "AO4 value" ["%"]DEC1;
V13 : "3P MOTOR1 VALUE or THERM1 out" ["%"]DEC1;
V14 : "THERM2 out" ["%"]DEC1;
V15 : "3P MOTOR2 VALUE or THERM3 out" ["%"]DEC1;
V16 : "THERM4 out" ["%"]DEC1;
V17 : "AI1 value" ["°C"]DEC1;
V18 : "AI2 value" ["°C"]DEC1;
V19 : "AI3 value" ["°C"]DEC1;
V20 : "AI4 value" ["°C"]DEC1;
V21 : "AI1 digital counter"INT;
V22 : "AI2 digital counter"INT;
V23 : "AI3 digital counter"INT;
V24 : "AI4 digital counter"INT;
PRIVATE
count5;
count6;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM Read1 NAMED "Read 1" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(01); % Modbus kommando för att läsa register kod 01
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(4); % Antal register att läsa
ANSWER SIZE 6 % (Antal register / 8) avrundat uppåt + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(01);
DATA[2] = BYTE(1); % Antal Bytes
DATA[3] -> BYTE(
IF (DATA & 1) THEN V1 := 1; ELSE V1 := 0; ENDIF;
IF (DATA & 2) THEN V2 := 1; ELSE V2 := 0; ENDIF;
IF (DATA & 4) THEN V3 := 1; ELSE V3 := 0; ENDIF;
IF (DATA & 8) THEN V4 := 1; ELSE V4 := 0; ENDIF;
);
TIMEOUT 3000
END;
TELEGRAM Read2 NAMED "Read 2" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(02); % Modbus kommando för att läsa register kod 02
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(4); % Antal register att läsa
ANSWER SIZE 6 % (Antal register / 8) avrundat uppåt + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(02);
DATA[2] = BYTE(1); % Antal Bytes
DATA[3] -> BYTE(
IF (DATA & 1) THEN V5 := 1; ELSE V5 := 0; ENDIF;
IF (DATA & 2) THEN V6 := 1; ELSE V6 := 0; ENDIF;
IF (DATA & 4) THEN V7 := 1; ELSE V7 := 0; ENDIF;
IF (DATA & 8) THEN V8 := 1; ELSE V8 := 0; ENDIF;
);
TIMEOUT 3000
END;
TELEGRAM WriteCoil NAMED "Write Coil" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(05); % Modbus kommando för att skriva en Coil
DATA[2] <- RWORD(
IF(count5>3) THEN count5 := 0; ENDIF;
IF (count5=0) THEN DATA := 0;
ELSIF (count5=1) THEN DATA := 1;
ELSIF (count5=2) THEN DATA := 2;
ELSIF (count5=3) THEN DATA := 3;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count5=0) THEN IF (V25 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=1) THEN IF (V26 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ELSIF (count5=2) THEN IF (V27 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ELSIF (count5=3) THEN IF (V28 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ENDIF;
count5 := count5+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(05);
TIMEOUT 3000
END;
TELEGRAM Read3 NAMED "Read 3" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(03); % Modbus kommando för att läsa register kod 03
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(8); % Antal register att läsa
ANSWER SIZE 21 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(03);
DATA[2] = BYTE(16); % Antal Bytes
DATA[3] -> RINT(V9 := DATA/10;);
DATA[5] -> RINT(V10 := DATA/10;);
DATA[7] -> RINT(V11 := DATA/10;);
DATA[9] -> RINT(V12 := DATA/10;);
DATA[11] -> RINT(V13 := DATA/10;);
DATA[13] -> RINT(V14 := DATA/10;);
DATA[15] -> RINT(V15 := DATA/10;);
DATA[17] -> RINT(V16 := DATA/10;);
TIMEOUT 3000
END;
TELEGRAM Read4 NAMED "Read 4" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(04); % Modbus kommando för att läsa register kod 04
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(8); % Antal register att läsa
ANSWER SIZE 21 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(04);
DATA[2] = BYTE(16); % Antal Bytes
DATA[3] -> RINT(V17 := DATA/10;);
DATA[5] -> RINT(V18 := DATA/10;);
DATA[7] -> RINT(V19 := DATA/10;);
DATA[9] -> RINT(V20 := DATA/10;);
DATA[11] -> RWORD(V21 := DATA;);
DATA[13] -> RWORD(V22 := DATA;);
DATA[15] -> RWORD(V23 := DATA;);
DATA[17] -> RWORD(V24 := DATA;);
TIMEOUT 3000
END;
TELEGRAM WriteRegister NAMED "Write Register" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(06); % Modbus kommando för att skriva ett register
DATA[2] <- RWORD(
IF(count6>7) THEN count6 := 0; ENDIF;
IF (count6=0) THEN DATA := 0;
ELSIF (count6=1) THEN DATA := 1;
ELSIF (count6=2) THEN DATA := 2;
ELSIF (count6=3) THEN DATA := 3;
ELSIF (count6=4) THEN DATA := 4;
ELSIF (count6=5) THEN DATA := 5;
ELSIF (count6=6) THEN DATA := 6;
ELSIF (count6=7) THEN DATA := 7;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count6=0) THEN DATA := V29*10;
ELSIF (count6=1) THEN DATA := V30*10;
ELSIF (count6=2) THEN DATA := V31*10;
ELSIF (count6=3) THEN DATA := V32*10;
ELSIF (count6=4) THEN DATA := V33*10;
ELSIF (count6=5) THEN DATA := V34*10;
ELSIF (count6=6) THEN DATA := V35*10;
ELSIF (count6=7) THEN DATA := V36*10;
ENDIF;
count6 := count6+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(06);
TIMEOUT 3000
END;
END;
PARAMETER
Id : "Adress"INT;
V25 : "DO1 - manual mode" INT;
V26 : "DO2 - manual mode" INT;
V27 : "DO3 - manual mode" INT;
V28 : "DO4 - manual mode" INT;
V29 : "AO1 value" ["%"]DEC1;
V30 : "AO2 value" ["%"]DEC1;
V31 : "AO3 value" ["%"]DEC1;
V32 : "AO4 value" ["%"]DEC1;
V33 : "3P MOTOR1 VALUE or THERM1 out" ["%"]DEC1;
V34 : "THERM2 out" ["%"]DEC1;
V35 : "3P MOTOR2 VALUE or THERM3 out" ["%"]DEC1;
V36 : "THERM4 out" ["%"]DEC1;
PUBLIC
V1 : "DO1 - manual mode" INT;
V2 : "DO2 - manual mode" INT;
V3 : "DO3 - manual mode" INT;
V4 : "DO4 - manual mode" INT;
V5 : "AI1 Digital Input" INT;
V6 : "AI2 Digital Input" INT;
V7 : "AI3 Digital Input" INT;
V8 : "AI4 Digital Input" INT;
V9 : "AO1 value" ["%"]DEC1;
V10 : "AO2 value" ["%"]DEC1;
V11 : "AO3 value" ["%"]DEC1;
V12 : "AO4 value" ["%"]DEC1;
V13 : "3P MOTOR1 VALUE or THERM1 out" ["%"]DEC1;
V14 : "THERM2 out" ["%"]DEC1;
V15 : "3P MOTOR2 VALUE or THERM3 out" ["%"]DEC1;
V16 : "THERM4 out" ["%"]DEC1;
V17 : "AI1 value" ["°C"]DEC1;
V18 : "AI2 value" ["°C"]DEC1;
V19 : "AI3 value" ["°C"]DEC1;
V20 : "AI4 value" ["°C"]DEC1;
V21 : "AI1 digital counter"INT;
V22 : "AI2 digital counter"INT;
V23 : "AI3 digital counter"INT;
V24 : "AI4 digital counter"INT;
PRIVATE
count5;
count6;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM Read1 NAMED "Read 1" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(01); % Modbus kommando för att läsa register kod 01
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(4); % Antal register att läsa
ANSWER SIZE 6 % (Antal register / 8) avrundat uppåt + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(01);
DATA[2] = BYTE(1); % Antal Bytes
DATA[3] -> BYTE(
IF (DATA & 1) THEN V1 := 1; ELSE V1 := 0; ENDIF;
IF (DATA & 2) THEN V2 := 1; ELSE V2 := 0; ENDIF;
IF (DATA & 4) THEN V3 := 1; ELSE V3 := 0; ENDIF;
IF (DATA & 8) THEN V4 := 1; ELSE V4 := 0; ENDIF;
);
TIMEOUT 3000
END;
TELEGRAM Read2 NAMED "Read 2" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(02); % Modbus kommando för att läsa register kod 02
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(4); % Antal register att läsa
ANSWER SIZE 6 % (Antal register / 8) avrundat uppåt + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(02);
DATA[2] = BYTE(1); % Antal Bytes
DATA[3] -> BYTE(
IF (DATA & 1) THEN V5 := 1; ELSE V5 := 0; ENDIF;
IF (DATA & 2) THEN V6 := 1; ELSE V6 := 0; ENDIF;
IF (DATA & 4) THEN V7 := 1; ELSE V7 := 0; ENDIF;
IF (DATA & 8) THEN V8 := 1; ELSE V8 := 0; ENDIF;
);
TIMEOUT 3000
END;
TELEGRAM WriteCoil NAMED "Write Coil" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(05); % Modbus kommando för att skriva en Coil
DATA[2] <- RWORD(
IF(count5>3) THEN count5 := 0; ENDIF;
IF (count5=0) THEN DATA := 0;
ELSIF (count5=1) THEN DATA := 1;
ELSIF (count5=2) THEN DATA := 2;
ELSIF (count5=3) THEN DATA := 3;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count5=0) THEN IF (V25 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=1) THEN IF (V26 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ELSIF (count5=2) THEN IF (V27 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ELSIF (count5=3) THEN IF (V28 >0) THEN DATA := 65280; ELSE DATA := 0; ENDIF;
ENDIF;
count5 := count5+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(05);
TIMEOUT 3000
END;
TELEGRAM Read3 NAMED "Read 3" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(03); % Modbus kommando för att läsa register kod 03
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(8); % Antal register att läsa
ANSWER SIZE 21 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(03);
DATA[2] = BYTE(16); % Antal Bytes
DATA[3] -> RINT(V9 := DATA/10;);
DATA[5] -> RINT(V10 := DATA/10;);
DATA[7] -> RINT(V11 := DATA/10;);
DATA[9] -> RINT(V12 := DATA/10;);
DATA[11] -> RINT(V13 := DATA/10;);
DATA[13] -> RINT(V14 := DATA/10;);
DATA[15] -> RINT(V15 := DATA/10;);
DATA[17] -> RINT(V16 := DATA/10;);
TIMEOUT 3000
END;
TELEGRAM Read4 NAMED "Read 4" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(04); % Modbus kommando för att läsa register kod 04
DATA[2] := RWORD(0); % Start address
DATA[4] := RWORD(8); % Antal register att läsa
ANSWER SIZE 21 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(04);
DATA[2] = BYTE(16); % Antal Bytes
DATA[3] -> RINT(V17 := DATA/10;);
DATA[5] -> RINT(V18 := DATA/10;);
DATA[7] -> RINT(V19 := DATA/10;);
DATA[9] -> RINT(V20 := DATA/10;);
DATA[11] -> RWORD(V21 := DATA;);
DATA[13] -> RWORD(V22 := DATA;);
DATA[15] -> RWORD(V23 := DATA;);
DATA[17] -> RWORD(V24 := DATA;);
TIMEOUT 3000
END;
TELEGRAM WriteRegister NAMED "Write Register" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(06); % Modbus kommando för att skriva ett register
DATA[2] <- RWORD(
IF(count6>7) THEN count6 := 0; ENDIF;
IF (count6=0) THEN DATA := 0;
ELSIF (count6=1) THEN DATA := 1;
ELSIF (count6=2) THEN DATA := 2;
ELSIF (count6=3) THEN DATA := 3;
ELSIF (count6=4) THEN DATA := 4;
ELSIF (count6=5) THEN DATA := 5;
ELSIF (count6=6) THEN DATA := 6;
ELSIF (count6=7) THEN DATA := 7;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count6=0) THEN DATA := V29*10;
ELSIF (count6=1) THEN DATA := V30*10;
ELSIF (count6=2) THEN DATA := V31*10;
ELSIF (count6=3) THEN DATA := V32*10;
ELSIF (count6=4) THEN DATA := V33*10;
ELSIF (count6=5) THEN DATA := V34*10;
ELSIF (count6=6) THEN DATA := V35*10;
ELSIF (count6=7) THEN DATA := V36*10;
ENDIF;
count6 := count6+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(06);
TIMEOUT 3000
END;
END;
Användarnas noteringar
Du måste vara inloggad för att göra en notering. Bli medlem eller logga in. Vi använder en moderator som godkänner noteringarna innan de visas.