Skip to content

Commit

Permalink
more documentation; command line switch for debugging messages; impro…
Browse files Browse the repository at this point in the history
…ved response time when UART connected
  • Loading branch information
scriptorron committed Nov 30, 2022
1 parent 6312ac4 commit 75e2042
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 23 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# AutoSTAR_remote
This is a GUI to remote control (using ASCOM) the Meade AutoSTAR #497 handheld.
This is a GUI to remote control (using ASCOM or serial interface) the Meade AutoSTAR #497 handheld.

![screenshot](AutoSTAR_remote_V1.0.png)

Press [SHIFT] when clicking on "ENTER", "MODE" or "GO TO" to generate a long key press.

You can change the serial port parameters when connecting with UART. Default parameters for the MEADE AutoSTAR #497 are:
- Speed: 9600 baud
- 8 data bits
- 1 stop bit
- no parity
- no flow control

When connecting with the serial port you have the option to set the time and date of the AutoSTAR to the computer clock. This feature is not fully tested. Especially the daylight saving may be wrong. Please check the AutoSTAR settings if you see strange errors when doing GOTO to an object.

The compiled binary just needs to be unpacked. No installation and no Python is needed. ASCOM driver https://bitbucket.org/cjdskunkworks/meadeautostar497 must be installed and off course you need to connect your #497 AutoSTAR with your computer.

For running the Python source code you need the following packages:
- PyQt5
- pyserial
- win32com when using ASCOM on Windows

The Python source code runs also on Raspberry Pi (Astroberry).
13 changes: 10 additions & 3 deletions src/ASCOM.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

class ASCOM:

def __init__(self):
def __init__(self, showDebugMessages=False):
self.Telescope = None
self.Name = ""
#
self.showDebugMessages = showDebugMessages

def dbgMsg(self, msg):
if self.showDebugMessages:
print(f'DEBUG: {msg}')

def open(self):
self.close()
Expand Down Expand Up @@ -48,10 +54,11 @@ def close(self):

def sendCommandBlind(self, cmd):
if self.is_open():
self.dbgMsg(f'sendCommandBlind: {cmd}')
try:
ret = self.Telescope.CommandBlind(cmd, False)
except win32com.client.pywintypes.com_error as e:
print(f'sendCommandBlind: {e}')
print(f'ERROR in sendCommandBlind: {e}')
return None
else:
return ret
Expand Down Expand Up @@ -88,6 +95,6 @@ def get_LCD(self):
# send the LCD contents before the ASCOM driver trows a timeout exception.
# Here we catch these timeout exceptions.
print(f'ERROR in get_LCD: {e}')
#print(f'sendCommandString response: {Response}')
self.dbgMsg(f'get_LCD response: ED --> {Response}')
return Response[1:].translate(self.CharacterTranslationTable)
return None
28 changes: 19 additions & 9 deletions src/AutoSTAR_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

theme_selection = "Dark" # "Dark", "Light"
LCD_polling_time = 1000 # milliseconds
LCD_earlyUpdate_time = 200 # milliseconds
LCD_earlyUpdate_time = 50 # milliseconds

"""
By watching the RS232 communication of the AutoStart Suit telescope control I found the following commands:
Expand Down Expand Up @@ -58,6 +58,8 @@
"""

"""
How the ASCOM driver sets time and date:
21:06:26.686 UTCDate Set - 11.22.22 20:06:26
21:06:26.686 SendString Transmitting #:GG#
21:06:26.704 SendString Received -01
Expand All @@ -73,8 +75,9 @@ class MainWin(QtWidgets.QMainWindow):
AutoSTAR_remote main window.
"""

def __init__(self):
def __init__(self, showDebugMessages=False):
super(MainWin, self).__init__()
self.showDebugMessages = showDebugMessages
self.ui = AutoSTAR_remote_ui.Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle(f'AutoSTAR_remote {version}')
Expand All @@ -87,7 +90,7 @@ def __init__(self):
self.Interface = None
# persistent settings
self.Settings = QtCore.QSettings()
print(f'QSettings file: {self.Settings.fileName()}')
self.dbgMsg(f'QSettings file: {self.Settings.fileName()}')
# LCD polling timer
self.PollingTimer = QtCore.QTimer()
self.PollingTimer.setSingleShot(True)
Expand Down Expand Up @@ -127,6 +130,10 @@ def __init__(self):
self.ui.pushButton_FocOut.pressed.connect(lambda: self.sendCommandBlind("F+"))
self.ui.pushButton_FocOut.released.connect(lambda: self.sendCommandBlind("FQ"))

def dbgMsg(self, msg):
if self.showDebugMessages:
print(f'DEBUG: {msg}')

@QtCore.pyqtSlot()
def closeEvent(self, event):
self.PollingTimer.stop()
Expand All @@ -151,7 +158,7 @@ def update_GuiOpenInterface(self):

