Skip to content

Commit

Permalink
fixed modbus write task, fixed event handling
Browse files Browse the repository at this point in the history
0.7.0b13
- fixed modbus write task
- fixed Event handling
  • Loading branch information
trombastic committed Jan 18, 2017
1 parent cbc48b2 commit 972e33f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@
- fixed Export without mean values
- fixed managementcommand for Data Export
- added lock for Exports to prevent running of more then one export at a time

0.7.0b12
- fixed export
- added datetime fields to Export
- added pytz to the requirements

0.7.0b13
- fixed modbus write task
- fixed Event handling
28 changes: 28 additions & 0 deletions docs/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,34 @@ values to the server the coresponding function code will be selected automaticly

.. image:: pic/backend_modbus_save_device.png

short instructions for the HMI
------------------------------


In the Backend HMI Section (http://IP/admin/hmi/):
1. Charts, add a new Chart
2. Page, add a Page
3. Widget, add a Widget, select under Page the page you added in 2. and under Chart the Chart from 1., a widget controls the position of every element on a Page.
4. View, add a View and select the page from 2.
5. GroupDisplayPermissions, add a new GroupDisplayPermission, (if nessesary add a new Group and add your User to that Group, select all items you created in 1. to 4.
6. open http://IP/, you should see the new View, if the DAQ is running and there is Data already in the DB, you should see the last 2 Houers of Data and the curennt Data.

```
+-View------------------------------------+
| |
| +-Page--------------------------------+ |
| | | |
| | +-Widget--------+ +-Widget--------+ | |
| | | | | | | |
| | | Row 1, Col 1 | | Row 1, Col 2 | | |
| | | +-Chart-----+ | | +-Chart-----+ | | |
| | | | | | | | | | | |
| | | +-----------+ | | +---------- + | | |
| | +---------------+ +---------------+ | |
| +-------------------------------------+ |
+-----------------------------------------+
```



Add a new View
Expand Down
2 changes: 1 addition & 1 deletion pyscada/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#__import__('pkg_resources').declare_namespace('pyscada')

__version__ = '0.7.0b12'
__version__ = '0.7.0b13'
__author__ = 'Martin Schröder'

default_app_config = 'pyscada.apps.PyScadaConfig'
Expand Down
30 changes: 18 additions & 12 deletions pyscada/modbus/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,31 @@ def write_data(self,variable_id, value):
# write register
if 0 <= self.variables[variable_id].modbusvariable.address <= 65535:

self._connect()
if self.variables[variable_id].get_bits_by_class()/16 == 1:
# just write the value to one register
self.slave.write_register(self.variables[variable_id].modbusvariable.address,int(value),unit=self._unit_id)
if self._connect():
if self.variables[variable_id].get_bits_by_class()/16 == 1:
# just write the value to one register
self.slave.write_register(self.variables[variable_id].modbusvariable.address,int(value),unit=self._unit_id)
else:
# encode it first
self.slave.write_registers(self.variables[variable_id].modbusvariable.address,list(self.variables[variable_id].encode_value(value)),unit=self._unit_id)
self._disconnect()
return True
else:
# encode it first
self.slave.write_registers(self.variables[variable_id].modbusvariable.address,list(self.variables[variable_id].encode_value(value)),unit=self._unit_id)
self._disconnect()
return True
log.info(("device with id: %d is now accessible")%(self.device.pk))
return False
else:
log.error('Modbus Address %d out of range'%self.variables[variable_id].modbusvariable.address)
return False
elif self.variables[variable_id].modbusvariable.function_code_read == 1:
# write coil
if 0 <= self.variables[variable_id].modbusvariable.address <= 65535:
self._connect()
self.slave.write_coil(self.variables[variable_id].modbusvariable.address,bool(value),unit=self._unit_id)
self._disconnect()
return True
if self._connect():
self.slave.write_coil(self.variables[variable_id].modbusvariable.address,bool(value),unit=self._unit_id)
self._disconnect()
return True
else:
log.info(("device with id: %d is now accessible")%(self.device.pk))
return False
else:
log.error('Modbus Address %d out of range'%self.variables[variable_id].modbusvariable.address)
else:
Expand Down
10 changes: 5 additions & 5 deletions pyscada/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ def compose_mail(active):
actual_value = RecordedData.objects.last_element(variable=self.variable)
if not actual_value:
return False
timestamp = actual_value.time
actual_value = actual_value.value
timestamp = actual_value.time_value()
actual_value = actual_value.value()
# determin the limit type, variable or fixed
if self.variable_limit:
# item has a variable limit
Expand All @@ -863,10 +863,10 @@ def compose_mail(active):
limit_value = RecordedData.objects.last_element(variable=self.variable_limit)
if not limit_value:
return False
if timestamp < limit_value.last().time:
if timestamp < limit_value.last().time_value():
# wenn limit value has changed after the actual value take that time
timestamp = limit_value.last().time
limit_value = limit_value.last().value # get value
timestamp = limit_value.last().time_value()
limit_value = limit_value.last().value() # get value
else:
# item has a fixed limit
limit_value = self.fixed_limit
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
'h5py>=2.2.1',
'psutil>=2.1.1',
'pillow',
'python-daemon>=2.0.0'
'python-daemon>=2.0.0',
'pytz'
],
packages=find_packages(exclude=["project", "project.*"]),
include_package_data=True,
Expand Down

0 comments on commit 972e33f

Please sign in to comment.