'\" t .\" Title: modbus_new_tcp_pi .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 10/15/2022 .\" Manual: libmodbus Manual .\" Source: libmodbus v3.1.6 .\" Language: English .\" .TH "MODBUS_NEW_TCP_PI" "3" "10/15/2022" "libmodbus v3\&.1\&.6" "libmodbus Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" modbus_new_tcp_pi \- create a libmodbus context for TCP Protocol Independent .SH "SYNOPSIS" .sp \fBmodbus_t *modbus_new_tcp_pi(const char *\fR\fB\fInode\fR\fR\fB, const char *\fR\fB\fIservice\fR\fR\fB);\fR .SH "DESCRIPTION" .sp The \fBmodbus_new_tcp_pi()\fR function shall allocate and initialize a modbus_t structure to communicate with a Modbus TCP IPv4 or IPv6 server\&. .sp The \fInode\fR argument specifies the host name or IP address of the host to connect to, eg\&. "192\&.168\&.0\&.5" , "::1" or "server\&.com"\&. A NULL value can be used to listen any addresses in server mode\&. .sp The \fIservice\fR argument is the service name/port number to connect to\&. To use the default Modbus port use the string "502"\&. On many Unix systems, it\(cqs convenient to use a port number greater than or equal to 1024 because it\(cqs not necessary to have administrator privileges\&. .SH "RETURN VALUE" .sp The function shall return a pointer to a \fBmodbus_t\fR structure if successful\&. Otherwise it shall return NULL and set errno to one of the values defined below\&. .SH "ERRORS" .PP \fBEINVAL\fR .RS 4 The node string is empty or has been truncated\&. The service string is empty or has been truncated\&. .RE .PP \fBENOMEM\fR .RS 4 Out of memory\&. Possibly, the application hits its memory limit and/or whole system is running out of memory\&. .RE .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf modbus_t *ctx; ctx = modbus_new_tcp_pi("::1", "1502"); if (ctx == NULL) { fprintf(stderr, "Unable to allocate libmodbus context\en"); return \-1; } if (modbus_connect(ctx) == \-1) { fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno)); modbus_free(ctx); return \-1; } .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBmodbus_new_tcp\fR(3) \fBmodbus_tcp_pi_listen\fR(3) \fBmodbus_free\fR(3) .SH "AUTHORS" .sp The libmodbus documentation was written by Stéphane Raimbault