@QtCore.pyqtSlot()
def on_actionconnect_ASCOM_triggered(self):
self.Interface = ASCOM.ASCOM()
self.Interface = ASCOM.ASCOM(showDebugMessages=self.showDebugMessages)
self.Interface.open()
if self.Interface.is_open():
self.update_GuiOpenInterface()
Expand All @@ -162,10 +169,9 @@ def on_actionconnect_ASCOM_triggered(self):
@QtCore.pyqtSlot()
def on_actionconnect_UART_triggered(self):
Parameter = {k: self.Settings.value(k) for k in self.Settings.allKeys()}
self.Interface = UART.UART(Parameter=Parameter)
self.Interface = UART.UART(Parameter=Parameter, showDebugMessages=self.showDebugMessages)
self.Interface.open()
if self.Interface.is_open():
print("DBG: UART is open")
Parameter = self.Interface.get_Parameter()
for k, v in Parameter.items():
self.Settings.setValue(k, v)
Expand Down Expand Up @@ -221,11 +227,10 @@ def updateLCD(self):
Line1 = LcdText[0:16]
Line2 = LcdText[16:]
self.ui.plainTextEdit_LCD.setPlainText(f'{Line1}\n{Line2}')
# print(f'{Unknown}: >{Line1}< >{Line2}<')
# print(", ".join([f'{ord(c):02X}' for c in LcdText]))
# print(bytes(LcdText, 'utf-8'))
else:
print('DBG: no response from get_LCD.')
self.dbgMsg('No response from get_LCD.')
if self.ui.actionpoll.isChecked():
if not self.PollingTimer.isActive():
self.PollingTimer.setInterval(LCD_polling_time)
Expand All @@ -247,6 +252,11 @@ def on_actionpoll_toggled(self, isChecked):

# Start Qt event loop unless running in interactive mode.
def main():
import argparse
parser = argparse.ArgumentParser(description="remote control for MEADE AutoSTAR #497")
parser.add_argument("-d", "--debug", action="store_true",
help="enable debug messages")
args = parser.parse_args()
# build application
App = QtWidgets.QApplication(sys.argv)
App.setOrganizationName("GeierSoft")
Expand Down Expand Up @@ -284,7 +294,7 @@ def main():
else:
pass
#
MainWindow = MainWin()
MainWindow = MainWin(showDebugMessages=args.debug)
# MainWindow.resize(1400, 900)
MainWindow.show()
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
Expand Down
30 changes: 20 additions & 10 deletions src/UART.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class UART(QtWidgets.QDialog):

def __init__(self, Parameter={}):
def __init__(self, Parameter={}, showDebugMessages=False):
super().__init__()
self.ui = UART_ui.Ui_Dialog()
self.ui.setupUi(self)
Expand All @@ -37,6 +37,12 @@ def __init__(self, Parameter={}):
# no port opened
self.PortHandle = None
self.Name = ""
#
self.showDebugMessages = showDebugMessages

def dbgMsg(self, msg):
if self.showDebugMessages:
print(f'DEBUG: {msg}')

def get_Parameter(self):
Parameter = {
Expand Down Expand Up @@ -117,20 +123,22 @@ def initializeCommunication(self):
# Attempting manual bypass of prompts
for i in range(10):
self.sendCommandBlind("EK9")
self.sendCommandString("ED")
self.get_LCD()
# set date and time
if self.ui.checkBox_SetTimeDate.isChecked():
# TODO: make this aware of the daylight saving setting of the controller!
now = datetime.datetime.now()
time = now.strftime("%H:%M:%S")
self.PortHandle.write(f'#:SL{time}#'.encode("ascii"))
cmd = f'#:SL{time}#'.encode("ascii")
self.PortHandle.write(cmd)
Response = self.PortHandle.read(size=1)
print(f'DBG: #:SL{time}# --> {Response}')
self.dbgMsg(f'{cmd} --> {Response}')
# MM/DD/YY
date = now.strftime("%m/%d/%y")
self.PortHandle.write(f'#:SC{date}#'.encode("ascii"))
Response = self.PortHandle.read(size=1)
print(f'DBG: #:SC{date}# --> {Response}')
date = now.strftime("%m.%d.%y")
cmd = f'#:SC{date}#'.encode("ascii")
self.PortHandle.write(cmd)
Response = self.PortHandle.read(size=66)
self.dbgMsg(f'{cmd} --> {Response}')

def is_open(self):
if self.PortHandle is not None:
Expand All @@ -148,6 +156,8 @@ def sendCommandBlind(self, cmd):
if self.is_open():
MeadeCmd = f'#:{cmd}#'.encode("ascii")
self.PortHandle.write(MeadeCmd)
self.PortHandle.flush()
self.dbgMsg(f'sendCommandBlind: {MeadeCmd}')

# The :ED# command sends the LCD contents, coded with the char table of the SED1233 LCD controller.
# For any reason the COM interface or the win32com transforms this into unicode. Unfortunately the
Expand All @@ -174,10 +184,10 @@ def sendCommandBlind(self, cmd):
def get_LCD(self):
if self.is_open():
MeadeCmd = b'#:ED#'
#print(f'sendCommandString command: {MeadeCmd}')
self.PortHandle.write(MeadeCmd)
self.PortHandle.flush()
Response = self.PortHandle.read_until(b"#")
print(f'DBG: get_LCD response: {Response}')
self.dbgMsg(f'get_LCD response: {MeadeCmd} --> {Response}')
Response = Response[1:].rstrip(b"#")
Response = Response.decode("latin-1")
return Response.translate(self.CharacterTranslationTable)
Expand Down

0 comments on commit 75e2042

Please sign in to comment.