Skip to content

Commit

Permalink
Merge pull request #12 from vapor-ware/mhink-plc-tests
Browse files Browse the repository at this point in the history
Bump up PLC timeouts. Add sleeps to allow emulators to configure. Log…
  • Loading branch information
MatthewHink committed Oct 13, 2017
2 parents f0ab45c + 6fe34d2 commit 368a8f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions bin/synse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ function start-plc-emulator {
socat PTY,link=/dev/ttyVapor001,mode=666 PTY,link=/dev/ttyVapor002,mode=666 &
python -u /synse/synse/emulator/plc/devicebus_emulator.py $1 &

# Sleep for a short bit - this is to give the emulator enough time to start
# up and configure before synse starts hitting it with requests.
sleep 0.25

}; function emulate-plc-with-cfg {
cp /synse/configs/synse/plc/synse_config.json /synse/override/config.json

Expand All @@ -170,6 +174,10 @@ function start-i2c-emulator {
socat PTY,link=/dev/ttyVapor005,mode=666 PTY,link=/dev/ttyVapor006,mode=666 &
python -u /synse/synse/emulator/i2c/i2c_emulator.py $1 &

# Sleep for a short bit - this is to give the emulator enough time to start
# up and configure before synse starts hitting it with requests.
sleep 0.25

}; function emulate-i2c-with-cfg {
cp /synse/configs/synse/i2c/synse_config.json /synse/override/config.json

Expand All @@ -195,6 +203,10 @@ function start-rs485-emulator {
socat PTY,link=/dev/ttyVapor003,mode=666 PTY,link=/dev/ttyVapor004,mode=666 &
python -u /synse/synse/emulator/rs485/rs485_emulator.py $1 &

# Sleep for a short bit - this is to give the emulator enough time to start
# up and configure before synse starts hitting it with requests.
sleep 0.25

}; function emulate-rs485-with-cfg {
cp /synse/configs/synse/rs485/synse_config.json /synse/override/config.json

Expand Down
2 changes: 1 addition & 1 deletion sample/config_plc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"device_name": "/dev/ttyVapor002",
"retry_limit": 3,
"timeout": 0.25,
"timeout": 0.50,
"time_slice": 75,
"bps": 115200
}
Expand Down
4 changes: 3 additions & 1 deletion synse/devicebus/devices/plc/plc_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,14 @@ def __init__(self, serial_reader=None, expected_sequence=None, data_bytes=None,
# them as-is, instead of collecting them under a general failure
logger.debug('<<Invalid_data ({}): {}'.format(e.message, str([hex(x) for x in serialbytes])))
raise e
except Exception:
except Exception as e:
# a catchall exception used to indicate that something bad has
# happened - this could be related to errors reading off the bus
# or reading nothing at all. in either case, we are unable to
# recover, so BusTimeoutException is passed up the chain for
# appropriate handling.
logger.error('Failed to communicate on PLC bus.')
logger.exception(e)
raise BusTimeoutException('No response from bus.')

elif data_bytes is not None:
Expand Down
4 changes: 2 additions & 2 deletions synse/devicebus/devices/plc/plc_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, **kwargs):

# these are optional values, so they may not exist in the config.
# if they do not exist, they will hold a default value
self.bus_timeout = kwargs.get('timeout', 0.25)
self.bus_timeout = kwargs.get('timeout', 0.50)
self.bus_baud = kwargs.get('bps', 115200)
self.retry_limit = kwargs.get('retry_limit', 3)
self.time_slice = kwargs.get('time_slice', 75)
Expand Down Expand Up @@ -202,7 +202,7 @@ def register(cls, devicebus_config, app_config, app_cache):
rack_lockfile = rack['lockfile']
rack_id = rack['rack_id'] # pylint: disable=unused-variable
hardware_type = rack['hardware_type']
rack_timeout = rack.get('timeout', 0.25) # pylint: disable=unused-variable
rack_timeout = rack.get('timeout', 0.50) # pylint: disable=unused-variable
counter = app_config['COUNTER']

for plc_config in rack['devices']:
Expand Down

0 comments on commit 368a8f8

Please sign in to comment.