{"id":316806,"date":"2021-01-22T15:01:34","date_gmt":"2021-01-22T15:01:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=316806"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=316806","title":{"rendered":"CodeSys \u043d\u0430 RaspberryPi 3 model B \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439+MS SQL. \u0420\u0430\u0441\u0447\u0435\u0442 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438, \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0433\u043e\u0444\u0440\u043e\u0430\u0433\u0440\u0435\u0433\u0430\u0442\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h3>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h3>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 (\u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0440\u0438\u0446)<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0440\u0430\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyODBC<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MsSQL Library SL<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0430\u0441\u0447\u0435\u0442 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 (\u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0440\u0438\u0446)<\/h3>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0438 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0410 6*6, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0412 p*f, \u0433\u0434\u0435 p=5 \u2013 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0433\u043e\u0444\u0440\u044b, f=5 \u2013 \u0444\u043e\u0440\u043c\u0430\u0442, \u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 Z<sub>p<\/sub> \u2013 \u0441\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0433\u043e\u0444\u0440\u044b \u0438 Z<sub>f &nbsp;<\/sub>&#8212; \u0441\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 Zp \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410, Zf \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0441\u0442\u0440\u043e\u043a \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410. \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2013 a66, \u044d\u0442\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0435\u0439 \u0434\u043b\u0438\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0435 2 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: Sp \u2013 \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0438 Sf \u2013 \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u0430- \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 F \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u2013 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0441\u044b\u0440\u044c\u044f.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b31\/e49\/3b6\/b31e493b6eda34714b54adc2b03fb231.jpg\" width=\"555\" height=\"418\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/369\/812\/048\/36981204842e82f44c4551f9423c93aa.jpg\" width=\"624\" height=\"453\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c! \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u0435\u0431\u0440\u0430.<\/p>\n<p>\u0421\u0443\u043c\u043c\u0430 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18b\/9f9\/8e9\/18b9f98e9275b9298650b6dadd5be226.jpg\" width=\"220\" height=\"125\"><figcaption><\/figcaption><\/figure>\n<p>&nbsp;\u0420\u0430\u0441\u0447\u0435\u0442 \u043f\u043b\u043e\u0449\u0430\u0434\u0435\u0439 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c 2 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410 \u0438 F<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/588\/a4b\/b0d\/588a4bb0de47a229fc505e8700333003.jpg\" width=\"257\" height=\"49\"><figcaption><\/figcaption><\/figure>\n<p>\u0438\u043b\u0438<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b25\/a88\/df4\/b25a88df4a4044681f24448c58febd0f.jpg\" width=\"254\" height=\"17\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0433\u043e\u0444\u0440\u044b: <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/881\/b32\/db8\/881b32db8768cd9488a11d77b93dd539.jpg\" width=\"233\" height=\"53\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK Format_math VAR_INPUT     EN:BOOL;     imp:BOOL; END_VAR VAR_INPUT RETAIN     f:INT := 1;     p:INT := 1; END_VAR VAR_INPUT     l_roll:REAL;     k_imp:INT;     res:BOOL;     res_month:BOOL; END_VAR VAR_OUTPUT     \/\/ \u043c\u0430\u0441\u0441\u0438\u0432 [f,p], f=6 - \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c, p=6 - \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c     length_f:ARRAY[1..6, 1..6] OF REAL;     wS_f:ARRAY [1..5] OF WORD;     wS_p:ARRAY [1..5] OF WORD; END_VAR VAR_OUTPUT RETAIN     S_f:ARRAY [1..5] OF REAL;     S_p:ARRAY [1..5] OF REAL; END_VAR VAR_OUTPUT     S_f_month:ARRAY [1..5] OF REAL;     S_p_month:ARRAY [1..5] OF REAL; END_VAR VAR     imp_old:BOOL;     f_b: ARRAY [1..5] OF BOOL;     p_b: ARRAY [1..5] OF BOOL;     length_f_old:ARRAY[1..6, 1..6] OF REAL;     i:BYTE;     j: BYTE;     k:REAL; END_VAR BEGIN   k:=l_roll\/(k_imp*1000);   IF EN AND not imp AND imp_old THEN       length_f[f,p]:=length_f[f,p]+k;       \/\/length_p[p]:=length_p[p]+(l_roll\/(k_imp*1000));   END_IF   FOR i:=1 TO 5 DO        length_f[i,6]:=0;       length_f[6,i]:=0;       FOR j:=1 TO 5 DO            length_f[i,6]:=length_f[i,6]+length_f[i,j];           length_f[6,i]:=length_f[6,i]+length_f[j,i];       END_FOR    END_FOR   CASE f OF           1: S_f[f]:=length_f[f,6]*1.050\/1000;            2: S_f[f]:=length_f[f,6]*1.250\/1000;            3: S_f[f]:=length_f[f,6]*1.400\/1000;            4: S_f[f]:=length_f[f,6]*1.575\/1000;            5: S_f[f]:=length_f[f,6]*1.600\/1000;    END_CASE    FOR i:=1 TO 5 DO        S_p[i]:=length_f[1,i]*1.05\/1000+length_f[2,i]*1.25\/1000+length_f[3,i]*1.4\/1000+length_f[4,i]*1.575\/1000+length_f[5,i]*1.6\/1000;       wS_p[i]:=REAL_TO_WORD(S_p[i]*10);       wS_f[i]:=REAL_TO_WORD(S_f[i]*10);   END_FOR   IF res THEN       FOR i:=1 TO 6 DO            FOR j:=1 TO 6 DO                length_f_old[i,j]:=length_f[i,j];               length_f[i,j]:=0;           END_FOR        END_FOR       FOR i:=1 TO 5 DO           S_f_month[i]:=S_f_month[i]+S_f[i];           S_f[i]:=0;           S_p_month[i]:=S_p_month[i]+S_p[i];           S_p[i]:=0;       END_FOR   END_IF    IF res_month THEN       FOR i:=1 TO 5 DO            S_f_month[i]:=0;           S_p_month[i]:=0;       END_FOR   END_IF    FOR i:=1 TO 5 DO f_b[i]:=0; END_FOR   FOR i:=1 TO 5 DO p_b[i]:=0; END_FOR   f_b[f]:=TRUE;   p_b[p]:=TRUE;   imp_old:=imp; END <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0417\u0430\u0442\u0440\u0430\u0442\u044b<\/h3>\n<ul>\n<li>\n<p>RPI 3 model B \u0437\u0430 4 \u0442\u044b\u0441\u044f\u0447\u0438 \u0440\u0443\u0431\u043b\u0435\u0439 (\u043d\u0430 AliExpress 3 \u0442\u044b\u0441. \u0440\u0443\u0431.). \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0448\u0435\u0432\u043e\u0439 RPI zero (2 \u0442\u044b\u0441. \u0440\u0443\u0431.), \u043d\u043e \u0440\u0430\u043c\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0438 \u0440\u0430\u0437\u043c\u044b\u0442\u044b \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0422\u0417 (\u0434\u0430\u0432\u0430\u0439 \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0442\u043e\u2026 \u0442\u043e\u2026 \u0438 \u0442\u043e\u2026);<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u0442\u0430 \u0441 \u043e\u043f\u0442\u043e\u0440\u0430\u0437\u0432\u044f\u0437\u043a\u0430\u043c\u0438 24\/5\u0412 \u043d\u0430 AliExpress 300 \u0440\u0443\u0431. (\u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u043f\u043b\u0430\u0442\u044b);<\/p>\n<\/li>\n<li>\n<p>CODESYS Control for Raspberry Pi SL 50 \u0435\u0432\u0440\u043e. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 RealTime 2 \u0447\u0430\u0441\u0430, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyODBC<\/h4>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3bf\/e72\/8fc\/3bfe728fc0155a55b1615911c0761ac5.jpg\" width=\"668\" height=\"412\"><figcaption><\/figcaption><\/figure>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 ODBC \u043d\u0430 Raspberry<\/h3>\n<p>\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo apt-get install python3-dev unixodbc-dev git pi@raspberrypi:~ $ git clone https:\/\/github.com\/mkleehammer\/pyodbc pi@raspberrypi:~ $ cd pythodbc pi@raspberrypi:~ $ import pyodbc pi@raspberrypi:~ $ python3 setup.py pi@raspberrypi:~ $ cd \/home\/pi\/pyodbc pi@raspberrypi:~ $ sudo python3 setup.py build pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install g++ pi@raspberrypi:~ $ sudo apt-get install unixodbc-dev pi@raspberrypi:~ $ pip install pyodbc pi@raspberrypi:~ $ odbcinst -j pi@raspberrypi:~ $ cat \/etc\/odbcinst.ini \t[FreeTDS] \tDescription=FreeTDS Driver v0.91 \tDriver=\/usr\/lib\/arm-linux-gnueabihf\/odbc\/libtdsodbc.so \tSetup=\/usr\/lib\/arm-linux-gnueabihf\/odbc\/libtdsS.so \tfileusage=1 \tdontdlclose=1 \tUsageCount=1 pi@raspberrypi:~ $ cat \/etc\/odbc.ini \tDriver = FreeTDS \tDescription = My Test Server \tTrace = No \tServerName = mssql \t#Port = port \tinstance = MSSQLSERVER #(whatever is the service u r runningcould be SQLEXPRESS) \tDatabase = database_name \tTDS_Version = 4.2 pi@raspberrypi:~ $ sudo nano \/etc\/freetds\/freetds.conf \t[egServer70]         host = ntmachine.domain.com         port = 1433         tds version = 7.0 \t[mssql]         host = server_ip_adress         instance = MSSQLSERVER         #Port = port          tds version = 4.2 <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo python3 \t&gt;&gt;&gt; server = '192.168.1.2' \t&gt;&gt;&gt; port = '1433' \t&gt;&gt;&gt; database = 'GA'  \t&gt;&gt;&gt; username = 'plc'  \t&gt;&gt;&gt; password = '123456'  \t&gt;&gt;&gt; cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password) \t&gt;&gt;&gt; cursor = cnxn.cursor() \t&gt;&gt;&gt; cursor.execute('select top 10 ID,Val,Date_Time from tbl_Val') \t#cursor.execute('INSERT INTO tbl_Val (ID, Val) VALUES (15, 20)') \t&gt;&gt;&gt; rows=cursor.fetchall() \t&gt;&gt;&gt; for row in rows: print(row.ID, row.Val) <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \/home\/pi\/pyodbc\/ \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u201cquery.py\u201d. \u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0434, \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<pre><code class=\"python\">import pyodbc import sys  cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+sys.argv[1]+';PORT='+sys.argv[2]+                       ';DATABASE='+sys.argv[3]+';UID='+sys.argv[4]+';PWD='                       + sys.argv[5]) cursor = cnxn.cursor()  cursor.execute('INSERT INTO [Py_Tbl] ([ID], [Val]) VALUES ('+sys.argv[6]+','                +sys.argv[7]+')') cnxn.commit()<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0438\u043c\u0435\u0435\u0442 5 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0411\u0414:<\/p>\n<ul>\n<li>\n<p>\u0421\u0435\u0442\u0435\u0432\u043e\u0435 \u0438\u043c\u044f \u0438\u043b\u0438 IP \u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430; <\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0440\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u0443 MSSQL \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 1433);<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043d;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u043e\u043b\u044c;<\/p>\n<\/li>\n<li>\n<p>ID \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435 SQL_Insert \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u041f\u041b\u041a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0432 \u043d\u0435\u0439 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK SQL_Insert VAR_INPUT \txExecuteScript: BOOL;\t \tServer:STRING := '192.168.1.2'; \tPORT:INT := 1433; \tDB_Name:STRING := 'GA'; \tlogin:STRING := 'plc'; \tpassword:STRING := '123456';\t \tID: INT; \tVal: REAL;  END_VAR VAR\t pResult: POINTER TO SysProcess.SysTypes.RTS_IEC_RESULT; \tText: string; END_VAR BEGIN   IF xExecuteScript THEN     text:='sudo python \/home\/pi\/pyodbc\/query.py ';     text:=concat(text,Server);     text:=concat(text,' ');     text:=concat(text,INT_TO_STRING(Port));     text:=concat(text,' ');     text:=concat(text,DB_Name);     text:=concat(text,' ');     text:=concat(text,login);     text:=concat(text,' ');     text:=concat(text,password);     text:=concat(text,' ');     text:=concat(text,INT_TO_STRING(id));     text:=concat(text,' ');     text:=concat(text,REAL_TO_STRING(Val));     SysProcess.SysProcessExecuteCommand(text,pResult);     xExecuteScript:=FALSE;   END_IF END<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u041f\u041b\u041a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 query.py \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u042d\u0442\u043e \u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo python \/home\/pi\/pyodbc\/query.py server port DB_name login pass id Value<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435 DB_send \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u044b ID \u0438\u0437 10 \u044f\u0447\u0435\u0435\u043a \u0442\u0438\u043f\u0430 integer \u0438 Val \u0438\u0437 10 \u044f\u0447\u0435\u0435\u043a \u0442\u0438\u043f\u0430 real. <\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK DB_Send VAR_INPUT \tid:ARRAY[1..10] OF INT; \tval:ARRAY[1..10] OF REAL; \tTime_send:TIME :=T#60S; END_VAR VAR \tSQL_Ins: SQL_Insert; \tTONInst: TON; \ti: int; END_VAR BEGIN   TONInst(IN := NOT(TONInst.Q), PT:= Time_send); \tIF  TONinst.Q THEN \t\tFOR i:=1 TO 10 DO \t\t\tIF id[i]&lt;&gt;0 THEN \t\t\t\tsql_ins(xExecuteScript:=true, ID:=id[i], val:=val[i]);  \t\t\tEND_IF \t\tEND_FOR \tEND_IF END<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p> \u041a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u041a\u0430\u0436\u0434\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 DB_Send \u0438\u0437 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0424\u0411 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f ID-&gt;Val \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 SQL_Inset \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 Python \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041c\u0435\u0442\u043e\u0434\u043e\u043c <em>pyodbc.connect<\/em> \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 <em>cursor.execute <\/em>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441 INSERT\u2026 \u0414\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0437\u0435.<\/p>\n<h3>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MsSQL Library SL<\/h3>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42b\/b0d\/528\/42bb0d5288088735a50eaf737c483756.jpg\" width=\"572\" height=\"426\"><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0442 3S-Smart Software Solutions GmbH MsSQL Library SL \u2013 \u044d\u0442\u043e <u>\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 <\/u>\u0438 \u0434\u043e\u0440\u043e\u0433\u043e\u0439 (200\u20ac) \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u041f\u041b\u041a, \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 MsSQL \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 TDS \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 2 \u0447\u0430\u0441\u0430, \u0437\u0430\u0431\u0435\u0433\u0430\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u0434, \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u043d\u044b\u0435 2 \u0447\u0430\u0441\u0430 \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u043b\u043e, \u043d\u0435 \u0438\u0434\u0435\u0442 \u043d\u0438 \u0432 \u043a\u0430\u043a\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439 PyODBC.<\/p>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>SELECT <\/p>\n<\/li>\n<li>\n<p>INSERT<\/p>\n<\/li>\n<li>\n<p>UPDATE<\/p>\n<\/li>\n<li>\n<p>DELETE<\/p>\n<\/li>\n<li>\n<p>Execute Stored procedures<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 5 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 SQL \u0432 IEC:<\/p>\n<ul>\n<li>\n<p>BOOL <\/p>\n<\/li>\n<li>\n<p>DINT <\/p>\n<\/li>\n<li>\n<p>REAL<\/p>\n<\/li>\n<li>\n<p>STRING <\/p>\n<\/li>\n<li>\n<p>DATETIME<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 4-\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>fbMsSQL_compact \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>fbMsSQL \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>fbPing \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>fbFIFOQuery \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 SQL \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u043c\u0435\u0435\u0442 4 default-\u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<ul>\n<li>\n<p>\u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0432\u0445\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u043e\u043a\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u043e\u043a\u043d\u043e \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 store.codesys.com \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 MsSQL Library SL \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 ..\\CODESYS MsSQL SL Library\\V1.4.0.5\\Examples\\Raspberry Pi target \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. <\/p>\n<p>\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d54\/d37\/99e\/d54d3799e5ce2de5d5a841e5567dbcb5.jpg\" width=\"614\" height=\"286\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/538648\/\"> https:\/\/habr.com\/ru\/post\/538648\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h3>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h3>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 (\u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0440\u0438\u0446)<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0440\u0430\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyODBC<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MsSQL Library SL<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0430\u0441\u0447\u0435\u0442 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u0438 \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 (\u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0440\u0438\u0446)<\/h3>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u0430 \u043c\u0435\u0442\u0440\u0430\u0436\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0438 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0410 6*6, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0412 p*f, \u0433\u0434\u0435 p=5 \u2013 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0433\u043e\u0444\u0440\u044b, f=5 \u2013 \u0444\u043e\u0440\u043c\u0430\u0442, \u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 Z<sub>p<\/sub> \u2013 \u0441\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0433\u043e\u0444\u0440\u044b \u0438 Z<sub>f &nbsp;<\/sub>&#8212; \u0441\u0443\u043c\u043c\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 Zp \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410, Zf \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0443\u043c\u043c\u0443 \u0441\u0442\u0440\u043e\u043a \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410. \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2013 a66, \u044d\u0442\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0435\u0439 \u0434\u043b\u0438\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0435 2 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: Sp \u2013 \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0438 Sf \u2013 \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u0430- \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430 F \u2013 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0438\u0437 5-\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u2013 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0441\u044b\u0440\u044c\u044f.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c! \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u0435\u0431\u0440\u0430.<\/p>\n<p>\u0421\u0443\u043c\u043c\u0430 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u0438 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>&nbsp;\u0420\u0430\u0441\u0447\u0435\u0442 \u043f\u043b\u043e\u0449\u0430\u0434\u0435\u0439 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c 2 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0410 \u0438 F<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0438\u043b\u0438<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c \u0433\u043e\u0444\u0440\u044b: <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK Format_math VAR_INPUT     EN:BOOL;     imp:BOOL; END_VAR VAR_INPUT RETAIN     f:INT := 1;     p:INT := 1; END_VAR VAR_INPUT     l_roll:REAL;     k_imp:INT;     res:BOOL;     res_month:BOOL; END_VAR VAR_OUTPUT     \/\/ \u043c\u0430\u0441\u0441\u0438\u0432 [f,p], f=6 - \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u043c, p=6 - \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c     length_f:ARRAY[1..6, 1..6] OF REAL;     wS_f:ARRAY [1..5] OF WORD;     wS_p:ARRAY [1..5] OF WORD; END_VAR VAR_OUTPUT RETAIN     S_f:ARRAY [1..5] OF REAL;     S_p:ARRAY [1..5] OF REAL; END_VAR VAR_OUTPUT     S_f_month:ARRAY [1..5] OF REAL;     S_p_month:ARRAY [1..5] OF REAL; END_VAR VAR     imp_old:BOOL;     f_b: ARRAY [1..5] OF BOOL;     p_b: ARRAY [1..5] OF BOOL;     length_f_old:ARRAY[1..6, 1..6] OF REAL;     i:BYTE;     j: BYTE;     k:REAL; END_VAR BEGIN   k:=l_roll\/(k_imp*1000);   IF EN AND not imp AND imp_old THEN       length_f[f,p]:=length_f[f,p]+k;       \/\/length_p[p]:=length_p[p]+(l_roll\/(k_imp*1000));   END_IF   FOR i:=1 TO 5 DO        length_f[i,6]:=0;       length_f[6,i]:=0;       FOR j:=1 TO 5 DO            length_f[i,6]:=length_f[i,6]+length_f[i,j];           length_f[6,i]:=length_f[6,i]+length_f[j,i];       END_FOR    END_FOR   CASE f OF           1: S_f[f]:=length_f[f,6]*1.050\/1000;            2: S_f[f]:=length_f[f,6]*1.250\/1000;            3: S_f[f]:=length_f[f,6]*1.400\/1000;            4: S_f[f]:=length_f[f,6]*1.575\/1000;            5: S_f[f]:=length_f[f,6]*1.600\/1000;    END_CASE    FOR i:=1 TO 5 DO        S_p[i]:=length_f[1,i]*1.05\/1000+length_f[2,i]*1.25\/1000+length_f[3,i]*1.4\/1000+length_f[4,i]*1.575\/1000+length_f[5,i]*1.6\/1000;       wS_p[i]:=REAL_TO_WORD(S_p[i]*10);       wS_f[i]:=REAL_TO_WORD(S_f[i]*10);   END_FOR   IF res THEN       FOR i:=1 TO 6 DO            FOR j:=1 TO 6 DO                length_f_old[i,j]:=length_f[i,j];               length_f[i,j]:=0;           END_FOR        END_FOR       FOR i:=1 TO 5 DO           S_f_month[i]:=S_f_month[i]+S_f[i];           S_f[i]:=0;           S_p_month[i]:=S_p_month[i]+S_p[i];           S_p[i]:=0;       END_FOR   END_IF    IF res_month THEN       FOR i:=1 TO 5 DO            S_f_month[i]:=0;           S_p_month[i]:=0;       END_FOR   END_IF    FOR i:=1 TO 5 DO f_b[i]:=0; END_FOR   FOR i:=1 TO 5 DO p_b[i]:=0; END_FOR   f_b[f]:=TRUE;   p_b[p]:=TRUE;   imp_old:=imp; END <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0417\u0430\u0442\u0440\u0430\u0442\u044b<\/h3>\n<ul>\n<li>\n<p>RPI 3 model B \u0437\u0430 4 \u0442\u044b\u0441\u044f\u0447\u0438 \u0440\u0443\u0431\u043b\u0435\u0439 (\u043d\u0430 AliExpress 3 \u0442\u044b\u0441. \u0440\u0443\u0431.). \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0448\u0435\u0432\u043e\u0439 RPI zero (2 \u0442\u044b\u0441. \u0440\u0443\u0431.), \u043d\u043e \u0440\u0430\u043c\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0438 \u0440\u0430\u0437\u043c\u044b\u0442\u044b \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0422\u0417 (\u0434\u0430\u0432\u0430\u0439 \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0442\u043e\u2026 \u0442\u043e\u2026 \u0438 \u0442\u043e\u2026);<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u0442\u0430 \u0441 \u043e\u043f\u0442\u043e\u0440\u0430\u0437\u0432\u044f\u0437\u043a\u0430\u043c\u0438 24\/5\u0412 \u043d\u0430 AliExpress 300 \u0440\u0443\u0431. (\u0432 \u0420\u043e\u0441\u0441\u0438\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u043f\u043b\u0430\u0442\u044b);<\/p>\n<\/li>\n<li>\n<p>CODESYS Control for Raspberry Pi SL 50 \u0435\u0432\u0440\u043e. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 RealTime 2 \u0447\u0430\u0441\u0430, \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyODBC<\/h4>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 ODBC \u043d\u0430 Raspberry<\/h3>\n<p>\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo apt-get install python3-dev unixodbc-dev git pi@raspberrypi:~ $ git clone https:\/\/github.com\/mkleehammer\/pyodbc pi@raspberrypi:~ $ cd pythodbc pi@raspberrypi:~ $ import pyodbc pi@raspberrypi:~ $ python3 setup.py pi@raspberrypi:~ $ cd \/home\/pi\/pyodbc pi@raspberrypi:~ $ sudo python3 setup.py build pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install g++ pi@raspberrypi:~ $ sudo apt-get install unixodbc-dev pi@raspberrypi:~ $ pip install pyodbc pi@raspberrypi:~ $ odbcinst -j pi@raspberrypi:~ $ cat \/etc\/odbcinst.ini \t[FreeTDS] \tDescription=FreeTDS Driver v0.91 \tDriver=\/usr\/lib\/arm-linux-gnueabihf\/odbc\/libtdsodbc.so \tSetup=\/usr\/lib\/arm-linux-gnueabihf\/odbc\/libtdsS.so \tfileusage=1 \tdontdlclose=1 \tUsageCount=1 pi@raspberrypi:~ $ cat \/etc\/odbc.ini \tDriver = FreeTDS \tDescription = My Test Server \tTrace = No \tServerName = mssql \t#Port = port \tinstance = MSSQLSERVER #(whatever is the service u r runningcould be SQLEXPRESS) \tDatabase = database_name \tTDS_Version = 4.2 pi@raspberrypi:~ $ sudo nano \/etc\/freetds\/freetds.conf \t[egServer70]         host = ntmachine.domain.com         port = 1433         tds version = 7.0 \t[mssql]         host = server_ip_adress         instance = MSSQLSERVER         #Port = port          tds version = 4.2 <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo python3 \t&gt;&gt;&gt; server = '192.168.1.2' \t&gt;&gt;&gt; port = '1433' \t&gt;&gt;&gt; database = 'GA'  \t&gt;&gt;&gt; username = 'plc'  \t&gt;&gt;&gt; password = '123456'  \t&gt;&gt;&gt; cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password) \t&gt;&gt;&gt; cursor = cnxn.cursor() \t&gt;&gt;&gt; cursor.execute('select top 10 ID,Val,Date_Time from tbl_Val') \t#cursor.execute('INSERT INTO tbl_Val (ID, Val) VALUES (15, 20)') \t&gt;&gt;&gt; rows=cursor.fetchall() \t&gt;&gt;&gt; for row in rows: print(row.ID, row.Val) <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \/home\/pi\/pyodbc\/ \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u201cquery.py\u201d. \u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0434, \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<pre><code class=\"python\">import pyodbc import sys  cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+sys.argv[1]+';PORT='+sys.argv[2]+                       ';DATABASE='+sys.argv[3]+';UID='+sys.argv[4]+';PWD='                       + sys.argv[5]) cursor = cnxn.cursor()  cursor.execute('INSERT INTO [Py_Tbl] ([ID], [Val]) VALUES ('+sys.argv[6]+','                +sys.argv[7]+')') cnxn.commit()<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0438\u043c\u0435\u0435\u0442 5 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0411\u0414:<\/p>\n<ul>\n<li>\n<p>\u0421\u0435\u0442\u0435\u0432\u043e\u0435 \u0438\u043c\u044f \u0438\u043b\u0438 IP \u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430; <\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0440\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u0443 MSSQL \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 1433);<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043d;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u043e\u043b\u044c;<\/p>\n<\/li>\n<li>\n<p>ID \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435 SQL_Insert \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u041f\u041b\u041a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0432 \u043d\u0435\u0439 \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK SQL_Insert VAR_INPUT \txExecuteScript: BOOL;\t \tServer:STRING := '192.168.1.2'; \tPORT:INT := 1433; \tDB_Name:STRING := 'GA'; \tlogin:STRING := 'plc'; \tpassword:STRING := '123456';\t \tID: INT; \tVal: REAL;  END_VAR VAR\t pResult: POINTER TO SysProcess.SysTypes.RTS_IEC_RESULT; \tText: string; END_VAR BEGIN   IF xExecuteScript THEN     text:='sudo python \/home\/pi\/pyodbc\/query.py ';     text:=concat(text,Server);     text:=concat(text,' ');     text:=concat(text,INT_TO_STRING(Port));     text:=concat(text,' ');     text:=concat(text,DB_Name);     text:=concat(text,' ');     text:=concat(text,login);     text:=concat(text,' ');     text:=concat(text,password);     text:=concat(text,' ');     text:=concat(text,INT_TO_STRING(id));     text:=concat(text,' ');     text:=concat(text,REAL_TO_STRING(Val));     SysProcess.SysProcessExecuteCommand(text,pResult);     xExecuteScript:=FALSE;   END_IF END<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u041f\u041b\u041a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 query.py \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u042d\u0442\u043e \u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"python\">pi@raspberrypi:~ $ sudo python \/home\/pi\/pyodbc\/query.py server port DB_name login pass id Value<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435 DB_send \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u044b ID \u0438\u0437 10 \u044f\u0447\u0435\u0435\u043a \u0442\u0438\u043f\u0430 integer \u0438 Val \u0438\u0437 10 \u044f\u0447\u0435\u0435\u043a \u0442\u0438\u043f\u0430 real. <\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">FUNCTION_BLOCK DB_Send VAR_INPUT \tid:ARRAY[1..10] OF INT; \tval:ARRAY[1..10] OF REAL; \tTime_send:TIME :=T#60S; END_VAR VAR \tSQL_Ins: SQL_Insert; \tTONInst: TON; \ti: int; END_VAR BEGIN   TONInst(IN := NOT(TONInst.Q), PT:= Time_send); \tIF  TONinst.Q THEN \t\tFOR i:=1 TO 10 DO \t\t\tIF id[i]&lt;&gt;0 THEN \t\t\t\tsql_ins(xExecuteScript:=true, ID:=id[i], val:=val[i]);  \t\t\tEND_IF \t\tEND_FOR \tEND_IF END<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p> \u041a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u041a\u0430\u0436\u0434\u044b\u0439 \u0446\u0438\u043a\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 DB_Send \u0438\u0437 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0424\u0411 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f ID-&gt;Val \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 SQL_Inset \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 Python \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041c\u0435\u0442\u043e\u0434\u043e\u043c <em>pyodbc.connect<\/em> \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 <em>cursor.execute <\/em>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441 INSERT\u2026 \u0414\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0437\u0435.<\/p>\n<h3>\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e MsSQL Library SL<\/h3>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0442 3S-Smart Software Solutions GmbH MsSQL Library SL \u2013 \u044d\u0442\u043e <u>\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 <\/u>\u0438 \u0434\u043e\u0440\u043e\u0433\u043e\u0439 (200\u20ac) \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u041f\u041b\u041a, \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0411\u0414 MsSQL \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 TDS \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b. \u0412 \u0434\u0435\u043c\u043e-\u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 2 \u0447\u0430\u0441\u0430, \u0437\u0430\u0431\u0435\u0433\u0430\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u0434, \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u043d\u044b\u0435 2 \u0447\u0430\u0441\u0430 \u043d\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u043b\u043e, \u043d\u0435 \u0438\u0434\u0435\u0442 \u043d\u0438 \u0432 \u043a\u0430\u043a\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439 PyODBC.<\/p>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>SELECT <\/p>\n<\/li>\n<li>\n<p>INSERT<\/p>\n<\/li>\n<li>\n<p>UPDATE<\/p>\n<\/li>\n<li>\n<p>DELETE<\/p>\n<\/li>\n<li>\n<p>Execute Stored procedures<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 5 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 SQL \u0432 IEC:<\/p>\n<ul>\n<li>\n<p>BOOL <\/p>\n<\/li>\n<li>\n<p>DINT <\/p>\n<\/li>\n<li>\n<p>REAL<\/p>\n<\/li>\n<li>\n<p>STRING <\/p>\n<\/li>\n<li>\n<p>DATETIME<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 4-\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>fbMsSQL_compact \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>fbMsSQL \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>fbPing \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>fbFIFOQuery \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 SQL \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u043c\u0435\u0435\u0442 4 default-\u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<ul>\n<li>\n<p>\u0443\u0447\u0435\u0442\u043d\u044b\u0435<\/p>\n<\/li>\n<\/ul>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-316806","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316806"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316806\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}