11 Resource temporarily unavailable, BeagleBone Black RS485 shield

Hi folks. I previously had some code working that wrote serial out to an RS485 shield. I’m setting up a new beagle bone and I can’t get the same code to work. When I write, I get an errno of 11 (Resource temporarily unavailable).

I must have set something up on the previous beagle bone, but I can’t remember what it would be. My best guess is that I need to do something to enable DE/ME on GPIO1_16. The shield (by LogicSupply) has a jumper to drive RE/DE from GPIO1_16 as opposed to RTS from UART4.

Here’s my code:

#include “Serial.h”

#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <asm/ioctls.h>
#include <errno.h>
#include <termios.h>
#include <linux/serial.h>

/* Driver-specific ioctls: */
#define TIOCGRS485 0x542E
#define TIOCSRS485 0x542F

#define SER_RS485_USE_GPIO (1<<5)

int SerialFD = -1;

int InitSerial(char* portPath)
{
if (SerialFD >= 0) {
fprintf(stdout, “InitSerial can only be called once\n”);
return 0;
}

/* Open your specific device (e.g., /dev/mydevice): */
SerialFD = open (portPath, O_RDWR);
if (SerialFD < 0) {
fprintf(stdout, “Couldn’t open device %d\n”, errno);
return 0;
}

termios myterm;

if (tcgetattr (SerialFD, &myterm) != 0) {
fprintf(stdout, “Couldn’t get existing termio attrs %d\n”, errno);
close(SerialFD);
return 0;
}

if (cfsetispeed(&myterm, B115200) < 0) {
fprintf(stdout, “Couldn’t set baud rate %d\n”, errno);
close(SerialFD);
return 0;
} else {
fprintf(stdout, “Starting terminal at B115200\n”);
}

myterm.c_iflag = 0;
myterm.c_oflag = 0;
myterm.c_lflag = 0;

tcsetattr(SerialFD, TCSANOW, &myterm);

struct serial_rs485 rs485conf;
bzero(&rs485conf, sizeof(serial_rs485));

/* Enable RS485 mode: */
rs485conf.flags = SER_RS485_ENABLED | SER_RS485_USE_GPIO;
rs485conf.padding[0] = 48;

if (ioctl (SerialFD, TIOCSRS485, &rs485conf) < 0) {
fprintf(stdout, “Couldn’t send ioctl %d\n”, errno);
close(SerialFD);
return 0;
}

return 1;
}

int SendData(const void *bytes, int length)
{
int result = write(SerialFD, bytes, length);
printf(“errno %d %s\n”, errno, strerror(errno));
}

void CloseSerial(void)
{
if (SerialFD) {
close (SerialFD);
}
}