modbus_new_rtu.txt 1.7 KB

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