ev3duder  0.3.0
EV3 Downloader/Uploader
bt-win.c File Reference

Windows bluetooth I/O using virtual COM port. More...

#include <stdlib.h>
#include <errno.h>
#include <windows.h>
#include "defs.h"

Go to the source code of this file.

Macros

#define BT   "COM1"
 

Functions

void * bt_open (const char *device, const char *unused)
 opens COM Porte described by device. NULL leads to default action More...
 
int bt_write (void *handle, const u8 *buf, size_t count)
 writes buf[1] till buf[count - 2] to device More...
 
int bt_read (void *handle, u8 *buf, size_t count, int milliseconds)
 writes buf[1] till buf[count - 2] to device More...
 
void bt_close (void *handle)
 calls CloseHandle on argument More...
 
const wchar_t * bt_error (void *fd_)
 Returns an error string describing the last error occured. More...
 

Detailed Description

Windows bluetooth I/O using virtual COM port.

Author
Ahmad Fatoum

Definition in file bt-win.c.

Macro Definition Documentation

#define BT   "COM1"

Definition at line 14 of file bt-win.c.

Function Documentation

void bt_close ( void *  handle)

calls CloseHandle on argument

Closes the resource opened by bt_open.

Parameters
[in]handlehandle returned by bt_open
Bug:
It takes whopping 3 seconds for the COM port to be reclaimable. If opened before that, the device is unusable for a minute.

Definition at line 69 of file bt-win.c.

const wchar_t* bt_error ( void *  fd_)

Returns an error string describing the last error occured.

Parameters
[in]devicehandle returned by bt_open
Returns
message An error string

Definition at line 79 of file bt-win.c.

void* bt_open ( const char *  device,
const char *  unused 
)

opens COM Porte described by device. NULL leads to default action

open a bluetooth device described by device. NULL leads to default action

Parameters
[in]virtualCOM port or NULL
Returns
HANDLE Windows HANDLE to virtual COM port for use with bt_{read,write,close,error}

Definition at line 21 of file bt-win.c.

int bt_read ( void *  handle,
u8 buf,
size_t  count,
int  milliseconds 
)

writes buf[1] till buf[count - 2] to device

Parameters
[in]devicehandle returned by bt_open
[in]bufbuffer to write to
[in]countnumber of characters to be read
[in]millisecondsis ignored
Returns
status -1 on error. bytes read otherwise.
Bug:
milliseconds is ignored

Definition at line 56 of file bt-win.c.

int bt_write ( void *  handle,
const u8 buf,
size_t  count 
)

writes buf[1] till buf[count - 2] to device

Parameters
[in]handlehandle returned by bt_open
[in]bufbyte string to write, the first byte is omitted
[in]countnumber of characters to be written (including leading ignored byte)
Returns
status -1 on error. bytes read otherwise.
Bug:
the first byte is omitted for compatiblity with the leading report byte demanded by hid_write. Wrapping HIDAPI could fix this.

Definition at line 36 of file bt-win.c.