Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

User:Pau pajuelo

1,130 bytes added, 11:19, 29 August 2012
m
Program
<pre>jdoe@ubuntu ~ $ source /opt/poky/1.2/environment-setup-armv7a-vfp-neon-poky-linux-gnueabi </pre>
Create a single .c file (hello-world.c), using your preferred editor (vi, nano, gedit, ...) <br> hello-world.c:
<pre>/* 485-example.c : Basic example of RS485 half duplex transmission */#include &lt;<stdio.h&gt; >#include <string.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <termios.h> #include <sys/ioctl.h>#include <asm/ioctls.h> #include <linux/serial.h> int main (int argc, char **argvvoid)
{
char dev[] = "/dev/ttyO0"; char tosend[] = {'A', 'B', 'C'}; struct serial_rs485 ctrl485; int status; int fd;  struct termios ti; speed_t speed;  /* Open the port */ fd = open(dev, O_RDWR); if (fd < 0) { printf("%s: Unable to open.\n", dev); return -1; }  /* Set the port in 485 mode */ ctrl485.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND; ctrl485.delay_rts_before_send = 0; ctrl485.delay_rts_after_send = 0;  status = ioctl(fd, TIOCSRS485, &ctrl485); if (status) { printf("Hello world%s: Unable to configure port in 485 mode, status (%i)\n", dev, status); return -1; }  /* Set the port speed */ speed = B9600; tcgetattr(fd, &nbspti); cfsetospeed(&ti, speed); cfsetispeed(&ti, speed); tcsetattr(fd, TCSANOW, &ti);  /* Send content to RS485 */ if (write(fd, tosend, sizeof(tosend)) != sizeof(tosend)) { printf("%s: write() failed\n", dev); }  return 0;
}
</pre>
4,199
edits