#pragma once
#include <windows.h>
// Implementation notes:
// This DLL does not export any string function, to avoid ANSI-UNICODE problems.
// For simplicity, very few entry points exist.
// Moreover, this DLL internally defaults to use the wide-character Windows API
// (like CreateFileW) and automatically switches to ANSI Windows API set
// (like CreateFileA) when Windows 9x/Me is detected, by using the so-called
// GNUL library (static version). Unicows is not needed.
// See http://www.sourceforge.net/ for GNUL library project.
/* Change log
*101230 Added LPOVERLAY argument to all 4 data transfer functions
Functions remain to appear synchronous, however, DLL API changed!
*/
#ifdef HE2325U_EXPORTS
# define FUNC(type) EXTERN_C type _declspec(dllexport) WINAPI
#else
# define FUNC(type) EXTERN_C type _declspec(dllimport) WINAPI
#endif
#ifdef __cplusplus
# define DEF(x) =(x)
#else
# define DEF(x)
#endif
#pragma pack(1)
typedef struct{
BYTE ReportID; // = 0
long BaudRate; // 2400, 9600, 19200
BYTE unknown; // = 3
}HEFEATUREREPORT,*PHEFEATUREREPORT;
typedef struct{
BYTE ReportID;
BYTE NumBytes; // Mask out bits 7:3 for getting length!
BYTE data[7];
}HEINPUTREPORT,HEOUTPUTREPORT,*PHEINPUTREPORT,*PHEOUTPUTREPORT;
#pragma pack()
#define HE_NUM_MAX 256
// Return values in <List> array for HeEnum()
#define AVAILABLE 0
#define NOT_AVAILABLE -1
#define REMOVED -2
#define CANNOT_OPEN -3
// Fast enumeration of available HE2325U devices, index 0 means n=1 for HeOpen()
FUNC(void) HeEnum(char List[HE_NUM_MAX]);
// Opens an indexed HE2325U device, n=1: first index etc. - Maximum <n> is 256
// Parameters:
// * <n> = numbered index, 1..HE_NUM_MAX
// <n>=0 simply returns the first successfully opened device.
// * <baud> = Baudrate, =0: Do not automatically set baurate with Feature Report
// * <FlagsAndAttributes> can be FILE_FLAG_OVERLAPPED if someone wishes to make
// asynchronous (overlapped) I/O to the device:
// You cannot use HeRead() and HeWrite and you must implement access using
// ReadFile()/WriteFile()
// Return values:
// * A non-negative handle value if successful
// * INVALID_HANDLE_VALUE if unsuccessful (index is not in list)
// * (HANDLE)-2 if <n> is in list but device currently removed (good for grayed items)
// * (HANDLE)-3 if <n> is in list but device cannot be opened (good for otherwise grayed items)
FUNC(HANDLE) HeOpen(int n DEF(0), long baud DEF(0), DWORD FlagsAndAttributes DEF(0));
// For enumeration, a program should loop from n=1 upto HE_NUM_MAX (=256)
// and fill a list box with entries if return value is non-negative.
// Non-negative handles returned by HeOpen must be closed with CloseHandle().
// Returns the data of some reports into <buf>, until TotalTimeOut (in ms) occurs,
// or until IntervalTimeOut (in ms) occurs after the last filled input report,
// or until <buf> is used up with less than 7 free bytes.
// With these two timers, this function behaves almost as serial communication using
// SetCommTimeouts(), that would lead to comfortable programming of data-block slicing code.
// Set IntervalTimeOut to (UINT)-1 if you don't want this gap-detect feature.
// Set TotalTimeOut to (UINT)-1 if you want a blocking HeRead() until buffer is full.
// Returns the number of bytes read (may be 0), or -1 in case of system failure.
// Note that buffer size may not completely used up even if more input reports
// are in the queue!
// Consequently, this function returns immediately with 0 if <blen> is less than 7.
FUNC(int) HeRead(HANDLE h, BYTE *buf, int blen, UINT IntervalTimeOut DEF(50), UINT TotalTimeOut DEF(1000), LPOVERLAPPED o DEF(NULL));
// Puts data pointed by <data> and byte length <dlen> to the HE2325U device.
// This function may block until all bytes are sent, up to 8 ms * (dlen+6)/7.
// Returns TRUE if all bytes sent successfully, FALSE otherwise (system failure).
FUNC(BOOL) HeWrite(HANDLE h, const BYTE *data, int dlen, LPOVERLAPPED o DEF(NULL));
// Direct access to reports, can block up to 8 ms.
// Maybe, this can query/control the four parallel lines of the chip
FUNC(BOOL) HeReadReport(HANDLE h, HEINPUTREPORT *report, LPOVERLAPPED o DEF(NULL));
FUNC(BOOL) HeWriteReport(HANDLE h, const HEOUTPUTREPORT *report, LPOVERLAPPED o DEF(NULL));
#ifndef HE2325U_EXPORTS
# undef FUNC
#endif
Vorgefundene Kodierung: UTF-8 | 0
|