Exemplo n.º 1
0
 def create(config, profile_dir):
     driver = S3gDriver(config, profile_dir)
     for profile_name in makerbot_driver.list_profiles(profile_dir):
         s3g_profile = makerbot_driver.Profile(profile_name, profile_dir)
         profile = _S3gProfile._create(profile_name, driver, s3g_profile)
         driver._profiles[profile.name] = profile
     return driver
Exemplo n.º 2
0
    def build_from_port(self, portname, leaveOpen=True):
        """
        Returns a tuple of an (s3gObj, ProfileObj)
        for a bot at port portname
        """
        machineInquisitor = self.create_inquisitor(portname)
        s3gBot, bot_setup_dict = machineInquisitor.query(leaveOpen)

        profile_regex = self.get_profile_regex(bot_setup_dict)
        matches = makerbot_driver.search_profiles_with_regex(
            profile_regex, self.profile_dir)
        matches = list(matches)
        return_object = ReturnObject
        attrs = ['s3g', 'profile', 'gcodeparser']
        for a in attrs:
            setattr(return_object, a, None)
        if len(matches) > 0:
            bestProfile = matches[0]
            setattr(return_object, 's3g', s3gBot)
            setattr(return_object, 'profile',
                    makerbot_driver.Profile(bestProfile, self.profile_dir))
            parser = makerbot_driver.Gcode.GcodeParser()
            parser.s3g = s3gBot
            parser.state.profile = getattr(return_object, 'profile')
            setattr(return_object, 'gcodeparser', parser)
        return return_object
Exemplo n.º 3
0
    def build_from_port(self, portname, leaveOpen=True, condition=None):
        """
        Returns a tuple of an (s3gObj, ProfileObj)
        for a machine at port portname
        """
        machineInquisitor = self.create_inquisitor(portname)
        if None is condition:
            condition = threading.Condition()
        s3gBot, machine_setup_dict = machineInquisitor.query(condition, leaveOpen)

        profile_regex = self.get_profile_regex(machine_setup_dict)
        matches = makerbot_driver.search_profiles_with_regex(
            profile_regex, self.profile_dir)
        matches = list(matches)
        return_object = ReturnObject()
        attrs = ['s3g', 'profile', 'gcodeparser']
        for a in attrs:
            setattr(return_object, a, None)
        if len(matches) > 0:
            bestProfile = matches[0]
            setattr(return_object, 's3g', s3gBot)
            profile = makerbot_driver.Profile(bestProfile, self.profile_dir)
            profile.values['print_to_file_type']=[machine_setup_dict['print_to_file_type']]
            profile.values['software_variant'] = machine_setup_dict['software_variant']
            profile.values['tool_count_error'] = machine_setup_dict['tool_count_error']
            setattr(return_object, 'profile', profile)
            parser = makerbot_driver.Gcode.GcodeParser()
            parser.s3g = s3gBot
            parser.state.profile = getattr(return_object, 'profile')
            setattr(return_object, 'gcodeparser', parser)
        return return_object
Exemplo n.º 4
0
    def setUp(self):
        self.mock = mock.Mock(makerbot_driver.s3g())

        self.g = makerbot_driver.Gcode.GcodeParser()
        self.g.s3g = self.mock
        profile = makerbot_driver.Profile("ReplicatorDual")
        self.g.state.profile = profile
Exemplo n.º 5
0
 def test_build_from_port_version_number_500_tool_count_1_Replicator(self):
     #Time to mock all of s3g's version!
     version = 500
     tool_count = 1
     vid, pid = 0x23C1, 0xD314
     verified_status = True
     proper_name = 'test_bot'
     self.s3g_mock.get_version = mock.Mock(return_value=version)
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_verified_status = mock.Mock(
         return_value=verified_status)
     self.s3g_mock.get_name = mock.Mock(return_value=proper_name)
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     #Mock the returned s3g obj
     expected_mock_s3g_obj = 'SUCCESS%i' % (version)
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorSingle')
     expected_parser = makerbot_driver.Gcode.GcodeParser()
     return_obj = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(getattr(return_obj, 's3g') != None)
     self.s3g_mock.set_firmware_version.assert_called_once_with(version)
     self.assertEqual(expected_profile.values,
                      getattr(return_obj, 'profile').values)
     self.assertTrue(getattr(return_obj, 'gcodeparser') != None)
