Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Округление #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions modules/modbus/modbus.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ function poll_device($id)
if ($rec['RESPONSE_CONVERT'] == 'hex') {
$result = $rec['DATA_ORIGINAL'];
}

$rec['DATA'] = $result;
$rec['DATA'] = round($result, $rec['ROUND']);
kirush0280 marked this conversation as resolved.
Show resolved Hide resolved
SQLUpdate('modbusdevices', $rec);

if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY'] && !$writing_request) {
Expand Down Expand Up @@ -534,6 +534,7 @@ function dbInstall($data)
modbusdevices: REQUEST_START int(10) NOT NULL DEFAULT '0'
modbusdevices: REQUEST_TOTAL int(10) NOT NULL DEFAULT '0'
modbusdevices: MULTIPLIER varchar(50) NOT NULL DEFAULT ''
modbusdevices: ROUND tinyint(10) NOT NULL DEFAULT ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для числовых значений DEFAULT лучше указывать числом, а не пустой строкой (см строку 535 к примеру).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть поставить по умолчанию 2, пусть до сотой округляются значения. Вряд ли кому то нужно в УД более точные значения?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по-умолчанию 2 мне кажется будет норм. но надо ещё проверить, чтоб при добавлении новой записи тоже по-умолчанию в выставлялась двойка в интерфейсе. т.е. надо этот момент добавления протестировать.

modbusdevices: RESPONSE_CONVERT varchar(10) NOT NULL DEFAULT ''
modbusdevices: DATA text
modbusdevices: DATA_ORIGINAL text
Expand All @@ -554,4 +555,4 @@ function dbInstall($data)
* TW9kdWxlIGNyZWF0ZWQgSnVsIDI0LCAyMDE0IHVzaW5nIFNlcmdlIEouIHdpemFyZCAoQWN0aXZlVW5pdCBJbmMgd3d3LmFjdGl2ZXVuaXQuY29tKQ==
*
*/
?>
?>
4 changes: 4 additions & 0 deletions modules/modbus/modbusdevices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
$rec['MULTIPLIER'] = gr('multiplier');
if (!$rec['MULTIPLIER']) $rec['MULTIPLIER'] = '';

$rec['ROUND'] = gr('round');
kirush0280 marked this conversation as resolved.
Show resolved Hide resolved
if (!$rec['ROUND']) $rec['ROUND'] = '';


$rec['CHECK_NEXT'] = date('Y-m-d H:i:s');
//updating 'POLLPERIOD' (int)
global $pollperiod;
Expand Down
8 changes: 8 additions & 0 deletions templates/modbus/modbusdevices_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
</div>
</div>

<div class="form-group">
<label class="col-lg-4 control-label" for="round">Округление:</label>
<div class="col-lg-8">
<input type="text" class="form-control" name="round" id="round" placeholder="<#LANG_NO#>" value="[#ROUND#]">
<div class="help-block">Кол-во знаков после запятой: 0,1,2 и т.д.</div>
</div>
</div>

<div class="form-group ">
<label class="col-lg-4 control-label" for="inputTitle"><#LANG_CHECK_EVERY#> (sec):<font color="red">*</font></label>
<div class="col-lg-8"><input type="text" class="form-control [#if ERR_POLLPERIOD#]alert-danger[#endif#]" name="pollperiod" value="[#POLLPERIOD#]" required="true"></div>
Expand Down