CalectroIO MB-01
Detaljer
- Typ
- Drivrutin
- Upplaggd av
- Ove Jansson, Abelko Innovation
- Version
- 1
- Uppdaterad
- 2017-03-01
- Skapad
- 2017-03-01
- Kategori
- IO enheter, Modbus
- Visningar
- 2548
Beskrivning
.
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
% Skapad med Modbus Creator
% - OBS! Användaren ansvarar själv för att samma TYPID inte används flera gånger i samma apparat.
% TYPID 10000-19999 är för användardefinierade enheter
DEVICETYPE IOMB01 NAMED "Calecto IOMB-01" TYPEID 10000 IS
PARAMETER
Id : "Adress";
V29 : "setDO1" INT;
V30 : "setDO2" INT;
V31 : "setDO3" INT;
V32 : "setAO1" ["V"]DEC2;
V33 : "setAO2" ["V"]DEC2;
V34 : "setAO3" ["V"]DEC2;
V35 : "setDO1 default" INT
V36 : "setDO2 default" INT
V37 : "setDO3 default" INT
V38 : "setAO1 default" ["V"]DEC2;
V39 : "setAO2 default" ["V"]DEC2;
V40 : "setAO3 default" ["V"]DEC2;
V41 : "setTimeout2default" ["sec"]INT; % 0=off
V42 : "setAI1 sensor type" ["PT1000,Ni1000LG"]ENUM;
V43 : "setAI2 sensor type" ["PT1000,Ni1000LG"]ENUM;
V44 : "setAI3 sensor type" ["PT1000,Ni1000LG"]ENUM;
PUBLIC
V1 : "DO1" INT;
V2 : "DO2" INT;
V3 : "DO3" INT;
V4 : "DI1" INT;
V5 : "DI2" INT;
V6 : "DI3" INT;
V7 : "AO1 (volt)" ["V"]DEC2;
V8 : "AO2 (volt)" ["V"]DEC2;
V9 : "AO3 (volt)" ["V"]DEC2;
V10 : "DO1 default" INT;
V11 : "DO2 default" INT;
V12 : "DO3 default" INT;
V13 : "AO1 default" ["V"]DEC2;
V14 : "AO2 default" ["V"]DEC2;
V15 : "AO3 default" ["V"]DEC2;
V16 : "Timeout2default" ["sec"];
V17 : "AI1 sensor type" ["PT1000,Ni1000LG"]ENUM;
V18 : "AI2 sensor type" ["PT1000,Ni1000LG"]ENUM;
V19 : "AI3 sensor type" ["PT1000,Ni1000LG"]ENUM;
V20 : "AI1 (Volt)" ["V"]DEC2;
V21 : "AI2 (volt)" ["V"]DEC2;
V22 : "AI3 (volt)" ["V"]DEC2;
V23 : "AI1 (ohms)" ["Ohms"]INT;
V24 : "AI2 (ohms)" ["Ohms"]INT;
V25 : "AI3 (ohms)" ["Ohms"]INT;
V26 : "AI1 (°C)" ["°C"]DEC1;
V27 : "AI2 (°C)" ["°C"]DEC1;
V28 : "AI3 (°C)" ["°C"]DEC1;
PRIVATE
count5;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM ReadDI NAMED "Read DI" 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(3); % 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;
);
TIMEOUT 300
END;
TELEGRAM ReadDO NAMED "Read DO" 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(3); % 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 V4 := 1; ELSE V4 := 0; ENDIF;
IF (DATA & 2) THEN V5 := 1; ELSE V5 := 0; ENDIF;
IF (DATA & 4) THEN V6 := 1; ELSE V6 := 0; ENDIF;
);
TIMEOUT 300
END;
TELEGRAM WriteDO NAMED "Write DO" 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>2) THEN count5 := 0; ENDIF;
IF (count5=0) THEN DATA := 0;
ELSIF (count5=1) THEN DATA := 1;
ELSIF (count5=2) THEN DATA := 2;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count5=0) THEN IF (V29 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=1) THEN IF (V30 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=2) THEN IF (V31 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ENDIF;
count5 := count5+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(05);
TIMEOUT 300
END;
TELEGRAM ReadMulti NAMED "Read AO+default" 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(6); % Start address
DATA[4] := RWORD(22); % Antal register att läsa
ANSWER SIZE 49 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(03);
DATA[2] = BYTE(44); % Antal Bytes
DATA[3] -> RWORD(V7 := DATA/100;);
DATA[5] -> RWORD(V8 := DATA/100;);
DATA[7] -> RWORD(V9 := DATA/100;);
DATA[27] -> RWORD(V10 := DATA;);
DATA[29] -> RWORD(V11 := DATA;);
DATA[31] -> RWORD(V12 := DATA;);
DATA[33] -> RWORD(V13 := DATA/100;);
DATA[35] -> RWORD(V14 := DATA/100;);
DATA[37] -> RWORD(V15 := DATA/100;);
DATA[39] -> RWORD(V16 := DATA;);
DATA[41] -> RWORD(V17 := DATA;);
DATA[43] -> RWORD(V18 := DATA;);
DATA[45] -> RWORD(V19 := DATA;);
TIMEOUT 300
END;
TELEGRAM ReadAI NAMED "Read AI" 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(9); % Start address
DATA[4] := RWORD(9); % Antal register att läsa
ANSWER SIZE 23 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(04);
DATA[2] = BYTE(18); % Antal Bytes
DATA[3] -> RWORD(V20 := DATA/100;);
DATA[5] -> RWORD(V21 := DATA/100;);
DATA[7] -> RWORD(V22 := DATA/100;);
DATA[9] -> RWORD(V23 := DATA;);
DATA[11] -> RWORD(V24 := DATA;);
DATA[13] -> RWORD(V25 := DATA;);
DATA[15] -> RWORD(V26 := DATA/10;);
DATA[17] -> RWORD(V27 := DATA/10;);
DATA[19] -> RWORD(V28 := DATA/10;);
TIMEOUT 300
END;
TELEGRAM WriteAO NAMED "Set AO" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(6); % Register adress
DATA[4] := RWORD(3); % Antal register
DATA[6] := BYTE(6); % Antal byte
DATA[7] <- RWORD(DATA:=V32;);
DATA[9] <- RWORD(DATA:=V33;);
DATA[11] <- RWORD(DATA:=V34;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
END;
TELEGRAM WriteType NAMED "Set AI sensor type" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(25); % Register adress
DATA[4] := RWORD(3); % Antal register
DATA[6] := BYTE(6); % Antal byte
DATA[7] <- RWORD(DATA:=V42;);
DATA[9] <- RWORD(DATA:=V43;);
DATA[11] <- RWORD(DATA:=V44;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
END;
TELEGRAM WriteDefaults NAMED "Set Defaults" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(18); % Register adress
DATA[4] := RWORD(7); % Antal register
DATA[6] := BYTE(14); % Antal byte
DATA[7] <- RWORD(DATA:=V35;);
DATA[9] <- RWORD(DATA:=V36;);
DATA[11] <- RWORD(DATA:=V37;);
DATA[13] <- RWORD(DATA:=V38;);
DATA[15] <- RWORD(DATA:=V39;);
DATA[17] <- RWORD(DATA:=V40;);
DATA[19] <- RWORD(DATA:=V41;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
END;
END;
% - OBS! Användaren ansvarar själv för att samma TYPID inte används flera gånger i samma apparat.
% TYPID 10000-19999 är för användardefinierade enheter
DEVICETYPE IOMB01 NAMED "Calecto IOMB-01" TYPEID 10000 IS
PARAMETER
Id : "Adress";
V29 : "setDO1" INT;
V30 : "setDO2" INT;
V31 : "setDO3" INT;
V32 : "setAO1" ["V"]DEC2;
V33 : "setAO2" ["V"]DEC2;
V34 : "setAO3" ["V"]DEC2;
V35 : "setDO1 default" INT
V36 : "setDO2 default" INT
V37 : "setDO3 default" INT
V38 : "setAO1 default" ["V"]DEC2;
V39 : "setAO2 default" ["V"]DEC2;
V40 : "setAO3 default" ["V"]DEC2;
V41 : "setTimeout2default" ["sec"]INT; % 0=off
V42 : "setAI1 sensor type" ["PT1000,Ni1000LG"]ENUM;
V43 : "setAI2 sensor type" ["PT1000,Ni1000LG"]ENUM;
V44 : "setAI3 sensor type" ["PT1000,Ni1000LG"]ENUM;
PUBLIC
V1 : "DO1" INT;
V2 : "DO2" INT;
V3 : "DO3" INT;
V4 : "DI1" INT;
V5 : "DI2" INT;
V6 : "DI3" INT;
V7 : "AO1 (volt)" ["V"]DEC2;
V8 : "AO2 (volt)" ["V"]DEC2;
V9 : "AO3 (volt)" ["V"]DEC2;
V10 : "DO1 default" INT;
V11 : "DO2 default" INT;
V12 : "DO3 default" INT;
V13 : "AO1 default" ["V"]DEC2;
V14 : "AO2 default" ["V"]DEC2;
V15 : "AO3 default" ["V"]DEC2;
V16 : "Timeout2default" ["sec"];
V17 : "AI1 sensor type" ["PT1000,Ni1000LG"]ENUM;
V18 : "AI2 sensor type" ["PT1000,Ni1000LG"]ENUM;
V19 : "AI3 sensor type" ["PT1000,Ni1000LG"]ENUM;
V20 : "AI1 (Volt)" ["V"]DEC2;
V21 : "AI2 (volt)" ["V"]DEC2;
V22 : "AI3 (volt)" ["V"]DEC2;
V23 : "AI1 (ohms)" ["Ohms"]INT;
V24 : "AI2 (ohms)" ["Ohms"]INT;
V25 : "AI3 (ohms)" ["Ohms"]INT;
V26 : "AI1 (°C)" ["°C"]DEC1;
V27 : "AI2 (°C)" ["°C"]DEC1;
V28 : "AI3 (°C)" ["°C"]DEC1;
PRIVATE
count5;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM ReadDI NAMED "Read DI" 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(3); % 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;
);
TIMEOUT 300
END;
TELEGRAM ReadDO NAMED "Read DO" 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(3); % 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 V4 := 1; ELSE V4 := 0; ENDIF;
IF (DATA & 2) THEN V5 := 1; ELSE V5 := 0; ENDIF;
IF (DATA & 4) THEN V6 := 1; ELSE V6 := 0; ENDIF;
);
TIMEOUT 300
END;
TELEGRAM WriteDO NAMED "Write DO" 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>2) THEN count5 := 0; ENDIF;
IF (count5=0) THEN DATA := 0;
ELSIF (count5=1) THEN DATA := 1;
ELSIF (count5=2) THEN DATA := 2;
ENDIF;
); % Register adress
DATA[4] <- RWORD(
IF (count5=0) THEN IF (V29 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=1) THEN IF (V30 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ELSIF (count5=2) THEN IF (V31 >0) THEN DATA := 65536; ELSE DATA := 0; ENDIF;
ENDIF;
count5 := count5+1;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = BYTE(05);
TIMEOUT 300
END;
TELEGRAM ReadMulti NAMED "Read AO+default" 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(6); % Start address
DATA[4] := RWORD(22); % Antal register att läsa
ANSWER SIZE 49 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(03);
DATA[2] = BYTE(44); % Antal Bytes
DATA[3] -> RWORD(V7 := DATA/100;);
DATA[5] -> RWORD(V8 := DATA/100;);
DATA[7] -> RWORD(V9 := DATA/100;);
DATA[27] -> RWORD(V10 := DATA;);
DATA[29] -> RWORD(V11 := DATA;);
DATA[31] -> RWORD(V12 := DATA;);
DATA[33] -> RWORD(V13 := DATA/100;);
DATA[35] -> RWORD(V14 := DATA/100;);
DATA[37] -> RWORD(V15 := DATA/100;);
DATA[39] -> RWORD(V16 := DATA;);
DATA[41] -> RWORD(V17 := DATA;);
DATA[43] -> RWORD(V18 := DATA;);
DATA[45] -> RWORD(V19 := DATA;);
TIMEOUT 300
END;
TELEGRAM ReadAI NAMED "Read AI" 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(9); % Start address
DATA[4] := RWORD(9); % Antal register att läsa
ANSWER SIZE 23 % (Antal register * 2) + 5
DATA[0] = BYTE(Id);
DATA[1] = BYTE(04);
DATA[2] = BYTE(18); % Antal Bytes
DATA[3] -> RWORD(V20 := DATA/100;);
DATA[5] -> RWORD(V21 := DATA/100;);
DATA[7] -> RWORD(V22 := DATA/100;);
DATA[9] -> RWORD(V23 := DATA;);
DATA[11] -> RWORD(V24 := DATA;);
DATA[13] -> RWORD(V25 := DATA;);
DATA[15] -> RWORD(V26 := DATA/10;);
DATA[17] -> RWORD(V27 := DATA/10;);
DATA[19] -> RWORD(V28 := DATA/10;);
TIMEOUT 300
END;
TELEGRAM WriteAO NAMED "Set AO" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(6); % Register adress
DATA[4] := RWORD(3); % Antal register
DATA[6] := BYTE(6); % Antal byte
DATA[7] <- RWORD(DATA:=V32;);
DATA[9] <- RWORD(DATA:=V33;);
DATA[11] <- RWORD(DATA:=V34;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
END;
TELEGRAM WriteType NAMED "Set AI sensor type" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(25); % Register adress
DATA[4] := RWORD(3); % Antal register
DATA[6] := BYTE(6); % Antal byte
DATA[7] <- RWORD(DATA:=V42;);
DATA[9] <- RWORD(DATA:=V43;);
DATA[11] <- RWORD(DATA:=V44;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
END;
TELEGRAM WriteDefaults NAMED "Set Defaults" IS
QUESTION
DATA[0] := BYTE(Id); % Enhetens Modbus adress
DATA[1] := HEX(10); % Modbus kommando för att skriva flera register
DATA[2] := RWORD(18); % Register adress
DATA[4] := RWORD(7); % Antal register
DATA[6] := BYTE(14); % Antal byte
DATA[7] <- RWORD(DATA:=V35;);
DATA[9] <- RWORD(DATA:=V36;);
DATA[11] <- RWORD(DATA:=V37;);
DATA[13] <- RWORD(DATA:=V38;);
DATA[15] <- RWORD(DATA:=V39;);
DATA[17] <- RWORD(DATA:=V40;);
DATA[19] <- RWORD(DATA:=V41;);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
TIMEOUT 300
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.