Exemplo n.º 6
0
 def test_build_from_port_s3g_version(self):
     #Time to mock all of s3g's version!
     tool_count = 2
     vid, pid = 0x23C1, 0xB404
     advanced_version_info = {
         'Version': 500,
         'InternalVersion': 0,
         'SoftwareVariant': 0,
         'ReservedA': 0,
         'ReservedB': 0,
     }
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     self.s3g_mock.get_advanced_version = mock.Mock()
     self.s3g_mock.get_advanced_version.return_value = advanced_version_info
     #Mock the returned s3g obj
     expected_mock_s3g_obj = 'SUCCESS500'
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorDual')
     expected_profile.values['print_to_file_type'] = ['s3g']
     return_obj = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(getattr(return_obj, 's3g') is not None)
     self.s3g_mock.set_print_to_file_type.assert_called_once_with('s3g')
     self.assertEqual(expected_profile.values,
                      getattr(return_obj, 'profile').values)
     self.assertTrue(getattr(return_obj, 'gcodeparser') is not None)
Exemplo n.º 7
0
 def test_profile_access(self):
     """
 Make sure we have no issues accessing the information in the machine profile
 """
     expected_name = "The Replicator Dual"
     name = "ReplicatorDual"
     p = makerbot_driver.Profile(name)
     self.assertEqual(p.values['type'], expected_name)
Exemplo n.º 8
0
def create_parser(machine_name, legacy=False):
    parser = makerbot_driver.Gcode.GcodeParser()
    if legacy:
        parser.state = makerbot_driver.Gcode.LegacyGcodeStates()
    else:
        parser.state = makerbot_driver.Gcode.GcodeStates()
    parser.state.profile = makerbot_driver.Profile(machine_name)
    return parser
Exemplo n.º 9
0
 def setUp(self):
     self.mock = mock.Mock(makerbot_driver.s3g())
     self.g = makerbot_driver.Gcode.GcodeParser()
     self.g.s3g = self.mock
     profile = makerbot_driver.Profile("ReplicatorDual")
     self.g.state.profile = profile
     for axis in ['X', 'Y', 'Z', 'A', 'B']:
         setattr(self.g.state.position, axis, 0)
     self.initial_position = [0, 0, 0, 0, 0]
Exemplo n.º 10
0
 def setUp(self):
     self.p = makerbot_driver.Gcode.GcodeParser()
     self.p.state = makerbot_driver.Gcode.LegacyGcodeStates()
     self.p.state.values['build_name'] = 'test'
     self.p.state.profile = makerbot_driver.Profile('TOMStepstruderSingle')
     self.s3g = makerbot_driver.s3g()
     with tempfile.NamedTemporaryFile(suffix='.gcode', delete=True) as f:
         path = f.name
     self.s3g.writer = makerbot_driver.Writer.FileWriter(open(path, 'wb'))
     self.p.s3g = self.s3g
Exemplo n.º 11
0
 def test_Profile_profiledir(self):
     profiledir = tempfile.mkdtemp()
     try:
         path = os.path.join(profiledir, 'Test.json')
         with open(path, 'w') as fp:
             values = {'key': 'value'}
             json.dump(values, fp)
         profile = makerbot_driver.Profile('Test', profiledir)
         self.assertEqual(values, profile.values)
     finally:
         shutil.rmtree(profiledir)
Exemplo n.º 12
0
 def test_good_profile_name(self):
     name = "ReplicatorSingle"
     p = makerbot_driver.Profile(name)
     path = os.path.join(
         os.path.abspath(os.path.dirname(__file__)),
         '..',
         'makerbot_driver',
         'profiles',
         name + '.json',
     )
     with open(path) as f:
         expected_vals = json.load(f)
     self.assertEqual(expected_vals, p.values)
