Integrate the context object in the serial code.

This commit is contained in:
Jef Driesen 2012-07-11 16:32:14 +02:00
parent ffad80316c
commit 38c7b022cd
24 changed files with 92 additions and 98 deletions

View File

@ -193,7 +193,7 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
device->model = 0;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -207,7 +207,7 @@ hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -135,7 +135,7 @@ hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -125,7 +125,7 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
device->layout = &mares_darwin_layout;
// Open the device.
int rc = serial_open (&device->base.port, name);
int rc = serial_open (&device->base.port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -229,7 +229,7 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -116,7 +116,7 @@ mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *na
memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -114,7 +114,7 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
int rc = serial_open (&device->base.port, name);
int rc = serial_open (&device->base.port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -329,7 +329,7 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -245,7 +245,7 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -275,7 +275,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -116,7 +116,7 @@ reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char
memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -94,7 +94,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const c
memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -101,7 +101,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const
memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -22,6 +22,8 @@
#ifndef SERIAL_H
#define SERIAL_H
#include <libdivecomputer/context.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -56,7 +58,7 @@ typedef enum serial_line_t {
int serial_errcode (void);
const char* serial_errmsg (void);
int serial_open (serial_t **device, const char* name);
int serial_open (serial_t **device, dc_context_t *context, const char* name);
int serial_close (serial_t *device);

View File

@ -43,19 +43,12 @@
#define TIOCINQ FIONREAD
#endif
#include <libdivecomputer/utils.h>
#include "serial.h"
#define TRACE(expr) \
{ \
int error = errno; \
message ("TRACE (%s:%d, %s): %s (%d)\n", __FILE__, __LINE__, \
expr, serial_errmsg (), serial_errcode ()); \
errno = error; \
}
#include "context-private.h"
struct serial_t {
/* Library context. */
dc_context_t *context;
/*
* The file descriptor corresponding to the serial port.
*/
@ -93,7 +86,7 @@ const char* serial_errmsg (void)
//
int
serial_open (serial_t **out, const char* name)
serial_open (serial_t **out, dc_context_t *context, const char* name)
{
if (out == NULL)
return -1; // EINVAL (Invalid argument)
@ -101,10 +94,13 @@ serial_open (serial_t **out, const char* name)
// Allocate memory.
serial_t *device = (serial_t *) malloc (sizeof (serial_t));
if (device == NULL) {
TRACE ("malloc");
SYSERROR (context, errno);
return -1; // ENOMEM (Not enough space)
}
// Library context.
device->context = context;
// Default to blocking reads.
device->timeout = -1;
@ -117,7 +113,7 @@ serial_open (serial_t **out, const char* name)
// without waiting for the modem connection to complete.
device->fd = open (name, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (device->fd == -1) {
TRACE ("open");
SYSERROR (context, errno);
free (device);
return -1; // Error during open call.
}
@ -127,7 +123,7 @@ serial_open (serial_t **out, const char* name)
// It is also used to check if the obtained
// file descriptor represents a terminal device.
if (tcgetattr (device->fd, &device->tty) != 0) {
TRACE ("tcgetattr");
SYSERROR (context, errno);
close (device->fd);
free (device);
return -1;
@ -150,7 +146,7 @@ serial_close (serial_t *device)
// Restore the initial terminal attributes.
if (tcsetattr (device->fd, TCSANOW, &device->tty) != 0) {
TRACE ("tcsetattr");
SYSERROR (device->context, errno);
close (device->fd);
free (device);
return -1;
@ -158,7 +154,7 @@ serial_close (serial_t *device)
// Close the device.
if (close (device->fd) != 0) {
TRACE ("close");
SYSERROR (device->context, errno);
free (device);
return -1;
}
@ -182,7 +178,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Retrieve the current settings.
struct termios tty;
if (tcgetattr (device->fd, &tty) != 0) {
TRACE ("tcgetattr");
SYSERROR (device->context, errno);
return -1;
}
@ -278,7 +274,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
}
if (cfsetispeed (&tty, baud) != 0 ||
cfsetospeed (&tty, baud) != 0) {
TRACE ("cfsetispeed/cfsetospeed");
SYSERROR (device->context, errno);
return -1;
}
@ -360,7 +356,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Apply the new settings.
if (tcsetattr (device->fd, TCSANOW, &tty) != 0) {
TRACE ("tcsetattr");
SYSERROR (device->context, errno);
return -1;
}
@ -371,11 +367,11 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
struct termios active;
if (tcgetattr (device->fd, &active) != 0) {
TRACE ("tcgetattr");
SYSERROR (device->context, errno);
return -1;
}
if (memcmp (&tty, &active, sizeof (struct termios) != 0)) {
TRACE ("memcmp");
ERROR (device->context, "Failed to set the terminal attributes.");
return -1;
}
@ -385,7 +381,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Get the current settings.
struct serial_struct ss;
if (ioctl (device->fd, TIOCGSERIAL, &ss) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -396,13 +392,13 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Apply the new settings.
if (ioctl (device->fd, TIOCSSERIAL, &ss) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
#elif defined(IOSSIOSPEED)
speed_t speed = baudrate;
if (ioctl (device->fd, IOSSIOSPEED, &speed) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
#else
@ -482,7 +478,7 @@ serial_read (serial_t *device, void *data, unsigned int size)
if (timeout > 0) {
struct timeval now;
if (gettimeofday (&now, NULL) != 0) {
TRACE ("gettimeofday");
SYSERROR (device->context, errno);
return -1;
}
@ -508,7 +504,7 @@ serial_read (serial_t *device, void *data, unsigned int size)
if (rc < 0) {
if (errno == EINTR)
continue; // Retry.
TRACE ("select");
SYSERROR (device->context, errno);
return -1; // Error during select call.
} else if (rc == 0) {
break; // Timeout.
@ -518,7 +514,7 @@ serial_read (serial_t *device, void *data, unsigned int size)
if (n < 0) {
if (errno == EINTR || errno == EAGAIN)
continue; // Retry.
TRACE ("read");
SYSERROR (device->context, errno);
return -1; // Error during read call.
} else if (n == 0) {
break; // EOF.
@ -541,7 +537,7 @@ serial_write (serial_t *device, const void *data, unsigned int size)
if (device->halfduplex) {
// Get the current time.
if (gettimeofday (&tvb, NULL) != 0) {
TRACE ("gettimeofday");
SYSERROR (device->context, errno);
return -1;
}
}
@ -556,7 +552,7 @@ serial_write (serial_t *device, const void *data, unsigned int size)
if (rc < 0) {
if (errno == EINTR)
continue; // Retry.
TRACE ("select");
SYSERROR (device->context, errno);
return -1; // Error during select call.
} else if (rc == 0) {
break; // Timeout.
@ -566,7 +562,7 @@ serial_write (serial_t *device, const void *data, unsigned int size)
if (n < 0) {
if (errno == EINTR || errno == EAGAIN)
continue; // Retry.
TRACE ("write");
SYSERROR (device->context, errno);
return -1; // Error during write call.
} else if (n == 0) {
break; // EOF.
@ -578,7 +574,7 @@ serial_write (serial_t *device, const void *data, unsigned int size)
// Wait until all data has been transmitted.
while (tcdrain (device->fd) != 0) {
if (errno != EINTR ) {
TRACE ("tcdrain");
SYSERROR (device->context, errno);
return -1;
}
}
@ -586,7 +582,7 @@ serial_write (serial_t *device, const void *data, unsigned int size)
if (device->halfduplex) {
// Get the current time.
if (gettimeofday (&tve, NULL) != 0) {
TRACE ("gettimeofday");
SYSERROR (device->context, errno);
return -1;
}
@ -635,7 +631,7 @@ serial_flush (serial_t *device, int queue)
}
if (tcflush (device->fd, flags) != 0) {
TRACE ("tcflush");
SYSERROR (device->context, errno);
return -1;
}
@ -650,7 +646,7 @@ serial_send_break (serial_t *device)
return -1; // EINVAL (Invalid argument)
if (tcsendbreak (device->fd, 0) != 0) {
TRACE ("tcsendbreak");
SYSERROR (device->context, errno);
return -1;
}
@ -667,7 +663,7 @@ serial_set_break (serial_t *device, int level)
unsigned long action = (level ? TIOCSBRK : TIOCCBRK);
if (ioctl (device->fd, action, NULL) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -685,7 +681,7 @@ serial_set_dtr (serial_t *device, int level)
int value = TIOCM_DTR;
if (ioctl (device->fd, action, &value) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -703,7 +699,7 @@ serial_set_rts (serial_t *device, int level)
int value = TIOCM_RTS;
if (ioctl (device->fd, action, &value) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -719,7 +715,7 @@ serial_get_received (serial_t *device)
int bytes = 0;
if (ioctl (device->fd, TIOCINQ, &bytes) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -735,7 +731,7 @@ serial_get_transmitted (serial_t *device)
int bytes = 0;
if (ioctl (device->fd, TIOCOUTQ, &bytes) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -751,7 +747,7 @@ serial_get_line (serial_t *device, int line)
int status = 0;
if (ioctl (device->fd, TIOCMGET, &status) != 0) {
TRACE ("ioctl");
SYSERROR (device->context, errno);
return -1;
}
@ -784,7 +780,7 @@ serial_sleep (serial_t *device, unsigned long timeout)
while (nanosleep (&ts, &ts) != 0) {
if (errno != EINTR ) {
TRACE ("nanosleep");
SYSERROR (device->context, errno);
return -1;
}
}

View File

@ -22,19 +22,12 @@
#include <stdlib.h>
#include <windows.h>
#include <libdivecomputer/utils.h>
#include "serial.h"
#define TRACE(expr) \
{ \
DWORD error = GetLastError (); \
message ("TRACE (%s:%d, %s): %s (%d)\n", __FILE__, __LINE__, \
expr, serial_errmsg (), serial_errcode ()); \
SetLastError (error); \
}
#include "context-private.h"
struct serial_t {
/* Library context. */
dc_context_t *context;
/*
* The file descriptor corresponding to the serial port.
*/
@ -91,7 +84,7 @@ const char* serial_errmsg (void)
//
int
serial_open (serial_t **out, const char* name)
serial_open (serial_t **out, dc_context_t *context, const char* name)
{
if (out == NULL)
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
@ -112,10 +105,13 @@ serial_open (serial_t **out, const char* name)
// Allocate memory.
serial_t *device = (serial_t *) malloc (sizeof (serial_t));
if (device == NULL) {
TRACE ("malloc");
SYSERROR (context, ERROR_OUTOFMEMORY);
return -1; // ERROR_OUTOFMEMORY (Not enough storage is available to complete this operation)
}
// Library context.
device->context = context;
// Default to full-duplex.
device->halfduplex = 0;
device->baudrate = 0;
@ -129,7 +125,7 @@ serial_open (serial_t **out, const char* name)
0, // Non-overlapped I/O.
NULL);
if (device->hFile == INVALID_HANDLE_VALUE) {
TRACE ("CreateFile");
SYSERROR (context, GetLastError ());
free (device);
return -1;
}
@ -140,7 +136,7 @@ serial_open (serial_t **out, const char* name)
// represents a serial device.
if (!GetCommState (device->hFile, &device->dcb) ||
!GetCommTimeouts (device->hFile, &device->timeouts)) {
TRACE ("GetCommState/GetCommTimeouts");
SYSERROR (context, GetLastError ());
CloseHandle (device->hFile);
free (device);
return -1;
@ -164,7 +160,7 @@ serial_close (serial_t *device)
// Restore the initial communication settings and timeouts.
if (!SetCommState (device->hFile, &device->dcb) ||
!SetCommTimeouts (device->hFile, &device->timeouts)) {
TRACE ("SetCommState/SetCommTimeouts");
SYSERROR (device->context, GetLastError ());
CloseHandle (device->hFile);
free (device);
return -1;
@ -172,7 +168,7 @@ serial_close (serial_t *device)
// Close the device.
if (!CloseHandle (device->hFile)) {
TRACE ("CloseHandle");
SYSERROR (device->context, GetLastError ());
free (device);
return -1;
}
@ -196,7 +192,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Retrieve the current settings.
DCB dcb;
if (!GetCommState (device->hFile, &dcb)) {
TRACE ("GetCommState");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -273,7 +269,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int
// Apply the new settings.
if (!SetCommState (device->hFile, &dcb)) {
TRACE ("SetCommState");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -296,7 +292,7 @@ serial_set_timeout (serial_t *device, long timeout)
// Retrieve the current timeouts.
COMMTIMEOUTS timeouts;
if (!GetCommTimeouts (device->hFile, &timeouts)) {
TRACE ("GetCommTimeouts");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -326,7 +322,7 @@ serial_set_timeout (serial_t *device, long timeout)
// Activate the new timeouts.
if (!SetCommTimeouts (device->hFile, &timeouts)) {
TRACE ("SetCommTimeouts");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -344,7 +340,7 @@ serial_set_queue_size (serial_t *device, unsigned int input, unsigned int output
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
if (!SetupComm (device->hFile, input, output)) {
TRACE ("SetupComm");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -372,7 +368,7 @@ serial_read (serial_t *device, void* data, unsigned int size)
DWORD dwRead = 0;
if (!ReadFile (device->hFile, data, size, &dwRead, NULL)) {
TRACE ("ReadFile");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -391,21 +387,21 @@ serial_write (serial_t *device, const void* data, unsigned int size)
// Get the current time.
if (!QueryPerformanceFrequency(&freq) ||
!QueryPerformanceCounter(&begin)) {
TRACE ("QueryPerformanceCounter");
SYSERROR (device->context, GetLastError ());
return -1;
}
}
DWORD dwWritten = 0;
if (!WriteFile (device->hFile, data, size, &dwWritten, NULL)) {
TRACE ("WriteFile");
SYSERROR (device->context, GetLastError ());
return -1;
}
if (device->halfduplex) {
// Get the current time.
if (!QueryPerformanceCounter(&end)) {
TRACE ("QueryPerformanceCounter");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -452,7 +448,7 @@ serial_flush (serial_t *device, int queue)
}
if (!PurgeComm (device->hFile, flags)) {
TRACE ("PurgeComm");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -467,14 +463,14 @@ serial_send_break (serial_t *device)
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
if (!SetCommBreak (device->hFile)) {
TRACE ("SetCommBreak");
SYSERROR (device->context, GetLastError ());
return -1;
}
Sleep (250);
if (!ClearCommBreak (device->hFile)) {
TRACE ("ClearCommBreak");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -490,12 +486,12 @@ serial_set_break (serial_t *device, int level)
if (level) {
if (!SetCommBreak (device->hFile)) {
TRACE ("SetCommBreak");
SYSERROR (device->context, GetLastError ());
return -1;
}
} else {
if (!ClearCommBreak (device->hFile)) {
TRACE ("ClearCommBreak");
SYSERROR (device->context, GetLastError ());
return -1;
}
}
@ -512,7 +508,7 @@ serial_set_dtr (serial_t *device, int level)
int status = (level ? SETDTR : CLRDTR);
if (!EscapeCommFunction (device->hFile, status)) {
TRACE ("EscapeCommFunction");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -529,7 +525,7 @@ serial_set_rts (serial_t *device, int level)
int status = (level ? SETRTS : CLRRTS);
if (!EscapeCommFunction (device->hFile, status)) {
TRACE ("EscapeCommFunction");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -546,7 +542,7 @@ serial_get_received (serial_t *device)
COMSTAT stats;
if (!ClearCommError (device->hFile, NULL, &stats)) {
TRACE ("ClearCommError");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -563,7 +559,7 @@ serial_get_transmitted (serial_t *device)
COMSTAT stats;
if (!ClearCommError (device->hFile, NULL, &stats)) {
TRACE ("ClearCommError");
SYSERROR (device->context, GetLastError ());
return -1;
}
@ -579,7 +575,7 @@ serial_get_line (serial_t *device, int line)
DWORD stats = 0;
if (!GetCommModemStatus (device->hFile, &stats)) {
TRACE ("GetCommModemStatus");
SYSERROR (device->context, GetLastError ());
return -1;
}

View File

@ -145,7 +145,7 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -95,7 +95,7 @@ suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *na
device->port = NULL;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -88,7 +88,7 @@ suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const cha
device->port = NULL;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -116,7 +116,7 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *
device->delay = 500;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -94,7 +94,7 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
device->port = NULL;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -100,7 +100,7 @@ uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char
device->devtime = 0;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -98,7 +98,7 @@ uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const ch
device->devtime = 0;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);

View File

@ -156,7 +156,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const cha
device->port = NULL;
// Open the device.
int rc = serial_open (&device->port, name);
int rc = serial_open (&device->port, context, name);
if (rc == -1) {
ERROR (context, "Failed to open the serial port.");
free (device);