library AIOENet;

{$R *.res}

uses
	System.SysUtils, System.Classes,
	DNS in 'DNS.pas',
	MDNS in 'MDNS.pas',
	DNSSD in 'DNSSD.pas',
	DClientSocks in 'DClientSocks.pas',
	CoreDataMessages in 'CoreDataMessages.pas',
	ENetDataItems in 'ENetDataItems.pas',
	Core in 'Core.pas',
	CoreExports in 'CoreExports.pas',
	DIOExports in 'DIOExports.pas',
	DACExports in 'DACExports.pas',
	ADCExports in 'ADCExports.pas';



//System(nil) functions.
function VBConnectA(Host: TPAnsiChar; Index: TSInt32): TClientRef; stdcall;
begin
	Result := ConnectA(Host, Index);
end;

function VBConnectW(Host: TPWideChar; Index: TSInt32): TClientRef; stdcall;
begin
	Result := ConnectW(Host, Index);
end;

function VBConnectU(Host: TPUCS4Char; Index: TSInt32): TClientRef; stdcall;
begin
	Result := ConnectU(Host, Index);
end;

function VBDisconnect(uClientRef: TClientRef): LongWord; stdcall;
begin
	Result := Disconnect(uClientRef);
end;

function VBSetTimeout(uClientRef: TClientRef; TimeoutMS: TSInt32): LongWord; stdcall;
begin
	Result := SetTimeout(uClientRef, TimeoutMS);
end;

function VBChangeDeviceHostnameA(uClientRef: TClientRef; NewHostname: TPAnsiChar): TWinErrCode; stdcall;
begin
	Result := ChangeDeviceHostnameA(uClientRef, NewHostname);
end;

function VBChangeDeviceHostnameW(uClientRef: TClientRef; NewHostname: TPWideChar): TWinErrCode; stdcall;
begin
	Result := ChangeDeviceHostnameW(uClientRef, NewHostname);
end;

function VBChangeDeviceHostnameU(uClientRef: TClientRef; NewHostname: TPUCS4Char): TWinErrCode; stdcall;
begin
	Result := ChangeDeviceHostnameU(uClientRef, NewHostname);
end;

{
function VBChangeNetworkingA(uClientRef: Pointer; NewIP, NewSubnet, NewGateway: PAnsiChar): LongWord; stdcall;
begin
	Result := ChangeNetworkingA(uClientRef, NewIP, NewSubnet, NewGateway);
end;

function VBChangeNetworkingW(uClientRef: Pointer; NewIP, NewSubnet, NewGateway: PWideChar): LongWord; stdcall;
begin
	Result := ChangeNetworkingW(uClientRef, NewIP, NewSubnet, NewGateway);
end;

function VBChangeNetworkingU(uClientRef: Pointer; NewIP, NewSubnet, NewGateway: PUCS4Char): LongWord; stdcall;
begin
	Result := ChangeNetworkingU(uClientRef, NewIP, NewSubnet, NewGateway);
end;
}

function VBScanForDevicesA(NameListSizeAvailable: TUInt32; pNameList: TPAnsiChar; out NameListSize: TUInt32): TWinErrCode; stdcall;
begin
	Result := ScanForDevicesA(NameListSizeAvailable, pNameList, NameListSize);
end;

function VBScanForDevicesW(NameListSizeAvailable: TUInt32; pNameList: TPWideChar; out NameListSize: TUInt32): TWinErrCode; stdcall;
begin
	Result := ScanForDevicesW(NameListSizeAvailable, pNameList, NameListSize);
end;

function VBScanForDevicesU(NameListSizeAvailable: TUInt32; pNameList: TPUCS4Char; out NameListSize: TUInt32): TWinErrCode; stdcall;
begin
	Result := ScanForDevicesU(NameListSizeAvailable, pNameList, NameListSize);
end;

{
function VBAEW_DetectDeviceIPsA(Flags: LongWord; Milliseconds: Double; pIntoBuf: PAnsiChar; BufSize: LongWord; pNeededBufSize: PLongWord): LongWord; stdcall;
begin
	Result := AEW_DetectDeviceIPsA(Flags, Milliseconds, pIntoBuf, BufSize, pNeededBufSize);
end;

function VBAEW_UploadFirmwareFileA(uClientRef: Pointer; pFirmwareFilePath: PAnsiChar): LongWord; stdcall;
begin
	Result := AEW_UploadFirmwareFileA(uClientRef, pFirmwareFilePath);
end;
}