Exemplo n.º 13
0
 def setUp(self):
     self.p = makerbot_driver.Gcode.GcodeParser()
     self.s = makerbot_driver.Gcode.GcodeStates()
     self.s.values['build_name'] = 'test'
     self.profile = makerbot_driver.Profile('ReplicatorSingle')
     self.s.profile = self.profile
     self.p.state = self.s
     self.s3g = makerbot_driver.s3g()
     with tempfile.NamedTemporaryFile(suffix='.gcode', delete=False) as input_file:
         pass
     input_path = input_file.name
     os.unlink(input_path)
     self.writer = makerbot_driver.Writer.FileWriter(open(input_path, 'wb'))
     self.s3g.writer = self.writer
     self.p.s3g = self.s3g
Exemplo n.º 14
0
 def __init__(self, machine_profile, profiledir=None):
     self.machine_profile = machine_profile
     self.start_order = [
         'begin_print',
         'homing',
         'start_position',
         'heat_platform',
         'heat_tools',
         'anchor',
     ]
     self.end_order = [
         'end_position',
         'cool_platform',
         'cool_tools',
         'end_print',
     ]
     self.recipes = makerbot_driver.Profile('recipes', profiledir)
Exemplo n.º 15
0
 def setUp(self):
     self.p = makerbot_driver.Gcode.GcodeParser()
     self.p.state = makerbot_driver.Gcode.LegacyGcodeStates()
     self.p.state.values['build_name'] = 'test'
     self.p.state.profile = makerbot_driver.Profile('TOMStepstruderSingle')
     start_pos = self.p.state.profile.values['print_start_sequence']['start_position']
     start_position = {
         'START_X' : start_pos['start_x'],
         'START_Y' : start_pos['start_y'],
         'START_Z' : start_pos['start_z']
     }
     self.p.environment.update(start_position)
     self.s3g = makerbot_driver.s3g()
     with tempfile.NamedTemporaryFile(suffix='.gcode', delete=True) as f:
         path = f.name
     condition = threading.Condition()
     self.s3g.writer = makerbot_driver.Writer.FileWriter(open(path, 'wb'), condition)
     self.p.s3g = self.s3g
Exemplo n.º 16
0
 def test_build_from_port_tool_count_2_mightyboard(self):
     #Time to mock all of s3g's version!
     tool_count = 2
     vid, pid = 0x23C1, 0xB404
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     self.s3g_mock.get_advanced_version = mock.Mock(
         side_effect=makerbot_driver.CommandNotSupportedError)
     #Mock the returned s3g obj
     expected_mock_s3g_obj = 'SUCCESS500'
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorDual')
     expected_profile.values['print_to_file_type'] = ['s3g']
     return_obj = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(getattr(return_obj, 's3g') is not None)
     self.assertEqual(expected_profile.values,
                      getattr(return_obj, 'profile').values)
     self.assertTrue(getattr(return_obj, 'gcodeparser') is not None)
Exemplo n.º 17
0
    def build_from_port(self, portname, leaveOpen=True):
        """
    Returns a tuple of an (s3gObj, ProfileObj) 
    for a bot at port portname
    """
        botInquisitor = self.create_inquisitor(portname)
        s3gBot, bot_setup_dict = botInquisitor.query(leaveOpen)

        profile_regex = self.get_profile_regex(bot_setup_dict)
        matches = makerbot_driver.search_profiles_with_regex(
            profile_regex, self.profile_dir)
        matches = list(matches)
        if len(matches) > 0:
            bestProfile = matches[0]
            machine_info = (s3gBot,
                            makerbot_driver.Profile(bestProfile,
                                                    self.profile_dir))
        else:
            machine_info = (None, None)
        return machine_info
Exemplo n.º 18
0
 def _getprinters(self):
     result = []
     profiledir = self._config['common']['profiledir']
     profile_names = list(makerbot_driver.list_profiles(profiledir))
     for profile_name in profile_names:
         if 'recipes' != profile_name:
             profile = makerbot_driver.Profile(profile_name, profiledir)
             printer = conveyor.domain.Printer.fromprofile(
                 profile, profile_name, None)
             printer.can_print = False
             dct = printer.todict()
             result.append(dct)
     printerthreads = self._server.getprinterthreads()
     for portname, printerthread in printerthreads.items():
         profile = printerthread.getprofile()
         printerid = printerthread.getprinterid()
         printer = conveyor.domain.Printer.fromprofile(
             profile, printerid, None)
         dct = printer.todict()
         result.append(dct)
     return result
