FIDELIX Analog inputs
Detaljer
- Typ
- Drivrutin
- Upplaggd av
- Ove Jansson, Abelko Innovation
- Version
- 2
- Uppdaterad
- 2019-01-07
- Skapad
- 2013-08-27
- Kategori
- IO enheter, Modbus
- Visningar
- 3555
Beskrivning
Device definition for FIDELIX Analog inputs
Bruksanvisning
See Fidelix I/O-module specifications (pdf)
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Device definition for FIDELIX Analog inputs
%
% Settings module:
% Parity: None
% Baud: 9600
% Mode: RTU
%
% Analog inputs are measured in Voltage
% To calculate Current use formula I = U / 100ohm
% To calculate Resistance use formula R = 4700ohm * U / (2.5V - U)
%
% Author: Peter Widetun, ABELKO AB Luleå
% History: 2009-12-14 Ändrat kommando 4 till kommando 3 Read holding registers
% History: 2019-01-07 Justerat register för "Aktivering AI" till adress 10.
%
%
DEVICETYPE FidelixAIN NAMED "Fidelix A.IN" TYPEID 21220 IS
PARAMETER
Id : "Adress";
EN1 :"Enable AI1";
EN2 :"Enable AI2";
EN3 :"Enable AI3";
EN4 :"Enable AI4";
EN5 :"Enable AI5";
EN6 :"Enable AI6";
EN7 :"Enable AI7";
EN8 :"Enable AI8";
PUBLIC
AI1 : "Analog in 1" ["V"];
AI2 : "Analog in 2" ["V"];
AI3 : "Analog in 3" ["V"];
AI4 : "Analog in 4" ["V"];
AI5 : "Analog in 5" ["V"];
AI6 : "Analog in 6" ["V"];
AI7 : "Analog in 7" ["V"];
AI8 : "Analog in 8" ["V"];
%AI1 : "Analog in 1" ["A"]; %For current measurement
%AI2 : "Analog in 2" ["A"];
%AI3 : "Analog in 3" ["A"];
%AI4 : "Analog in 4" ["A"];
%AI5 : "Analog in 5" ["A"];
%AI6 : "Analog in 6" ["A"];
%AI7 : "Analog in 7" ["A"];
%AI8 : "Analog in 8" ["A"];
%AI1 : "Analog in 1" ["Ohm"]; % For resistance measurement
%AI2 : "Analog in 2" ["Ohm"];
%AI3 : "Analog in 3" ["Ohm"];
%AI4 : "Analog in 4" ["Ohm"];
%AI5 : "Analog in 5" ["Ohm"];
%AI6 : "Analog in 6" ["Ohm"];
%AI7 : "Analog in 7" ["Ohm"];
%AI8 : "Analog in 8" ["Ohm"];
PRIVATE
Tmp;
LB1;
LB2;
LB3;
LB4;
LB5;
LB6;
LB7;
LB8;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM AnalogInput NAMED "Läs AI" IS
QUESTION
DATA[0] := BYTE(Id); % Modbus unit address
DATA[1] := HEX(03); % Modbus command "03h" Read holding registers
DATA[2] := RWORD(0); % Start address register
DATA[4] := RWORD(10); % Number of registers
ANSWER SIZE 25
DATA[0] = BYTE(Id); % ID
DATA[1] = HEX(03); % Modbus command "03h" Read holding registers
DATA[2] = BYTE(20); % Byte count
DATA[19] -> RWORD(
LB1 := (DATA & 15);
LB2 := (DATA & 240) / 16;
LB3 := (DATA & 3840) / 256;
LB4 := (DATA & 61440)/ 4096;
);
DATA[21] -> RWORD(
LB5 := (DATA & 15);
LB6 := (DATA & 240) / 16;
LB7 := (DATA & 3840) / 256;
LB8 := (DATA & 61440)/ 4096;
);
DATA[3] -> RWORD(AI1 := ((DATA*16) + LB1) / 104857.5;); % For Voltage measurement
DATA[5] -> RWORD(AI2 := ((DATA*16) + LB2) / 104857.5;); % Maxbit = 10V
DATA[7] -> RWORD(AI3 := ((DATA*16) + LB3) / 104857.5;);
DATA[9] -> RWORD(AI4 := ((DATA*16) + LB4) / 104857.5;);
DATA[11] -> RWORD(AI5 := ((DATA*16) + LB5) / 104857.5;);
DATA[13] -> RWORD(AI6 := ((DATA*16) + LB6) / 104857.5;);
DATA[15] -> RWORD(AI7 := ((DATA*16) + LB7) / 104857.5;);
DATA[17] -> RWORD(AI8 := ((DATA*16) + LB8) / 104857.5;);
%DATA[3] -> RWORD(AI1 := (2.5 * (DATA*16) + LB1) / 1048575;); % Maxbit = 2.5V
%DATA[5] -> RWORD(AI2 := (2.5 * (DATA*16) + LB2) / 1048575;); % For current measurement I = U / 100Ohm
%DATA[7] -> RWORD(AI3 := (2.5 * (DATA*16) + LB3) / 1048575;);
%DATA[9] -> RWORD(AI4 := (2.5 * (DATA*16) + LB4) / 1048575;);
%DATA[11] -> RWORD(AI5 := (2.5 * (DATA*16) + LB5) / 1048575;);
%DATA[13] -> RWORD(AI6 := (2.5 * (DATA*16) + LB6) / 1048575;);
%DATA[15] -> RWORD(AI7 := (2.5 * (DATA*16) + LB7) / 1048575;);
%DATA[17] -> RWORD(AI8 := (2.5 * (DATA*16) + LB8) / 1048575;);
%DATA[3] -> RWORD(Tmp := (2.5 * (DATA*16) + LB1) / 1048575; % Maxbit = 2.5V
% IF Tmp<2.5 THEN AI1 := (4700 * Tmp) / (2.5 - Tmp); % For resistance measurement R = 470Ohm * U / (2.5V - U)
% ELSE AI1 := 0;
% ENDIF;
% };
%DATA[5] -> RWORD(Tmp := (2.5 * (DATA*16) + LB2) / 1048575;);
% IF Tmp<2.5 THEN AI2 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI2 := 0;
% ENDIF;
% };
%DATA[7] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB3) / 1048575;);
% IF Tmp<2.5 THEN AI3 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI3 := 0;
% ENDIF;
% };
%DATA[9] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB4) / 1048575;);
% IF Tmp<2.5 THEN AI4 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI4 := 0;
% ENDIF;
% };
%DATA[11] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB5) / 1048575;);
% IF Tmp<2.5 THEN AI5 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI5 := 0;
% ENDIF;
% };
%DATA[13] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB6) / 1048575;);
% IF Tmp<2.5 THEN AI6 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI6 := 0;
% ENDIF;
% };
%DATA[15] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB7) / 1048575;);
% IF Tmp<2.5 THEN AI7 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI7 := 0;
% ENDIF;
% };
%DATA[17] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB8) / 1048575;);
% IF Tmp<2.5 THEN AI8 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI8 := 0;
% ENDIF;
% };
TIMEOUT 1000
END;
TELEGRAM AnalogEnable NAMED "Aktivera AI" IS
QUESTION
DATA[0] := BYTE(Id); % Modbus unit address
DATA[1] := HEX(10); % Modbus command "0x10" write multiple registers
DATA[2] := RWORD(10); % start register
DATA[4] := RWORD(1); % number of registers to write
DATA[6] := BYTE(2); % number of bytes
DATA[7] <- RWORD(
IF EN1 THEN Tmp := 1; ELSE Tmp := 0; ENDIF;
IF EN2 THEN Tmp := Tmp + 2; ENDIF;
IF EN3 THEN Tmp := Tmp + 4; ENDIF;
IF EN4 THEN Tmp := Tmp + 8; ENDIF;
IF EN5 THEN Tmp := Tmp + 16; ENDIF;
IF EN6 THEN Tmp := Tmp + 32; ENDIF;
IF EN7 THEN Tmp := Tmp + 64; ENDIF;
IF EN8 THEN Tmp := Tmp + 128; ENDIF;
DATA := Tmp;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
%DATA[2] = RWORD(10); % start register
%DATA[4] = RWORD(1); % number of registers to write
TIMEOUT 300
END;
END;
% Device definition for FIDELIX Analog inputs
%
% Settings module:
% Parity: None
% Baud: 9600
% Mode: RTU
%
% Analog inputs are measured in Voltage
% To calculate Current use formula I = U / 100ohm
% To calculate Resistance use formula R = 4700ohm * U / (2.5V - U)
%
% Author: Peter Widetun, ABELKO AB Luleå
% History: 2009-12-14 Ändrat kommando 4 till kommando 3 Read holding registers
% History: 2019-01-07 Justerat register för "Aktivering AI" till adress 10.
%
%
DEVICETYPE FidelixAIN NAMED "Fidelix A.IN" TYPEID 21220 IS
PARAMETER
Id : "Adress";
EN1 :"Enable AI1";
EN2 :"Enable AI2";
EN3 :"Enable AI3";
EN4 :"Enable AI4";
EN5 :"Enable AI5";
EN6 :"Enable AI6";
EN7 :"Enable AI7";
EN8 :"Enable AI8";
PUBLIC
AI1 : "Analog in 1" ["V"];
AI2 : "Analog in 2" ["V"];
AI3 : "Analog in 3" ["V"];
AI4 : "Analog in 4" ["V"];
AI5 : "Analog in 5" ["V"];
AI6 : "Analog in 6" ["V"];
AI7 : "Analog in 7" ["V"];
AI8 : "Analog in 8" ["V"];
%AI1 : "Analog in 1" ["A"]; %For current measurement
%AI2 : "Analog in 2" ["A"];
%AI3 : "Analog in 3" ["A"];
%AI4 : "Analog in 4" ["A"];
%AI5 : "Analog in 5" ["A"];
%AI6 : "Analog in 6" ["A"];
%AI7 : "Analog in 7" ["A"];
%AI8 : "Analog in 8" ["A"];
%AI1 : "Analog in 1" ["Ohm"]; % For resistance measurement
%AI2 : "Analog in 2" ["Ohm"];
%AI3 : "Analog in 3" ["Ohm"];
%AI4 : "Analog in 4" ["Ohm"];
%AI5 : "Analog in 5" ["Ohm"];
%AI6 : "Analog in 6" ["Ohm"];
%AI7 : "Analog in 7" ["Ohm"];
%AI8 : "Analog in 8" ["Ohm"];
PRIVATE
Tmp;
LB1;
LB2;
LB3;
LB4;
LB5;
LB6;
LB7;
LB8;
BAUDRATE 9600;
CHECKSUM MODBUS SWAPPED;
TELEGRAM AnalogInput NAMED "Läs AI" IS
QUESTION
DATA[0] := BYTE(Id); % Modbus unit address
DATA[1] := HEX(03); % Modbus command "03h" Read holding registers
DATA[2] := RWORD(0); % Start address register
DATA[4] := RWORD(10); % Number of registers
ANSWER SIZE 25
DATA[0] = BYTE(Id); % ID
DATA[1] = HEX(03); % Modbus command "03h" Read holding registers
DATA[2] = BYTE(20); % Byte count
DATA[19] -> RWORD(
LB1 := (DATA & 15);
LB2 := (DATA & 240) / 16;
LB3 := (DATA & 3840) / 256;
LB4 := (DATA & 61440)/ 4096;
);
DATA[21] -> RWORD(
LB5 := (DATA & 15);
LB6 := (DATA & 240) / 16;
LB7 := (DATA & 3840) / 256;
LB8 := (DATA & 61440)/ 4096;
);
DATA[3] -> RWORD(AI1 := ((DATA*16) + LB1) / 104857.5;); % For Voltage measurement
DATA[5] -> RWORD(AI2 := ((DATA*16) + LB2) / 104857.5;); % Maxbit = 10V
DATA[7] -> RWORD(AI3 := ((DATA*16) + LB3) / 104857.5;);
DATA[9] -> RWORD(AI4 := ((DATA*16) + LB4) / 104857.5;);
DATA[11] -> RWORD(AI5 := ((DATA*16) + LB5) / 104857.5;);
DATA[13] -> RWORD(AI6 := ((DATA*16) + LB6) / 104857.5;);
DATA[15] -> RWORD(AI7 := ((DATA*16) + LB7) / 104857.5;);
DATA[17] -> RWORD(AI8 := ((DATA*16) + LB8) / 104857.5;);
%DATA[3] -> RWORD(AI1 := (2.5 * (DATA*16) + LB1) / 1048575;); % Maxbit = 2.5V
%DATA[5] -> RWORD(AI2 := (2.5 * (DATA*16) + LB2) / 1048575;); % For current measurement I = U / 100Ohm
%DATA[7] -> RWORD(AI3 := (2.5 * (DATA*16) + LB3) / 1048575;);
%DATA[9] -> RWORD(AI4 := (2.5 * (DATA*16) + LB4) / 1048575;);
%DATA[11] -> RWORD(AI5 := (2.5 * (DATA*16) + LB5) / 1048575;);
%DATA[13] -> RWORD(AI6 := (2.5 * (DATA*16) + LB6) / 1048575;);
%DATA[15] -> RWORD(AI7 := (2.5 * (DATA*16) + LB7) / 1048575;);
%DATA[17] -> RWORD(AI8 := (2.5 * (DATA*16) + LB8) / 1048575;);
%DATA[3] -> RWORD(Tmp := (2.5 * (DATA*16) + LB1) / 1048575; % Maxbit = 2.5V
% IF Tmp<2.5 THEN AI1 := (4700 * Tmp) / (2.5 - Tmp); % For resistance measurement R = 470Ohm * U / (2.5V - U)
% ELSE AI1 := 0;
% ENDIF;
% };
%DATA[5] -> RWORD(Tmp := (2.5 * (DATA*16) + LB2) / 1048575;);
% IF Tmp<2.5 THEN AI2 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI2 := 0;
% ENDIF;
% };
%DATA[7] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB3) / 1048575;);
% IF Tmp<2.5 THEN AI3 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI3 := 0;
% ENDIF;
% };
%DATA[9] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB4) / 1048575;);
% IF Tmp<2.5 THEN AI4 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI4 := 0;
% ENDIF;
% };
%DATA[11] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB5) / 1048575;);
% IF Tmp<2.5 THEN AI5 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI5 := 0;
% ENDIF;
% };
%DATA[13] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB6) / 1048575;);
% IF Tmp<2.5 THEN AI6 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI6 := 0;
% ENDIF;
% };
%DATA[15] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB7) / 1048575;);
% IF Tmp<2.5 THEN AI7 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI7 := 0;
% ENDIF;
% };
%DATA[17] -> RWORD(Tmp := 2.5 * ((DATA*16) + LB8) / 1048575;);
% IF Tmp<2.5 THEN AI8 := (4700 * Tmp) / (2.5 - Tmp);
% ELSE AI8 := 0;
% ENDIF;
% };
TIMEOUT 1000
END;
TELEGRAM AnalogEnable NAMED "Aktivera AI" IS
QUESTION
DATA[0] := BYTE(Id); % Modbus unit address
DATA[1] := HEX(10); % Modbus command "0x10" write multiple registers
DATA[2] := RWORD(10); % start register
DATA[4] := RWORD(1); % number of registers to write
DATA[6] := BYTE(2); % number of bytes
DATA[7] <- RWORD(
IF EN1 THEN Tmp := 1; ELSE Tmp := 0; ENDIF;
IF EN2 THEN Tmp := Tmp + 2; ENDIF;
IF EN3 THEN Tmp := Tmp + 4; ENDIF;
IF EN4 THEN Tmp := Tmp + 8; ENDIF;
IF EN5 THEN Tmp := Tmp + 16; ENDIF;
IF EN6 THEN Tmp := Tmp + 32; ENDIF;
IF EN7 THEN Tmp := Tmp + 64; ENDIF;
IF EN8 THEN Tmp := Tmp + 128; ENDIF;
DATA := Tmp;
);
ANSWER SIZE 8
DATA[0] = BYTE(Id);
DATA[1] = HEX(10);
%DATA[2] = RWORD(10); % start register
%DATA[4] = RWORD(1); % number of registers to write
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.