'\" t
.\"     Title: modbus_new_rtu
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\"      Date: 05/26/2012
.\"    Manual: Libmodbus Manual
.\"    Source: libmodbus 3.0.3
.\"  Language: English
.\"
.TH "MODBUS_NEW_RTU" "3" "05/26/2012" "libmodbus 3\&.0\&.3" "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_rtu \- create a libmodbus context for RTU
.SH "SYNOPSIS"
.sp
\fBmodbus_t *modbus_new_rtu(const char *\fR\fB\fIdevice\fR\fR\fB, int \fR\fB\fIbaud\fR\fR\fB, char \fR\fB\fIparity\fR\fR\fB, int \fR\fB\fIdata_bit\fR\fR\fB, int \fR\fB\fIstop_bit\fR\fR\fB);\fR
.SH "DESCRIPTION"
.sp
The \fImodbus_new_rtu()\fR function shall allocate and initialize a modbus_t structure to communicate in RTU mode on a serial line\&.
.sp
The \fIdevice\fR argument specifies the name of the serial port handled by the OS, eg\&. \fI/dev/ttyS0\fR or \fI/dev/ttyUSB0\fR\&. On Windows, it\(cqs necessary to prepend COM name with \fI\e\e\&.\e\fR for COM number greater than 9, eg\&. \fI\e\e\e\e\&.\e\eCOM10\fR\&. See \m[blue]\fBhttp://msdn\&.microsoft\&.com/en\-us/library/aa365247(v=vs\&.85)\&.aspx\fR\m[] for details
.sp
The \fIbaud\fR argument specifies the baud rate of the communication, eg\&. 9600, 19200, 57600, 115200, etc\&.
.PP
The \fIparity\fR argument can have one of the following values
.RS 4
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}

\fIN\fR
for none
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}

\fIE\fR
for even
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}

\fIO\fR
for odd
.RE
.RE
.sp
The \fIdata_bits\fR argument specifies the number of bits of data, the allowed values are 5, 6, 7 and 8\&.
.sp
The \fIstop_bits\fR argument specifies the bits of stop, the allowed values are 1 and 2\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_new_rtu()\fR 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
An invalid argument was given\&.
.RE
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
modbus_t *ctx;

ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, \*(AqN\*(Aq, 8, 1);
if (ctx == NULL) {
    fprintf(stderr, "Unable to create the libmodbus context\en");
    return \-1;
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_new_tcp\fR(3) \fBmodbus_free\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
.SH "NOTES"
.IP " 1." 4
stephane.raimbault@gmail.com
.RS 4
\%mailto:stephane.raimbault@gmail.com
.RE
