Skip to content

Commit 6312ac4

Browse files
committed
catching error when aborting ASCOM connect; improved reception of LCD contents; persistent storing of UART settings; better telescope initialization when connecting with UART
1 parent 954361b commit 6312ac4

File tree

3 files changed

+109
-45
lines changed

3 files changed

+109
-45
lines changed

src/ASCOM.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ def open(self):
2222
else:
2323
Chooser.DeviceType = 'Telescope'
2424
self.Name = Chooser.Choose(None)
25-
self.Telescope = win32com.client.Dispatch(self.Name)
26-
self.Telescope.Connected = True
27-
if not self.Telescope.Connected:
28-
QtWidgets.QMessageBox.critical(None, "Can not connect to telescope!",
29-
f"Please check connection to\n{self.Name}.\nMaybe it is already in use.")
30-
self.Telescope = None
25+
if self.Name != "":
26+
self.Telescope = win32com.client.Dispatch(self.Name)
27+
self.Telescope.Connected = True
28+
if not self.Telescope.Connected:
29+
QtWidgets.QMessageBox.critical(None, "Can not connect to telescope!",
30+
f"Please check connection to\n{self.Name}.\nMaybe it is already in use.")
31+
self.Telescope = None
3132

3233
def get_Parameter(self):
3334
# has no parameter
@@ -56,13 +57,37 @@ def sendCommandBlind(self, cmd):
5657
return ret
5758
return None
5859

59-
def sendCommandString(self, cmd):
60+
# The :ED# command sends the LCD contents, coded with the char table of the SED1233 LCD controller.
61+
# For any reason the COM interface or the win32com transforms this into unicode. Unfortunately the
62+
# special characters of the SED1233 controller get mapped to the wrong unicode. Here we fix this
63+
# with a translation table:
64+
CharacterTranslationTable = {
65+
0x0d: ord('\n'),
66+
# 0x2020: ord(' '),
67+
0xDF: ord('°'),
68+
0x7E: 0x2192, # ord('>'),
69+
0x7F: 0x2190, # ord('<'),
70+
0x18: 0x2191, # ord('^'),
71+
0x19: 0x2193, # ord('v'),
72+
# bar graph symbols
73+
0x5F: 0x2582,
74+
0x81: 0x2583,
75+
0x201A: 0x2584, # raw: 0x82
76+
0x0192: 0x2585, # raw: 0x83
77+
0x201E: 0x2586, # raw: 0x84
78+
0x2026: 0x2587, # raw: 0x85
79+
0x2020: 0x2588, # raw: 0x86
80+
}
81+
82+
def get_LCD(self):
6083
if self.is_open():
6184
try:
62-
return self.Telescope.CommandString(cmd, False)
85+
Response = self.Telescope.CommandString("ED", False)
6386
except win32com.client.pywintypes.com_error as e:
6487
# Sometimes the handbox needs long time for calculations and does not
6588
# send the LCD contents before the ASCOM driver trows a timeout exception.
6689
# Here we catch these timeout exceptions.
67-
print(f'updateLCD: {e}')
90+
print(f'ERROR in get_LCD: {e}')
91+
#print(f'sendCommandString response: {Response}')
92+
return Response[1:].translate(self.CharacterTranslationTable)
6893
return None

src/AutoSTAR_remote.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
+ ? :EK63#
5858
"""
5959

60+
"""
61+
21:06:26.686 UTCDate Set - 11.22.22 20:06:26
62+
21:06:26.686 SendString Transmitting #:GG#
63+
21:06:26.704 SendString Received -01
64+
21:06:26.708 SendChars Transmitting #:SL21:06:26# <-- 21:06
65+
21:06:26.744 SendChars Received 1
66+
21:06:26.744 SendChars Transmitting #:SC11.22.22# <-- 22. Nov 2022
67+
21:06:26.962 SendChars Received 1
68+
"""
69+
6070

6171
class MainWin(QtWidgets.QMainWindow):
6272
"""
@@ -156,6 +166,10 @@ def on_actionconnect_UART_triggered(self):
156166
self.Interface.open()
157167
if self.Interface.is_open():
158168
print("DBG: UART is open")
169+
Parameter = self.Interface.get_Parameter()
170+
for k, v in Parameter.items():
171+
self.Settings.setValue(k, v)
172+
self.Settings.sync()
159173
self.update_GuiOpenInterface()
160174
else:
161175
self.Interface.close()
@@ -199,41 +213,19 @@ def buttonAction(self, cmd, long_cmd=None):
199213
self.PollingTimer.setInterval(LCD_earlyUpdate_time)
200214
self.PollingTimer.start()
201215

202-
# The :ED# command sends the LCD contents, coded with the char table of the SED1233 LCD controller.
203-
# For any reason the COM interface or the win32com transforms this into unicode. Unfortunately the
204-
# special characters of the SED1233 controller get mapped to the wrong unicode. Here we fix this
205-
# with a translation table:
206-
CharacterTranslationTable = {
207-
0x0d: ord('\n'),
208-
# 0x2020: ord(' '),
209-
0xDF: ord('°'),
210-
0x7E: 0x2192, # ord('>'),
211-
0x7F: 0x2190, # ord('<'),
212-
0x18: 0x2191, # ord('^'),
213-
0x19: 0x2193, # ord('v'),
214-
# bar graph symbols
215-
0x5F: 0x2582,
216-
0x81: 0x2583,
217-
0x201A: 0x2584, # raw: 0x82
218-
0x0192: 0x2585, # raw: 0x83
219-
0x201E: 0x2586, # raw: 0x84
220-
0x2026: 0x2587, # raw: 0x85
221-
0x2020: 0x2588, # raw: 0x86
222-
}
223-
224216
def updateLCD(self):
225217
LcdText = None
226218
if self.Interface is not None:
227-
LcdText = self.Interface.sendCommandString("ED")
219+
LcdText = self.Interface.get_LCD()
228220
if LcdText is not None:
229-
LcdText = LcdText.translate(self.CharacterTranslationTable)
230-
Unknown = ord(LcdText[0])
231-
Line1 = LcdText[1:17]
232-
Line2 = LcdText[17:]
221+
Line1 = LcdText[0:16]
222+
Line2 = LcdText[16:]
233223
self.ui.plainTextEdit_LCD.setPlainText(f'{Line1}\n{Line2}')
234224
# print(f'{Unknown}: >{Line1}< >{Line2}<')
235225
# print(", ".join([f'{ord(c):02X}' for c in LcdText]))
236226
# print(bytes(LcdText, 'utf-8'))
227+
else:
228+
print('DBG: no response from get_LCD.')
237229
if self.ui.actionpoll.isChecked():
238230
if not self.PollingTimer.isActive():
239231
self.PollingTimer.setInterval(LCD_polling_time)

