#ifdef DARWIN
+#include <unistd.h>
+
#undef USE_POLL
/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
if (!get_number (object, CFSTR(kUSBVendorID), &device->vendor) ||
!get_number (object, CFSTR(kUSBProductID), &device->product))
continue;
- if (list->ftdi) {
- if (device->vendor != 0x0403)
- continue;
- } else {
- if (device->vendor != 0xfffe)
- continue;
- if (device->product < 0x000a || 0x0013 < device->product)
- continue;
- }
if (get_string (object, CFSTR("IOCalloutDevice"), device->path, sizeof (device->path)) &&
get_string (object, CFSTR("USB Product Name"), device->name, sizeof (device->name)) &&
get_string (object, CFSTR("USB Serial Number"), serial_string, sizeof (serial_string))) {
if (!log)
log = fopen("\\temp\\altos.txt", "w");
if (log) {
+ SYSTEMTIME time;
+ GetLocalTime(&time);
+ fprintf (log, "%4d-%02d-%02d %2d:%02d:%02d. ",
+ time.wYear, time.wMonth, time.wDay,
+ time.wHour, time.wMinute, time.wSecond);
va_start(a, fmt);
vfprintf(log, fmt, a);
va_end(a);
file->handle = open_serial(full_name);
if (file->handle != INVALID_HANDLE_VALUE)
break;
+ altos_set_last_windows_error();
Sleep(100);
}
PUBLIC void
altos_close(struct altos_file *file)
{
- if (file->handle != INVALID_HANDLE_VALUE) {
- CloseHandle(file->handle);
+ HANDLE handle = file->handle;
+ if (handle != INVALID_HANDLE_VALUE) {
+ HANDLE ov_read = file->ov_read.hEvent;
+ HANDLE ov_write = file->ov_write.hEvent;
+ file->handle = INVALID_HANDLE_VALUE;
+ file->ov_read.hEvent = INVALID_HANDLE_VALUE;
+ file->ov_write.hEvent = INVALID_HANDLE_VALUE;
+ PurgeComm(handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR);
+ Sleep(100);
+ CloseHandle(handle);
file->handle = INVALID_HANDLE_VALUE;
- SetEvent(file->ov_read.hEvent);
- SetEvent(file->ov_write.hEvent);
- CloseHandle(file->ov_read.hEvent);
- CloseHandle(file->ov_write.hEvent);
+ CloseHandle(ov_read);
+ CloseHandle(ov_write);
}
}