def METHOD_NAME(self,m):
    '''
    set EMC mode if possible, else throw LinuxcncError
    return current mode
    '''
    self.s.poll()
    if self.s.task_mode == m :
        return m
    if self.running(do_poll=False):
        raise LinuxcncError("interpreter running - can not change mode")
    self.c.mode(m)
    self.c.wait_complete()
    return m