modbus_send_raw_request.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. modbus_send_raw_request(3)
  2. ==========================
  3. NAME
  4. ----
  5. modbus_send_raw_request - send a raw request
  6. SYNOPSIS
  7. --------
  8. *int modbus_send_raw_request(*modbus_t 'ctx', uint8_t *'raw_req, int 'raw_req_length');*
  9. DESCRIPTION
  10. -----------
  11. The _modbus_send_raw_request()_ function shall send a request via the socket of
  12. the context 'ctx'. This function must be used for debugging purposes because you
  13. have to take care to make a valid request by hand. The function only adds to the
  14. message, the header or CRC of the selected backend, so 'raw_req' must start and
  15. contain at least a slave/unit identifier and a function code. This function can
  16. be used to send request not handled by the library.
  17. RETURN VALUE
  18. ------------
  19. The _modbus_send_raw_request()_ function shall return the full message length,
  20. counting the extra data relating to the backend, if successful. Otherwise it
  21. shall return -1 and set errno.
  22. EXAMPLE
  23. -------
  24. [source,c]
  25. -------------------
  26. modbus_t *ctx;
  27. /* Read 5 holding registers from address 1 */
  28. uint8_t raw_req[] = { 0xFF, 0x03, 0x00, 0x01, 0x0, 0x05 };
  29. int req_length;
  30. uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
  31. ctx = modbus_new_tcp("127.0.0.1", 1502);
  32. if (modbus_connect(ctx) == -1) {
  33. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  34. modbus_free(ctx);
  35. return -1;
  36. }
  37. req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
  38. modbus_receive(ctx, -1, rsp);
  39. modbus_close(ctx);
  40. modbus_free(ctx);
  41. -------------------
  42. SEE ALSO
  43. --------
  44. linkmb:modbus_receive[3]
  45. AUTHORS
  46. -------
  47. The libmodbus documentation was written by Stéphane Raimbault
  48. <stephane.raimbault@gmail.com>