function VBGetDeviceFeatures(uClientRef: TClientRef; FeatureBytes: TUInt32; pFeatures: TPUInt8): TWinErrCode; stdcall;
begin
	Result := GetDeviceFeatures(uClientRef, FeatureBytes, pFeatures);
end;



//DIO functions.
function VBDIO_Configure(uClientRef: TClientRef; pDataBytes: TPUInt32; pData: TPUInt8; pDirection: TPUInt8): LongWord; stdcall;
begin
	Result := DIO_Configure(uClientRef, pDataBytes, pData, pDirection);
end;

function VBDIO_ReadDirection(uClientRef: TClientRef; pDataBytes: TPUInt32; pData: TPUInt8): TWinErrCode; stdcall;
begin
	Result := DIO_ReadDirection(uClientRef, pDataBytes, pData);
end;

function VBDIO_WriteAll(uClientRef: TClientRef; pDataBytes: TPUInt32; pData: TPUInt8): LongWord; stdcall;
begin
	Result := DIO_WriteAll(uClientRef, pDataBytes, pData);
end;

function VBDIO_ReadAll(uClientRef: TClientRef; pDataBytes: TPUInt32; pData: TPUInt8): LongWord; stdcall;
begin
	Result := DIO_ReadAll(uClientRef, pDataBytes, pData);
end;



//D/A(DAC) functions.
function VBDAC_GetRange(uClientRef: TClientRef; Ch: TChannelIndex; pRange: TPRangeCode = nil; pLowV: TPDouble = nil; pHighV: TPDouble = nil): TWinErrCode; stdcall;
begin
	Result := DAC_GetRange(uClientRef, Ch, pRange, pLowV, pHighV);
end;

function VBDAC_Enable(uClientRef: TClientRef): TWinErrCode; stdcall;
begin
	Result := DAC_Enable(uClientRef);
end;

function VBDAC_Disable(uClientRef: TClientRef): TWinErrCode; stdcall;
begin
	Result := DAC_Disable(uClientRef);
end;

function VBDAC_OutputCounts(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; Counts: TUInt16): TWinErrCode; stdcall;
begin
	Result := DAC_OutputCounts(uClientRef, Ch, Counts);
end;

function VBDAC_OutputFrac(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; Frac: TDouble): TWinErrCode; stdcall;
begin
	Result := DAC_OutputFrac(uClientRef, Ch, Frac);
end;

function VBDAC_OutputNCounts(uClientRef: TClientRef; Channels: TUInt32; pCounts: TPUInt16): TWinErrCode; stdcall;
begin
	Result := DAC_OutputNCounts(uClientRef, Channels, pCounts);
end;

function VBDAC_OutputNFrac(uClientRef: TClientRef; Channels: TUInt32; pFrac: TPDouble): TWinErrCode; stdcall;
begin
	Result := DAC_OutputNFrac(uClientRef, Channels, pFrac);
end;

function VBDAC_OutputNV(uClientRef: TClientRef; Channels: TUInt32; pV: TPDouble): TWinErrCode; stdcall;
begin
	Result := DAC_OutputNV(uClientRef, Channels, pV);
end;

function VBDAC_SetChCal(uClientRef: TClientRef; Ch: TChannelIndex; ScaleFactor: TDouble = 1; OffsetCounts: TDouble = 0): TWinErrCode; stdcall;
begin
	Result := DAC_SetChCal(uClientRef, Ch, ScaleFactor, OffsetCounts);
end;

function VBDAC_SetAllCal(uClientRef: TClientRef; pScaleFactor: TPDouble = nil; pOffsetCounts: TPDouble = nil): TWinErrCode; stdcall;
begin
	Result := DAC_SetAllCal(uClientRef, pScaleFactor, pOffsetCounts);
end;

function VBDAC_RecordRange(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; RangeCode: TRangeCode): TWinErrCode; stdcall;
begin
	Result := DAC_RecordRange(uClientRef, Ch, RangeCode);
end;

(*
function VBDAC_Configure(uClientRef: TClientRef; RangeCt: TUInt32; pRange: TPRangeCode): TWinErrCode; stdcall;
begin
	Result := DAC_Configure(uClientRef, RangeCt, pRange);
end;
*)

function VBDAC_OutputV(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; V: TDouble): TWinErrCode; stdcall;
begin
	Result := DAC_OutputV(uClientRef, Ch, V);
end;



//A/D(ADC) functions.
function VBADC_Reset(uClientRef: TClientRef): TWinErrCode; stdcall;
begin
	Result := ADC_Reset(uClientRef);
end;

