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

small fixes #826

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion bin/peas_shell
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import datetime
import os
import readline
import sys
import serial

from astropy.utils import console
from threading import Timer
Expand Down Expand Up @@ -164,6 +165,13 @@ class PanSensorShell(cmd.Cmd):
self.weather = AAGCloudSensor(serial_address=port, store_result=True)
self.do_enable_sensor('weather')

def do_clear_buffer(self, sensor , sensor_name):
if hasattr(self, sensor) and sensor in self.active_sensors:
port = self.config[sensor][sensor_name]['serial_port']
ser=serial.Serial(port)
Copy link
Member

Choose a reason for hiding this comment

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

The self.active_sensors holds actual sensor objects, either a ArduinoSerialMonitor or AAGCloudSensor. Those object already have a SerialData connection, so we don't want to create a new serial device connection here but instead use the existing ones.

Also, we don't seem to have any issues with the AAGCloudSensor as it is handling its own read and write methods so clears them appropriately.

The more I think about it the more we might just want to try to manage the buffer better via our read/writes in pocs.utils.rs232.SerialData and not expose this command. Specifically, I think we just need to reset the input buffer every time we are trying to issue a write command. @jamessynge thoughts?

Copy link
Contributor Author

@kmeagle1515 kmeagle1515 Apr 26, 2019

Choose a reason for hiding this comment

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

Actually i did not thought about the pre-existing serial connection. Regardless of the issue #809 yeah the fix that you recently mentioned won't need an extra do_clear_buffer method in peas_shell, instead it will only require the self.ser.reset_input_buffer() in the write method of rs232 file , also the reset_input_buffer() and reset_output_buffer() methods in the same rs232.py file won't be needed.
@wtgee @jamessynge thoughts?

ser.reset_input_buffer()
ser.reset_output_buffer()

##################################################################################################
# Relay Methods
##################################################################################################
Expand Down Expand Up @@ -208,7 +216,7 @@ class PanSensorShell(cmd.Cmd):
relay_info = relay_lookup[relay]
serial_connection = self.environment.serial_readers[relay_info['board']]['reader']

serial_connection.ser.flushInput()
serial_connection.ser.reset_input_buffer()
serial_connection.write("{},9".format(relay_info['pin']))
except Exception as e:
print_warning("Problem toggling relay {}".format(relay))
Expand Down
2 changes: 1 addition & 1 deletion peas/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def find_arduino_devices():


def detect_board_on_port(port, logger=None):
"""Open a port and determine which type of board its producing output.
"""Open a port and determine which type of board is producing output.

Returns: (name, serial_reader) if we can read a line of JSON from the
port, parse it and find a 'name' attribute in the top-level object.
Expand Down
3 changes: 2 additions & 1 deletion pocs/utils/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def scrub_message(self, message):
if isinstance(v, Time):
v = str(v.isot).split('.')[0].replace('T', ' ')

# Hmmmm. What is going on here? We need some documentation.
# _time gives the time in date and time format.
# Date and Time are space seperated so only time is passed as value.
if k.endswith('_time'):
v = str(v).split(' ')[-1]

Expand Down
8 changes: 8 additions & 0 deletions pocs/utils/rs232.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ def reset_input_buffer(self):
"""
self.ser.reset_input_buffer()

def reset_output_buffer(self):
"""Clear buffered data from connected port/device.

This is continued with respect to the above block which was done by james synge.
Does the work of clearing the port's output buffer. This reduces delay.
"""
self.ser.reset_output_buffer()

def __del__(self):
"""Close the serial device on delete.

Expand Down