src/UART.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from PyQt5 import QtCore, QtGui, QtWidgets
66
import sys
77
import os
8+
import datetime
89
import serial
910
import serial.tools.list_ports
1011

@@ -78,7 +79,7 @@ def find_Ports(self, include_links=False):
7879

7980
def open(self, timeout=2.0, write_timeout=None, inter_byte_timeout=None, exclusive=False):
8081
ret = self.exec_()
81-
if ret == self.Accepted:
82+
if (ret == self.Accepted) and (len(self.KnownPorts) > 0):
8283
self.Name = self.ui.comboBox_ComPort.currentText()
8384
port = self.KnownPorts[self.ui.comboBox_ComPort.currentIndex()]["port"]
8485
baudrate = int(self.ui.comboBox_Speed.currentText())
@@ -107,6 +108,29 @@ def open(self, timeout=2.0, write_timeout=None, inter_byte_timeout=None, exclusi
107108
except serial.SerialException as e:
108109
QtWidgets.QMessageBox.critical(None, "Can not open UART port!", f"{e}")
109110
self.PortHandle = None
111+
self.initializeCommunication()
112+
113+
def initializeCommunication(self):
114+
if self.is_open():
115+
# clear the buffer
116+
self.PortHandle.write('#'.encode("ascii"))
117+
# Attempting manual bypass of prompts
118+
for i in range(10):
119+
self.sendCommandBlind("EK9")
120+
self.sendCommandString("ED")
121+
# set date and time
122+
if self.ui.checkBox_SetTimeDate.isChecked():
123+
# TODO: make this aware of the daylight saving setting of the controller!
124+
now = datetime.datetime.now()
125+
time = now.strftime("%H:%M:%S")
126+
self.PortHandle.write(f'#:SL{time}#'.encode("ascii"))
127+
Response = self.PortHandle.read(size=1)
128+
print(f'DBG: #:SL{time}# --> {Response}')
129+
# MM/DD/YY
130+
date = now.strftime("%m/%d/%y")
131+
self.PortHandle.write(f'#:SC{date}#'.encode("ascii"))
132+
Response = self.PortHandle.read(size=1)
133+
print(f'DBG: #:SC{date}# --> {Response}')
110134

111135
def is_open(self):
112136
if self.PortHandle is not None:
@@ -125,19 +149,42 @@ def sendCommandBlind(self, cmd):
125149
MeadeCmd = f'#:{cmd}#'.encode("ascii")
126150
self.PortHandle.write(MeadeCmd)
127151

128-
def sendCommandString(self, cmd):
152+
# The :ED# command sends the LCD contents, coded with the char table of the SED1233 LCD controller.
153+
# For any reason the COM interface or the win32com transforms this into unicode. Unfortunately the
154+
# special characters of the SED1233 controller get mapped to the wrong unicode. Here we fix this
155+
# with a translation table:
156+
CharacterTranslationTable = {
157+
0x0d: ord('\n'),
158+
# 0x2020: ord(' '),
159+
0xDF: ord('°'),
160+
0x7E: 0x2192, # ord('>'),
161+
0x7F: 0x2190, # ord('<'),
162+
0x18: 0x2191, # ord('^'),
163+
0x19: 0x2193, # ord('v'),
164+
# bar graph symbols
165+
0x5F: 0x2582,
166+
0x81: 0x2583,
167+
0x82: 0x2584, # raw: 0x82
168+
0x83: 0x2585, # raw: 0x83
169+
0x84: 0x2586, # raw: 0x84
170+
0x85: 0x2587, # raw: 0x85
171+
0x86: 0x2588, # raw: 0x86
172+
}
173+
174+
def get_LCD(self):
129175
if self.is_open():
130-
MeadeCmd = f'#:{cmd}#'.encode("ascii")
131-
print(f'sendCommandString command: {MeadeCmd}')
176+
MeadeCmd = b'#:ED#'
177+
#print(f'sendCommandString command: {MeadeCmd}')
132178
self.PortHandle.write(MeadeCmd)
133-
Response = self.PortHandle.read_until("#".encode("ascii"))
134-
print(f'sendCommandString response: {Response}')
135-
Response = Response.rstrip("#".encode("ascii"))
136-
Response = Response.decode("utf-16")
137-
return Response
179+
Response = self.PortHandle.read_until(b"#")
180+
print(f'DBG: get_LCD response: {Response}')
181+
Response = Response[1:].rstrip(b"#")
182+
Response = Response.decode("latin-1")
183+
return Response.translate(self.CharacterTranslationTable)
138184
return None
139185

140186

187+
141188
if __name__ == '__main__':
142189
# for debugging only
143190
theme_selection = "Dark" # "Dark", "Light"

0 commit comments

Comments
 (0)