function VBADC_SetRate(uClientRef: TClientRef; Rate: TDouble): TWinErrCode; stdcall;
begin
	Result := ADC_SetRate(uClientRef, Rate);
end;

function VBADC_GetRate(uClientRef: TClientRef; out Rate: TDouble): TWinErrCode; stdcall;
begin
	Result := ADC_GetRate(uClientRef, Rate);
end;

function VBADC_SetRange(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; RangeCode: TRangeCode): TWinErrCode; stdcall;
begin
	Result := ADC_SetRange(uClientRef, Ch, RangeCode);
end;

function VBADC_SetDifferential(uClientRef: TClientRef; Ch: TChannelIndex {= ciAll}; bDifferential: ByteBool): TWinErrCode; stdcall;
begin
	Result := ADC_SetDifferential(uClientRef, Ch, bDifferential);
end;

function VBADC_SetChScan(uClientRef: TClientRef; FirstCh, LastCh: TChannelIndex): TWinErrCode; stdcall;
begin
	Result := ADC_SetChScan(uClientRef, FirstCh, LastCh);
end;

function VBADC_SetOversample(uClientRef: TClientRef; Oversample: TUInt32): TWinErrCode; stdcall;
begin
	Result := ADC_SetOversample(uClientRef, Oversample);
end;

function VBADC_SetCalMode(uClientRef: TClientRef; CalMode: TCalMode): TWinErrCode; stdcall;
begin
	Result := ADC_SetCalMode(uClientRef, CalMode);
end;

function VBADC_SetRangeCal(uClientRef: TClientRef; RangeCode: TRangeCode; ScaleFactor: TDouble = 1; OffsetCounts: TDouble = 0): TWinErrCode; stdcall;
begin
	Result := ADC_SetRangeCal(uClientRef, RangeCode, ScaleFactor, OffsetCounts);
end;

function VBADC_AcquireBegin(uClientRef: TClientRef; BufDataCt: TUInt32): TWinErrCode; stdcall;
begin
	Result := ADC_AcquireBegin(uClientRef, BufDataCt);
end;

function VBADC_AcquireEnd(uClientRef: TClientRef): TWinErrCode; stdcall;
begin
	Result := ADC_AcquireEnd(uClientRef);
end;

function VBADC_AcquireGetDataPtr(uClientRef: TClientRef): TPUInt8; stdcall;
begin
	Result := ADC_AcquireGetDataPtr(uClientRef);
end;

function VBADC_AcquireGetDataV(uClientRef: TClientRef; pDataSamples: TPUInt32; pData: TPDouble = nil; pStatus: TPUInt16 = nil; pTimestamp: TPUInt16 = nil): TWinErrCode; stdcall;
begin
	Result := ADC_AcquireGetDataV(uClientRef, pDataSamples, pData, pStatus, pTimestamp);
end;

function VBADC_AcquireGetDataRaw(uClientRef: TClientRef; pDataSamples: TPUInt32; pDataRaw: TPUInt32 = nil): TWinErrCode; stdcall;
begin
	Result := ADC_AcquireGetDataRaw(uClientRef, pDataSamples, pDataRaw);
end;

function VBADC_ImmediateGetScanV(uClientRef: TClientRef; pData: TPDouble = nil; pStatus: TPUInt16 = nil; pTimestamp: TPUInt16 = nil): TWinErrCode; stdcall;
begin
	Result := ADC_ImmediateGetScanV(uClientRef, pData, pStatus, pTimestamp);
end;

function VBADC_ImmediateGetScanRaw(uClientRef: TClientRef; pDataRaw: TPUInt32): TWinErrCode; stdcall;
begin
	Result := ADC_ImmediateGetScanRaw(uClientRef, pDataRaw);
end;

function VBADC_ImmediateGetSampleV(uClientRef: TClientRef; Ch: TChannelIndex; pData: TPDouble = nil; pStatus: TPUInt16 = nil; pTimestamp: TPUInt16 = nil): TWinErrCode; stdcall;
begin
	Result := ADC_ImmediateGetSampleV(uClientRef, Ch, pData, pStatus, pTimestamp);
end;

function VBADC_ImmediateGetSampleRaw(uClientRef: TClientRef; Ch: TChannelIndex; pDataRaw: TPUInt32): TWinErrCode; stdcall;
begin
	Result := ADC_ImmediateGetSampleRaw(uClientRef, Ch, pDataRaw);
end;



