I'm having trouble concatenating bytes. I am attempting to communicate with an mass flow controller by the code below. But I keep getting the error:
endswith first arg must be bytes or a tuple of bytes, not str
The code is:
class MKS946:
def __init__(self, com_port):
self.port = int(com_port)
def __enter__(self):
rm = pyvisa.ResourceManager()
self.mks946 = rm.open_resource(f"ASRL{self.port}::INSTR")
self.mks946.baud_rate = 9600
sleep(0.1)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.mks946.write("@253LOCK!OFF")
self.mks946.close()
def comm(self, command):
""" Implement communication protocol """
prestring = b'@253'
#endstring = b';FF'
self.mks946.write(prestring + command.encode('ascii'))
sleep(0.1)
return_string = self.mks946.read_bytes(self.mks946.bytes_in_buffer)
return return_string
def get_id(self):
return self.comm('SN')
if __name__ == "__main__":
with MKS946(4) as mfc_box:
print(mfc_box.get_id())
The offending line is:
self.mks946.write(prestring + command.encode('ascii'))
How can I concatenate the bytes in a simple way?