Exemplo n.º 19
0
 def connect(self, port, machineName):
     self.port = serial.Serial(port, 115200, timeout=1)
     self.driver.writer = makerbot_driver.Writer.StreamWriter(self.port, self.condition)
     self.connected = True
     self.driver.init()
     self.driver.display_message(0, 0, "********************", 3, False, False, False)
     self.driver.display_message(0, 0, "     Welcome to     ", 3, True, False, False)
     self.driver.display_message(0, 0, "    MakerBotCNC!    ", 3, True, False, False)
     self.driver.display_message(0, 0, "********************", 3, True, True, False)
     #self.driver.queue_song(6)
     if machineName in self.profileNames:
         self.profile = makerbot_driver.Profile(self.profileNames[machineName])
         self.spm = {
             'x' : self.profile.values['axes']['X']['steps_per_mm'],
             'y' : self.profile.values['axes']['Y']['steps_per_mm'],
             'z' : self.profile.values['axes']['Z']['steps_per_mm']
         }
         self.origin = {
             'x' : -190,
             'y' : -43,
             'z' : 100
         }
         self.position = {
             'x' : 0,
             'y' : 0,
             'z' : 0
         }
         self.amplitude = {
             'x' : 0,
             'y' : 0,
             'z' : 0
         }
         for axis in self.origin.keys():
             self.amplitude[axis] = abs(self.origin[axis])
     else:
         raise Exception("Unknown Machine " + machineName)
     self.machinePort = port
     self.machineName = machineName
     print("Connected to machine " + machineName + " on port " + port)
Exemplo n.º 20
0
 def test_build_from_port_version_number_500_tool_count_2_mightyboard(self):
     #Time to mock all of s3g's version!
     version = 500
     tool_count = 2
     vid, pid = 0x23C1, 0xB404
     verified_status = True
     proper_name = 'test_bot'
     self.s3g_mock.get_version = mock.Mock(return_value=version)
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_verified_status = mock.Mock(
         return_value=verified_status)
     self.s3g_mock.get_name = mock.Mock(return_value=proper_name)
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     #Mock the returned s3g obj
     expected_mock_s3g_obj = 'SUCCESS%i' % (version)
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorDual')
     s3g_obj, profile = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(s3g_obj != None)
     self.assertEqual(expected_profile.values, profile.values)
Exemplo n.º 21
0
 def setUp(self):
     self.p = makerbot_driver.Gcode.GcodeParser()
     self.s = makerbot_driver.Gcode.GcodeStates()
     self.s.values['build_name'] = 'test'
     self.profile = makerbot_driver.Profile('ReplicatorSingle')
     start_pos = self.profile.values['print_start_sequence']['start_position']
     start_position = {
         'START_X' : start_pos['start_x'],
         'START_Y' : start_pos['start_y'],
         'START_Z' : start_pos['start_z']
     }
     self.p.environment.update(start_position)
     self.s.profile = self.profile
     self.p.state = self.s
     self.s3g = makerbot_driver.s3g()
     with tempfile.NamedTemporaryFile(suffix='.gcode', delete=False) as input_file:
         pass
     input_path = input_file.name
     os.unlink(input_path)
     condition = threading.Condition()
     self.writer = makerbot_driver.Writer.FileWriter(open(input_path, 'wb'), condition)
     self.s3g.writer = self.writer
     self.p.s3g = self.s3g
Exemplo n.º 22
0
 def test_build_from_port_invalid_tool_count(self):
     # result here is a replicator Dual - this is the default for valid replicator vid pid
     # we don't want a situation where the eeprom is corrupt and the bot cannot be recognized
     tool_count = -1
     vid, pid = 0x23C1, 0xD314
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     self.s3g_mock.get_version = mock.Mock(return_value=500)
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_advanced_version = mock.Mock(
         side_effect=makerbot_driver.CommandNotSupportedError)
     expected_mock_s3g_obj = 'SUCCESS500'
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorSingle')
     expected_profile.values['print_to_file_type'] = ['s3g']
     expected_profile.values['software_variant'] = '0x00'
     expected_profile.values['tool_count_error'] = True
     expected_parser = makerbot_driver.Gcode.GcodeParser()
     return_obj = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(getattr(return_obj, 's3g') is not None)
     self.assertEqual(expected_profile.values,
                      getattr(return_obj, 'profile').values)
     self.assertTrue(getattr(return_obj, 'gcodeparser') is not None)
