<s> """<STR_LIT>""" <EOL> __copyright__ = "<STR_LIT>" <EOL> import sys <EOL> import time <EOL> import os <EOL> import json <EOL> from Cura . util import machineCom <EOL> class serialComm ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , portName , baudrate ) : <EOL> self . _comm = None <EOL> self . _gcodeList = [ ] <EOL> try : <EOL> baudrate = int ( baudrate ) <EOL> except ValueError : <EOL> baudrate = <NUM_LIT:0> <EOL> self . _comm = machineCom . MachineCom ( portName , baudrate , callbackObject = self ) <EOL> def mcLog ( self , message ) : <EOL> sys . stdout . write ( '<STR_LIT>' % ( message ) ) <EOL> def mcTempUpdate ( self , temp , bedTemp , targetTemp , bedTargetTemp ) : <EOL> sys . stdout . write ( '<STR_LIT>' % ( json . dumps ( temp ) , json . dumps ( targetTemp ) , bedTemp , bedTargetTemp ) ) <EOL> def mcStateChange ( self , state ) : <EOL> if self . _comm is None : <EOL> return <EOL> sys . stdout . write ( '<STR_LIT>' % ( state , self . _comm . getStateString ( ) ) ) <EOL> def mcMessage ( self , message ) : <EOL> sys . stdout . write ( '<STR_LIT>' % ( message ) ) <EOL> def mcProgress ( self , lineNr ) : <EOL> sys . stdout . write ( '<STR_LIT>' % ( lineNr ) ) <EOL> def mcZChange ( self , newZ ) : <EOL> sys . stdout . write ( '<STR_LIT>' % ( newZ ) ) <EOL> def monitorStdin ( self ) : <EOL> while not self . _comm . isClosed ( ) : <EOL> line = sys . stdin . readline ( ) . strip ( ) <EOL> line = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if line [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . _comm . cancelPrint ( ) <EOL> self . _gcodeList = [ '<STR_LIT>' ] <EOL> elif line [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . _gcodeList . append ( line [ <NUM_LIT:1> ] ) <EOL> elif line [ <NUM_LIT:0> ] == '<STR_LIT:C>' : <EOL> self . _comm . sendCommand ( line [ <NUM_LIT:1> ] ) <EOL> elif line [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . _comm . printGCode ( self . _gcodeList ) <EOL> else : <EOL> sys . stderr . write ( str ( line ) ) <EOL> def startMonitor ( portName , baudrate ) : <EOL> sys . stdout = os . fdopen ( sys . stdout . fileno ( ) , '<STR_LIT:w>' , <NUM_LIT:0> ) <EOL> comm = serialComm ( portName , baudrate ) <EOL> comm . monitorStdin ( ) <EOL> def main ( ) : <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> return <EOL> portName , baudrate = sys . argv [ <NUM_LIT:1> ] , sys . argv [ <NUM_LIT:2> ] <EOL> startMonitor ( portName , baudrate ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
