modbus_new_rtu.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. modbus_new_rtu(3)
  2. =================
  3. NAME
  4. ----
  5. modbus_new_rtu - create a libmodbus context for RTU
  6. SYNOPSIS
  7. --------
  8. *modbus_t modbus_new_rtu(const char *'device', int 'baud',
  9. char 'parity', int 'data_bit', int 'stop_bit')*
  10. DESCRIPTION
  11. -----------
  12. The _modbus_new_rtu()_ function shall allocate and initialize a modbus_t
  13. structure to communicate in RTU mode on a serial line.
  14. The _device_ argument specifies the name of the serial port handled by the OS,
  15. eg. '/dev/ttyS0' or '/dev/ttyUSB0'. On Windows, it's necessary to prepend COM
  16. name with '\\.\' for COM number greater than 9, eg. '\\\\.\\COM10'. See
  17. http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx for details
  18. The _baud_ argument specifies the baud rate of the communication, eg. 9600,
  19. 19200, 57600, 115200, etc.
  20. The _parity_ argument can have one of the following values:::
  21. * _N_ for none
  22. * _E_ for even
  23. * _O_ for odd
  24. The _data_bits_ argument specifies the number of bits of data, the allowed
  25. values are 5, 6, 7 and 8.
  26. The _stop_bits_ argument specifies the bits of stop, the allowed values are 1
  27. and 2.
  28. RETURN VALUE
  29. ------------
  30. The _modbus_new_rtu()_ function shall return a pointer to a *modbus_t* structure
  31. if successful. Otherwise it shall return NULL and set errno to one of the values
  32. defined below.
  33. ERRORS
  34. ------
  35. *EINVAL*::
  36. An invalid argument was given.
  37. EXAMPLE
  38. -------
  39. [source,c]
  40. -------------------
  41. modbus_t *ctx;
  42. ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
  43. if (ctx == NULL) {
  44. fprintf(stderr, "Unable to create the libmodbus context\n");
  45. return -1;
  46. }
  47. -------------------
  48. SEE ALSO
  49. --------
  50. linkmb:modbus_new_tcp[3]
  51. linkmb:modbus_free[3]
  52. AUTHORS
  53. -------
  54. The libmodbus documentation was written by Stéphane Raimbault
  55. <stephane.raimbault@gmail.com>