Exemplo n.º 23
0
 def test_build_from_port_tool_count_1_Replicator(self):
     #Time to mock all of s3g's version!
     tool_count = 1
     vid, pid = 0x23C1, 0xD314
     self.s3g_mock.get_version = mock.Mock(return_value=500)
     self.s3g_mock.get_toolhead_count = mock.Mock(return_value=tool_count)
     self.s3g_mock.get_vid_pid = mock.Mock()
     self.s3g_mock.get_vid_pid.return_value = vid, pid
     self.s3g_mock.get_advanced_version = mock.Mock(
         side_effect=makerbot_driver.CommandNotSupportedError)
     #Mock the returned s3g obj
     expected_mock_s3g_obj = 'SUCCESS500'
     self.factory.create_s3g = mock.Mock()
     self.factory.create_s3g.return_value = expected_mock_s3g_obj
     expected_profile = makerbot_driver.Profile('ReplicatorSingle')
     expected_profile.values['print_to_file_type'] = ['s3g']
     expected_profile.values['software_variant'] = '0x00'
     expected_profile.values['tool_count_error'] = False
     expected_parser = makerbot_driver.Gcode.GcodeParser()
     return_obj = self.factory.build_from_port('/dev/dummy_port')
     self.assertTrue(getattr(return_obj, 's3g') is not None)
     self.assertEqual(expected_profile.values,
                      getattr(return_obj, 'profile').values)
     self.assertTrue(getattr(return_obj, 'gcodeparser') is not None)
Exemplo n.º 24
0
 def setUp(self):
     self.profile = makerbot_driver.Profile('ReplicatorSingle')
     self.g = makerbot_driver.Gcode.GcodeStates()
     self.g.profile = self.profile
Exemplo n.º 25
0
 def setUp(self):
     self.profile = makerbot_driver.Profile("ReplicatorDual")
     self.g = makerbot_driver.Gcode.GcodeStates()
     self.g.profile = self.profile
Exemplo n.º 26
0
                  dest="sequences",
                  help="Flag to not use makerbot_driver's start/end sequences",
                  default=True,
                  action="store_false")

(options, args) = parser.parse_args()

for input_file in args:
    validGcode = True
    fh = tempfile.NamedTemporaryFile()

    s = makerbot_driver.s3g()
    condition = threading.Condition()
    s.writer = makerbot_driver.Writer.FileWriter(fh, condition)

    profile = makerbot_driver.Profile(options.machine)

    filename = os.path.basename(input_file)
    filename = os.path.splitext(filename)[0]

    parser = makerbot_driver.Gcode.GcodeParser()
    parser.state.values["build_name"] = filename
    parser.state.profile = profile
    parser.s3g = s

    ga = makerbot_driver.GcodeAssembler(profile)
    start, end, variables = ga.assemble_recipe()
    start_gcode = ga.assemble_start_sequence(start)
    end_gcode = ga.assemble_end_sequence(end)
    parser.environment.update(variables)
Exemplo n.º 27
0
 def setUp(self):
     self.profile = makerbot_driver.Profile('ReplicatorDual')
     self.ga = makerbot_driver.GcodeAssembler(self.profile)
     self.recipes = makerbot_driver.Profile('recipes')
Exemplo n.º 28
0
 def setUp(self):
     self.g = makerbot_driver.Gcode.GcodeStates()
     profile = makerbot_driver.Profile('ReplicatorDual')
     self.g.profile = profile
Exemplo n.º 29
0
 def _findprofile(self, name):
     if None is name:
         name = self._config['common']['profile']
     profile = makerbot_driver.Profile(name, self._config['common']['profiledir'])
     return profile
Exemplo n.º 30
0
    def test_bad_profile_name(self):
        bad_name = 'this_is_going_to_fail :('

        with self.assertRaises(IOError):
            makerbot_driver.Profile(bad_name)