The serialComm class is the interface class which handles the communication between stdin/stdout and the machineCom class.
This interface class is used to run the (USB) serial communication in a different process then the GUI.
"""
- def __init__(self, portName):
+ def __init__(self, portName, baudrate):
self._comm = None
self._gcodeList = []
- self._comm = machineCom.MachineCom(portName, callbackObject=self)
+ try:
+ baudrate = int(baudrate)
+ except ValueError:
+ baudrate = 0
+ self._comm = machineCom.MachineCom(portName, baudrate, callbackObject=self)
def mcLog(self, message):
sys.stdout.write('log:%s\n' % (message))
else:
sys.stderr.write(str(line))
-def startMonitor(portName):
+def startMonitor(portName, baudrate):
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
- comm = serialComm(portName)
+ comm = serialComm(portName, baudrate)
comm.monitorStdin()
def main():
- if len(sys.argv) != 2:
+ if len(sys.argv) != 3:
return
- portName = sys.argv[1]
- startMonitor(portName)
+ portName, baudrate = sys.argv[1], sys.argv[2]
+ startMonitor(portName, baudrate)
if __name__ == '__main__':
main()
self._log("Connection closed, closing down monitor")
def _setBaudrate(self, baudrate):
- #For linux the pyserial implementation lacks TCGETS2 support. So do that ourselves
- if sys.platform.startswith('linux'):
- try:
- self._serial.baudrate = baudrate
- except:
- try:
- # set custom speed
- import fcntl, array, termios
- TCGETS2 = 0x802C542A
- TCSETS2 = 0x402C542B
- BOTHER = 0o010000
- buf = array.array('i', [0] * 64)
- fcntl.ioctl(self._serial.fd, TCGETS2, buf)
- buf[2] &= ~termios.CBAUD
- buf[2] |= BOTHER
- buf[9] = buf[10] = baudrate
- fcntl.ioctl(self._serial.fd, TCSETS2, buf)
- except:
- print getExceptionString()
- else:
+ try:
self._serial.baudrate = baudrate
+ except:
+ print getExceptionString()
def _log(self, message):
self._callback.mcLog(message)
cmdList = [os.path.join(os.path.dirname(sys.executable), 'Cura'), '--serialCommunication']
else:
cmdList = [sys.executable, '-m', 'Cura.serialCommunication']
- cmdList += [self._portName]
+ cmdList += [self._portName, profile.getMachineSetting('serial_baud')]
if platform.system() == "Darwin":
if platform.machine() == 'i386':
cmdList = ['arch', '-i386'] + cmdList