//Debug(Deb) functions.
function VBDeb_SendReceiveDI(uClientRef: TClientRef; SendDID: TUInt16; SendPayloadBytes: TUInt32; pSendPayload: TPUInt8; pReceiveDID: TPUInt16; pReceivePayloadBytes: TPUInt32; pReceivePayload: TPUInt8): TWinErrCode; stdcall;
begin
	Result := Deb_SendReceiveDI(uClientRef, SendDID, SendPayloadBytes, pSendPayload, pReceiveDID, pReceivePayloadBytes, pReceivePayload);
end;

{
function VBDeb_StrToStrA(uClientRef: Pointer; pSendPacketChars: PLongInt; pSendPacket: PAnsiChar; pReplyPacketChars: PLongInt; pReplyPacket: PAnsiChar): LongWord; stdcall;
begin
	Result := Deb_StrToStrA(uClientRef, pSendPacketChars, pSendPacket, pReplyPacketChars, pReplyPacket);
end;

function VBDeb_StrToStrW(uClientRef: Pointer; pSendPacketChars: PLongInt; pSendPacket: PWideChar; pReplyPacketChars: PLongInt; pReplyPacket: PWideChar): LongWord; stdcall;
begin
	Result := Deb_StrToStrW(uClientRef, pSendPacketChars, pSendPacket, pReplyPacketChars, pReplyPacket);
end;

function VBDeb_StrToStrU(uClientRef: Pointer; pSendPacketChars: PLongInt; pSendPacket: PUCS4Char; pReplyPacketChars: PLongInt; pReplyPacket: PUCS4Char): LongWord; stdcall;
begin
	Result := Deb_StrToStrU(uClientRef, pSendPacketChars, pSendPacket, pReplyPacketChars, pReplyPacket);
end;
}

function VBDeb_LogEnable: LongBool; stdcall;
begin
	Result := Deb_LogEnable;
end;





