parameters: (
      command: SerialCommand,
      serial: str = Path(..., description="Serial number of the module"),
      hardware: HardwareControlAPI = Depends(get_hardware),
  )
docstring: Send a command on device identified by serial
docstring_summary: Send a command on device identified by serial
docstring_tokens: Send a command on device identified by serial
function: async def post_serial_command(
      command: SerialCommand,
      serial: str = Path(..., description="Serial number of the module"),
      hardware: HardwareControlAPI = Depends(get_hardware),
  ) -> SerialCommandResponse:
      """Send a command on device identified by serial"""
      attached_modules = hardware.attached_modules
      if not attached_modules:
          raise LegacyErrorResponse(message="No connected modules").as_error(
              status.HTTP_404_NOT_FOUND
          )
  
      # Search for the module
      matching_mod = find_matching_module(serial, attached_modules)
  
      if not matching_mod:
          raise LegacyErrorResponse(message="Specified module not found").as_error(
              status.HTTP_404_NOT_FOUND
          )
  
      if hasattr(matching_mod, command.command_type):
          clean_args = command.args or []
          method = getattr(matching_mod, command.command_type)
          try:
              if asyncio.iscoroutinefunction(method):
                  val = await method(*clean_args)
              else:
                  val = method(*clean_args)
          except TypeError as e:
              raise LegacyErrorResponse(
                  message=f"Server encountered a TypeError "
                  f"while running {method} : {e}. "
                  f"Possibly a type mismatch in args"
              ).as_error(status.HTTP_400_BAD_REQUEST)
          else:
              return SerialCommandResponse(message="Success", returnValue=val)
      else:
          raise LegacyErrorResponse(
              message=f"Module does not have command: {command.command_type}"
          ).as_error(status.HTTP_400_BAD_REQUEST)
function_tokens: async def post_serial_command ( command : SerialCommand , serial : str = Path ( ... , description = "Serial number of the module" ) , hardware : HardwareControlAPI = Depends ( get_hardware ) , ) -> SerialCommandResponse : attached_modules = hardware . attached_modules if not attached_modules : raise LegacyErrorResponse ( message = "No connected modules" ) . as_error ( status . HTTP_404_NOT_FOUND ) # Search for the module matching_mod = find_matching_module ( serial , attached_modules ) if not matching_mod : raise LegacyErrorResponse ( message = "Specified module not found" ) . as_error ( status . HTTP_404_NOT_FOUND ) if hasattr ( matching_mod , command . command_type ) : clean_args = command . args or [ ] method = getattr ( matching_mod , command . command_type ) try : if asyncio . iscoroutinefunction ( method ) : val = await method ( * clean_args ) else : val = method ( * clean_args ) except TypeError as e : raise LegacyErrorResponse ( message = f"Server encountered a TypeError " f"while running {method} : {e}. " f"Possibly a type mismatch in args" ) . as_error ( status . HTTP_400_BAD_REQUEST ) else : return SerialCommandResponse ( message = "Success" , returnValue = val ) else : raise LegacyErrorResponse ( message = f"Module does not have command: {command.command_type}" ) . as_error ( status . HTTP_400_BAD_REQUEST )