lirc-write.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _lirc-write:
  3. ************
  4. LIRC write()
  5. ************
  6. Name
  7. ====
  8. lirc-write - Write to a LIRC device
  9. Synopsis
  10. ========
  11. .. code-block:: c
  12. #include <unistd.h>
  13. .. c:function:: ssize_t write( int fd, void *buf, size_t count )
  14. :name: lirc-write
  15. Arguments
  16. =========
  17. ``fd``
  18. File descriptor returned by ``open()``.
  19. ``buf``
  20. Buffer with data to be written
  21. ``count``
  22. Number of bytes at the buffer
  23. Description
  24. ===========
  25. :ref:`write() <lirc-write>` writes up to ``count`` bytes to the device
  26. referenced by the file descriptor ``fd`` from the buffer starting at
  27. ``buf``.
  28. The exact format of the data depends on what mode a driver is in, use
  29. :ref:`lirc_get_features` to get the supported modes and use
  30. :ref:`lirc_set_send_mode` set the mode.
  31. When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
  32. the chardev is a pulse/space sequence of integer values. Pulses and spaces
  33. are only marked implicitly by their position. The data must start and end
  34. with a pulse, therefore, the data must always include an uneven number of
  35. samples. The write function blocks until the data has been transmitted
  36. by the hardware. If more data is provided than the hardware can send, the
  37. driver returns ``EINVAL``.
  38. When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
  39. ``struct lirc_scancode`` must be written to the chardev at a time, else
  40. ``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
  41. and the protocol in the :c:type:`rc_proto`: member. All other members must be
  42. set to 0, else ``EINVAL`` is returned. If there is no protocol encoder
  43. for the protocol or the scancode is not valid for the specified protocol,
  44. ``EINVAL`` is returned. The write function blocks until the scancode
  45. is transmitted by the hardware.
  46. Return Value
  47. ============
  48. On success, the number of bytes written is returned. It is not an error if
  49. this number is smaller than the number of bytes requested, or the amount
  50. of data required for one frame. On error, -1 is returned, and the ``errno``
  51. variable is set appropriately. The generic error codes are described at the
  52. :ref:`Generic Error Codes <gen-errors>` chapter.