exports
  VBADC_AcquireGetDataPtr, ADC_AcquireGetDataPtr name '_ADC_AcquireGetDataPtr', ADC_AcquireGetDataPtr,



  VBDAC_SetAllCal , DAC_SetAllCal name '_DAC_SetAllCal' , DAC_SetAllCal ,
  VBDAC_SetChCal  , DAC_SetChCal  name '_DAC_SetChCal'  , DAC_SetChCal  ,

  VBChangeDeviceHostnameA     , ChangeDeviceHostnameA     name '_ChangeDeviceHostnameA'     , ChangeDeviceHostnameA     ,
  VBChangeDeviceHostnameW     , ChangeDeviceHostnameW     name '_ChangeDeviceHostnameW'     , ChangeDeviceHostnameW     ,
  VBChangeDeviceHostnameU     , ChangeDeviceHostnameU     name '_ChangeDeviceHostnameU'     , ChangeDeviceHostnameU     ,

  VBScanForDevicesU           , ScanForDevicesU           name '_ScanForDevicesU'           , ScanForDevicesU           ,
  VBScanForDevicesW           , ScanForDevicesW           name '_ScanForDevicesW'           , ScanForDevicesW           ,
  VBScanForDevicesA           , ScanForDevicesA           name '_ScanForDevicesA'           , ScanForDevicesA           ,

  VBDAC_OutputNCounts         , DAC_OutputNCounts         name '_DAC_OutputNCounts'         , DAC_OutputNCounts         ,
  VBDAC_OutputNFrac           , DAC_OutputNFrac           name '_DAC_OutputNFrac'           , DAC_OutputNFrac           ,
  VBDAC_OutputNV              , DAC_OutputNV              name '_DAC_OutputNV'              , DAC_OutputNV              ,

  VBDeb_SendReceiveDI         , Deb_SendReceiveDI         name '_Deb_SendReceiveDI'         , Deb_SendReceiveDI         ,

  VBDAC_RecordRange           , DAC_RecordRange           name '_DAC_RecordRange'           , DAC_RecordRange           ,

  VBGetDeviceFeatures         , GetDeviceFeatures         name '_GetDeviceFeatures'         , GetDeviceFeatures         ,
  VBADC_SetOversample         , ADC_SetOversample         name '_ADC_SetOversample'         , ADC_SetOversample         ,
  VBADC_SetDifferential       , ADC_SetDifferential       name '_ADC_SetDifferential'       , ADC_SetDifferential       ,
  VBADC_SetCalMode            , ADC_SetCalMode            name '_ADC_SetCalMode'            , ADC_SetCalMode            ,
  VBADC_SetRangeCal           , ADC_SetRangeCal           name '_ADC_SetRangeCal'           , ADC_SetRangeCal           ,

  VBDAC_OutputV               , DAC_OutputV               name '_DAC_OutputV'               , DAC_OutputV               ,

  VBADC_AcquireGetDataRaw     , ADC_AcquireGetDataRaw     name '_ADC_AcquireGetDataRaw'     , ADC_AcquireGetDataRaw     ,
  VBADC_AcquireGetDataV       , ADC_AcquireGetDataV       name '_ADC_AcquireGetDataV'       , ADC_AcquireGetDataV       ,
  VBADC_AcquireEnd            , ADC_AcquireEnd            name '_ADC_AcquireEnd'            , ADC_AcquireEnd            ,
  VBADC_AcquireBegin          , ADC_AcquireBegin          name '_ADC_AcquireBegin'          , ADC_AcquireBegin          ,
  VBADC_GetRate               , ADC_GetRate               name '_ADC_GetRate'               , ADC_GetRate               ,
  VBADC_SetRate               , ADC_SetRate               name '_ADC_SetRate'               , ADC_SetRate               ,

  VBADC_ImmediateGetScanV     , ADC_ImmediateGetScanV     name '_ADC_ImmediateGetScanV'     , ADC_ImmediateGetScanV     ,
  VBADC_ImmediateGetScanRaw   , ADC_ImmediateGetScanRaw   name '_ADC_ImmediateGetScanRaw'   , ADC_ImmediateGetScanRaw   ,
  VBADC_ImmediateGetSampleV   , ADC_ImmediateGetSampleV   name '_ADC_ImmediateGetSampleV'   , ADC_ImmediateGetSampleV   ,
  VBADC_ImmediateGetSampleRaw , ADC_ImmediateGetSampleRaw name '_ADC_ImmediateGetSampleRaw' , ADC_ImmediateGetSampleRaw ,
  VBADC_SetRange              , ADC_SetRange              name '_ADC_SetRange'              , ADC_SetRange              ,
  VBADC_SetChScan             , ADC_SetChScan             name '_ADC_SetChScan'             , ADC_SetChScan             ,
  VBADC_Reset                 , ADC_Reset                 name '_ADC_Reset'                 , ADC_Reset                 ,

  VBDeb_LogEnable             , Deb_LogEnable             name '_Deb_LogEnable'             , Deb_LogEnable             ,

  {
  VBDeb_StrToStrU             , Deb_StrToStrU             name '_Deb_StrToStrU'             , Deb_StrToStrU             ,
  VBDeb_StrToStrW             , Deb_StrToStrW             name '_Deb_StrToStrW'             , Deb_StrToStrW             ,
  VBDeb_StrToStrA             , Deb_StrToStrA             name '_Deb_StrToStrA'             , Deb_StrToStrA             ,
  VBDeb_StrToStrA name 'VBDeb_StrToStr' , Deb_StrToStrA   name '_Deb_StrToStr'       , Deb_StrToStrA name 'Deb_StrToStr',
  }

  VBDAC_OutputFrac            , DAC_OutputFrac            name '_DAC_OutputFrac'            , DAC_OutputFrac            ,
  VBDAC_OutputCounts          , DAC_OutputCounts          name '_DAC_OutputCounts'          , DAC_OutputCounts          ,
  VBDAC_Disable               , DAC_Disable               name '_DAC_Disable'               , DAC_Disable               ,
  VBDAC_Enable                , DAC_Enable                name '_DAC_Enable'                , DAC_Enable                ,
  VBDAC_GetRange              , DAC_GetRange              name '_DAC_GetRange'              , DAC_GetRange              ,

  VBDIO_ReadAll               , DIO_ReadAll               name '_DIO_ReadAll'               , DIO_ReadAll               ,
  VBDIO_WriteAll              , DIO_WriteAll              name '_DIO_WriteAll'              , DIO_WriteAll              ,
  VBDIO_ReadDirection         , DIO_ReadDirection         name '_DIO_ReadDirection'         , DIO_ReadDirection         ,
  VBDIO_Configure             , DIO_Configure             name '_DIO_Configure'             , DIO_Configure             ,

  VBSetTimeout                , SetTimeout                name '_SetTimeout'                , SetTimeout                ,
  VBDisconnect                , Disconnect                name '_Disconnect'                , Disconnect                ,

  VBConnectU                  , ConnectU                  name '_ConnectU'                  , ConnectU                  ,
  VBConnectW                  , ConnectW                  name '_ConnectW'                  , ConnectW                  ,
  VBConnectA                  , ConnectA                  name '_ConnectA'                  , ConnectA                  ,
  VBConnectA name 'VBConnect' , ConnectA                  name '_Connect'                   , ConnectA name 'Connect'   ;

begin
end.
