#include <unistd.h>
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
+#if defined(__APPLE__)
+#include "fakepoll.h"
+#else
#include <sys/poll.h>
+#endif
#include <sys/ioctl.h>
-#include <errno.h>
#include <glib.h>
Rts = 16 /* Request to send */
} MonoSerialSignal;
+/*
+ * Silence the compiler, we do not need these prototypes to be public, since these are only
+ * used by P/Invoke
+ */
+
+int open_serial (char *devfile);
+int close_serial (int unix_fd);
+guint32 read_serial (int fd, guchar *buffer, int offset, int count);
+int write_serial (int fd, guchar *buffer, int offset, int count, int timeout);
+int discard_buffer (int fd, gboolean input);
+gint32 get_bytes_in_buffer (int fd, gboolean input);
+gboolean is_baud_rate_legal (int baud_rate);
+int setup_baud_rate (int baud_rate);
+gboolean set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake);
+MonoSerialSignal get_signals (int fd, gint32 *error);
+gint32 set_signal (int fd, MonoSerialSignal signal, gboolean value);
+int breakprop (int fd);
+gboolean poll_serial (int fd, gint32 *error, int timeout);
+void *list_serial_devices (void);
+
int
-open_serial (char* devfile)
+open_serial (char *devfile)
{
int fd;
fd = open (devfile, O_RDWR | O_NOCTTY | O_NONBLOCK);
while (n > 0)
{
- size_t t;
+ ssize_t t;
if (timeout != 0) {
int c;
}
gboolean
-set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
+is_baud_rate_legal (int baud_rate)
{
- struct termios newtio;
-
- if (tcgetattr (fd, &newtio) == -1)
- return FALSE;
-
- newtio.c_cflag |= (CLOCAL | CREAD);
- newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
- newtio.c_oflag &= ~(OPOST);
- newtio.c_iflag = IGNBRK;
+ return setup_baud_rate (baud_rate) != -1;
+}
- /* setup baudrate */
+int
+setup_baud_rate (int baud_rate)
+{
switch (baud_rate)
{
-/*This is not defined on OSX and *BSD */
+/*Some values are not defined on OSX and *BSD */
+#if defined(B921600)
+ case 921600:
+ baud_rate = B921600;
+ break;
+#endif
#if defined(B460800)
case 460800:
baud_rate = B460800;
case 50:
case 0:
default:
- baud_rate = B9600;
+ baud_rate = -1;
break;
}
+ return baud_rate;
+}
+
+gboolean
+set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
+{
+ struct termios newtio;
+
+ if (tcgetattr (fd, &newtio) == -1)
+ return FALSE;
+
+ newtio.c_cflag |= (CLOCAL | CREAD);
+ newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN );
+ newtio.c_oflag &= ~(OPOST);
+ newtio.c_iflag = IGNBRK;
+
+ /* setup baudrate */
+ baud_rate = setup_baud_rate (baud_rate);
/* char lenght */
newtio.c_cflag &= ~CSIZE;