//////////////////////////////////////////////////////////////////////
//
// PmcaCom.h: interface for the PmcaCom module.
//
// This header file is a part of the PMCA COM package
//
// Amptek Inc, 2000
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PMCACOM_H__F277DC42_F1AE_11D1_B630_9CFF0CC10000__INCLUDED_)
#define AFX_PMCACOM_H__F277DC42_F1AE_11D1_B630_9CFF0CC10000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000


#pragma pack(push)
#pragma pack(1)

typedef enum
{
    PMCA_AUTO_DETECT,
    PMCA_8000,
    PMCA_8000A
} PmcaDeviceType;

typedef enum
{
    PMCA_LI,
    PMCA_NICAD
} PmcaBatteryType;

typedef union
{
    struct
    {
        unsigned char gain:3;
        unsigned char live:1;
        unsigned char acquire:1;
        unsigned char secure:1;
        unsigned char batteryType:1;
        unsigned char batteryCondition:1;
    } bits;
    unsigned char byte;
} PmcaFlagsType;

typedef struct
{
    PmcaFlagsType   flags;
    unsigned short  threshold:15;
    unsigned short  absolutePeak:1;
} PmcaControlType;

typedef struct
{
    unsigned char   checkSum;
    PmcaControlType control;
    unsigned long   liveTime75:8;
    unsigned long   liveTime:24;
    unsigned long   realTime75:8;
    unsigned long   realTime:24;
    unsigned long   battery:8;
    unsigned long   presetTime:24;
    union
    {
        unsigned long checkSum;
        struct
        {
            unsigned short  group:10;
            unsigned short  spare:6;
            unsigned short  serialNumber;
        } gsn;
    } u;
} PmcaStatusType;

#pragma pack(pop)

#define STATUS_SIZE 20
#define TIME_STAMP_SIZE 8


#if defined(PMCA_IMPORT)
#define PMCA_EXETRN __declspec(dllimport)

#elif defined(PMCA_EXPORT)
#define PMCA_EXTERN __declspec(dllexport)

#else
#define PMCA_EXTERN extern
#endif

#define PMCA_CALL _stdcall
#define PMCA_RETURN int PMCA_CALL

PMCA_EXTERN PmcaDeviceType PMCA_CALL PmcaGetDeviceType(void);
PMCA_EXTERN PMCA_RETURN PmcaTerminateCom(void);
PMCA_EXTERN PMCA_RETURN PmcaSetPriority(int priority);
PMCA_EXTERN PMCA_RETURN PmcaCancel(int id);
PMCA_EXTERN PMCA_RETURN PmcaWait(int id);

// Synchronous functions

PMCA_EXTERN PMCA_RETURN PmcaPowerUp(int port);
PMCA_EXTERN PMCA_RETURN PmcaConnect(
        int port, int baudRate, PmcaDeviceType device);
PMCA_EXTERN PMCA_RETURN PmcaDisconnect(void);

PMCA_EXTERN PMCA_RETURN PmcaGetSerialNumber(void);
PMCA_EXTERN PMCA_RETURN PmcaGetBatteryType(void);
PMCA_EXTERN PMCA_RETURN PmcaGetBatteryCondition(void);
PMCA_EXTERN PMCA_RETURN PmcaGetBatteryCapacity(void);
PMCA_EXTERN PMCA_RETURN PmcaGetGroup(void);
PMCA_EXTERN PMCA_RETURN PmcaGetThreshold(void);
PMCA_EXTERN PMCA_RETURN PmcaGetGain(void);
PMCA_EXTERN PMCA_RETURN PmcaGetRealTime(void);
PMCA_EXTERN PMCA_RETURN PmcaGetLiveTime(void);
PMCA_EXTERN PMCA_RETURN PmcaGetFlags(PmcaFlagsType *flags);
PMCA_EXTERN PMCA_RETURN PmcaGetStatus(PmcaStatusType *status);
PMCA_EXTERN PMCA_RETURN PmcaGetData(unsigned long *buffer,
        int channel, int dwordCount);
PMCA_EXTERN PMCA_RETURN PmcaGetDateAndTime(char *strDateTime);

PMCA_EXTERN PMCA_RETURN PmcaSetAbsolutePeakMode(void);
PMCA_EXTERN PMCA_RETURN PmcaSetFirstPeakMode(void);
PMCA_EXTERN PMCA_RETURN PmcaSelectRealTimer(void);
PMCA_EXTERN PMCA_RETURN PmcaSelectLiveTimer(void);
PMCA_EXTERN PMCA_RETURN PmcaClearData(void);
PMCA_EXTERN PMCA_RETURN PmcaClearTime(void);
PMCA_EXTERN PMCA_RETURN PmcaClearDataAndTime(void);
PMCA_EXTERN PMCA_RETURN PmcaStartAcquisition(int setStartTime);
PMCA_EXTERN PMCA_RETURN PmcaStopAcquisition(void);
PMCA_EXTERN PMCA_RETURN PmcaSetGroup(int group);
PMCA_EXTERN PMCA_RETURN PmcaSetGain(int gain);
PMCA_EXTERN PMCA_RETURN PmcaSetTime(char *strTime);
PMCA_EXTERN PMCA_RETURN PmcaSetDate(char *strDate);
PMCA_EXTERN PMCA_RETURN PmcaSetLock(int lock);
PMCA_EXTERN PMCA_RETURN PmcaSetBatteryType(
        PmcaBatteryType batteryType);
PMCA_EXTERN PMCA_RETURN PmcaSetAcquisitionTime(int time);
PMCA_EXTERN PMCA_RETURN PmcaSetThreshold(short threshold);

// Asynchronous functions

PMCA_EXTERN PMCA_RETURN PmcaAsyncPowerUp(int *result,
        int port, int baudRate, PmcaDeviceType device);
PMCA_EXTERN PMCA_RETURN PmcaAsyncConnect(int *result,
        int port, int baudRate, PmcaDeviceType device);
PMCA_EXTERN PMCA_RETURN PmcaAsyncDisconnect(int *result);

PMCA_EXTERN PMCA_RETURN PmcaAsyncGetSerialNumber(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetBatteryType(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetBatteryCondition(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetBatteryCapacity(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetGroup(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetThreshold(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetGain(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetRealTime(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetLiveTime(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetFlags(int *result,
        PmcaFlagsType *flags);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetStatus(
        int *result, PmcaStatusType *buffer);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetData(int *result,
        unsigned long *buffer, int channel, int dwordCount);
PMCA_EXTERN PMCA_RETURN PmcaAsyncGetDateAndTime(
        int *result, char *strDateTime);

PMCA_EXTERN PMCA_RETURN PmcaAsyncSetAbsolutePeakMode(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetFirstPeakMode(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSelectRealTimer(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSelectLiveTimer(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncClearData(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncClearTime(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncClearDataAndTime(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncStartAcquisition(
        int *result, int setStartTime);
PMCA_EXTERN PMCA_RETURN PmcaAsyncStopAcquisition(int *result);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetGroup(int *result, int group);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetGain(int *result, int gain);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetTime(int *result, char *time);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetDate(int *result, char *date);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetLock(int *result, int lock);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetBatteryType(int *result,
        PmcaBatteryType batteryType);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetAcquisitionTime(int *result,
        int time);
PMCA_EXTERN PMCA_RETURN PmcaAsyncSetThreshold(int *result,
        short threshold);

#endif // !defined(AFX_PMCACOM_H__F277DC42_F1AE_11D1_B630_9CFF0CC10000__INCLUDED_)
