# Path: intera_interface/src/intera_io/io_command.py
# class SetCommand(IOCommand):
#     '''
#     Container for a port or signal set command
#     '''
#     def __init__(self, args=None):
#         super(SetCommand, self).__init__('set', args)
# 
#     def _set(self, components, component_name,
#              data_type, dimensions, *component_value):
#         '''
#         add a set component command
#         '''
#         self.args.setdefault(components, {})
#         self.args[components][component_name] = {
#             'format' : {'type' : data_type},
#             'data'   : [val for val in component_value]
#         }
#         if dimensions > 1:
#             self.args[components][component_name]['format']['dimensions'] = [dimensions]
# 
#     def set_signal(self, signal_name, data_type, *signal_value):
#         '''
#         add a set signal command
#         '''
#         dimensions = len(signal_value)
#         self._set('signals', signal_name, data_type, dimensions, *signal_value)
#         return self
# 
#     def set_port(self, port_name, data_type, *port_value):
#         '''
#         add a set port command
#         '''
#         dimensions = len(port_value)
#         self._set('ports', port_name, data_type, dimensions, *port_value)
#         return self


import rospy
import sys
import json
import copy
import threading
import uuid
import intera_dataflow
from threading import Lock
from .io_command import SetCommand
from intera_core_msgs.msg import (
    IODeviceConfiguration,
    IODeviceStatus,
    IOComponentCommand
)
        with self.state_mutex:
            if port_name in list(self.ports.keys()):
                return copy.deepcopy(self.ports[port_name]['type'])
        return None

    def get_port_value(self, port_name):
        """
        return the status for the given port, or none
        """
        with self.state_mutex:
            if port_name in list(self.ports.keys()):
                return copy.deepcopy(self.ports[port_name]['data'])
        return None

    def set_port_value(self, port_name, port_value, port_type=None, timeout=5.0):
        """
        set the value for the given port
        return True if the port value is set, False if the requested port is invalid
        """
        if port_name not in list_port_names():
            rospy.logerr("Cannot find port '{0}' in this IO Device ({1}).".format(port_name,
                self._path))
            return
        if port_type == None:
            p_type = self.get_port_type(port_name)
            if p_type == None:
                rospy.logerr("Failed to get 'type' for port '{0}'.".format(port_name))
                return
        else:
            p_type = port_type

# Path: intera_interface/src/intera_io/io_command.py
# class SetCommand(IOCommand):
#     '''
#     Container for a port or signal set command
#     '''
#     def __init__(self, args=None):
#         super(SetCommand, self).__init__('set', args)
# 
#     def _set(self, components, component_name,
#              data_type, dimensions, *component_value):
#         '''
#         add a set component command
#         '''
#         self.args.setdefault(components, {})
#         self.args[components][component_name] = {
#             'format' : {'type' : data_type},
#             'data'   : [val for val in component_value]
#         }
#         if dimensions > 1:
#             self.args[components][component_name]['format']['dimensions'] = [dimensions]
# 
#     def set_signal(self, signal_name, data_type, *signal_value):
#         '''
#         add a set signal command
#         '''
#         dimensions = len(signal_value)
#         self._set('signals', signal_name, data_type, dimensions, *signal_value)
#         return self
# 
#     def set_port(self, port_name, data_type, *port_value):
#         '''
#         add a set port command
#         '''
#         dimensions = len(port_value)
#         self._set('ports', port_name, data_type, dimensions, *port_value)
#         return self


# Path: intera_interface/src/intera_io/io_interface.py
import rospy
import sys
import json
import copy
import threading
import uuid
import intera_dataflow
from threading import Lock
from .io_command import SetCommand
from intera_core_msgs.msg import (
    IODeviceConfiguration,
    IODeviceStatus,
    IOComponentCommand
)

        with self.state_mutex:
            if port_name in list(self.ports.keys()):
                return copy.deepcopy(self.ports[port_name]['type'])
        return None

    def get_port_value(self, port_name):
        """
        return the status for the given port, or none
        """
        with self.state_mutex:
            if port_name in list(self.ports.keys()):
                return copy.deepcopy(self.ports[port_name]['data'])
        return None

    def set_port_value(self, port_name, port_value, port_type=None, timeout=5.0):
        """
        set the value for the given port
        return True if the port value is set, False if the requested port is invalid
        """
        if port_name not in list_port_names():
            rospy.logerr("Cannot find port '{0}' in this IO Device ({1}).".format(port_name,
                self._path))
            return
        if port_type == None:
            p_type = self.get_port_type(port_name)
            if p_type == None:
                rospy.logerr("Failed to get 'type' for port '{0}'.".format(port_name))
                return
        else:
            p_type = port_type

        set_command = SetCommand().set_port(port_name, p_type, port_value)