Dec-29-2021, 03:49 AM
(This post was last modified: Dec-29-2021, 04:14 AM by deanhystad.)
Your program sends "hello" out the serial port. Why? I didn't see anything about having to send a program name to the telescope.
I thought readline() returned zero bytes when it times out. Looking at Pyserial documentation it says readline() is provided by io.IOBase.readline() and when I look there it says nothing about what readline does when it times out. BUT I did notice that read_until() behaves as you described. This would make it a good choice for reading the response.
Writing extra "#" is just going to cause confusion. Your telescope is going to say "I see #, where was the command?" and then it is probably going to return a NAK which you will read thinking it is the response to the command you are trying to send instead of a response to the leading "#".
As I said in my post, I do not have an ETX telescope. I guess to be clear I should say I don't have a Meade telescope and have no way to test the code I wrote. I would be surprised if it works.
I thought readline() returned zero bytes when it times out. Looking at Pyserial documentation it says readline() is provided by io.IOBase.readline() and when I look there it says nothing about what readline does when it times out. BUT I did notice that read_until() behaves as you described. This would make it a good choice for reading the response.
import serial NAK = b"\x15" EOL = "#".encode() def sendCommand(ser, cmdStr): """Send command to telescope. Prepend : and append #""" ser.write(f":{cmdStr}#".encode()) def readResponse(ser): """Read response. Strip trailing #""" response = ser.read_until(EOL) if len(response) == 0: return None elif response[0] == NAK: return NAK if EOL in response: response = response[:response.index(EOL)] return response.decode() ser = serial.Serial("COM3", 9600, timeout=1.0) sendCommand(ser, "GR") print(readResponse(ser))NAK is not zero bytes. NAK is b'\15'.
Writing extra "#" is just going to cause confusion. Your telescope is going to say "I see #, where was the command?" and then it is probably going to return a NAK which you will read thinking it is the response to the command you are trying to send instead of a response to the leading "#".
As I said in my post, I do not have an ETX telescope. I guess to be clear I should say I don't have a Meade telescope and have no way to test the code I wrote. I would be surprised if it works.