unit lc4hs;
interface
uses
  Windows;

const
  LC4HS_MAX_CARDS                       = 32;

{ private error codes returned by GetLastError if LCICOpen fails}
  LC4HS_ERR_CHECK_STRING_NOT_FOUND	= $E0000101;
  LC4HS_ERR_TRANSMIT_FAILED		= $E0000102;
  LC4HS_ERR_RAM_ERROR			= $E0000103;
  LC4HS_ERR_A2D_ERROR			= $E0000104;
  LC4HS_ERR_X244_ERROR			= $E0000105;
  LC4HS_ERR_NEED_CAL_AND_PARAMS		= $E0000106;
  LC4HS_ERR_NORESPONSE_FLAG		= $E0000107;
  LC4HS_ERR_NORESPONSE_STATUS		= $E0000108;

  LC4HS_ERR_ALREADY_STARTED		= $E0000109; // returned by Init
  LC4HS_ERR_ALREADY_STOPPED		= $E000010A; // returned by Finish
  LC4HS_ERR_NOT_READY			= $E000010B; // returned by Poll functions if card not ready
  LC4HS_ERR_READ_TIMEOUT		= $E000010C; // returned by Get functions if card does not respond
  LC4HS_ERR_NOT_STARTED                 = $E000010D;
  LC4HS_ERR_DIGITAL_OUTPUT_WRITE	= $E0000110; //Problem with digital output reg.
  LC4HS_ERR_INVALID_CHANNEL		= $E0000111; //returned by GetZeroAD, + Poll/Read functions


  LC4HS_DETECT_CONFIGURED = $1;		//successfully configured card at this address
  LC4HS_DETECT_RESOURCE_CONFLICT = $2;     //memory belongs to another device
  LC4HS_DETECT_NOT_FOUND = $3;	        //slot is available, but empty
  LC4HS_DETECT_NEW_CARD = $4;	        //there is a card here, but it is not configured

type
  DWORD4 = array[0..3] of DWORD;
  BOOL4 = array[0..3] of BOOL;           //This is a windows BOOL - 32 bit
  FLOAT4 = array[0..3] of Single;
  TIOSet = set of 0..31;                //VB must have 32 bit params

function Lc4hsSetup(hWnd: HWND; DeviceName: LPSTR; CheckAddress: BOOL): BOOL; stdcall;
{	This function opens the configuration dialog for the device
	named by DeviceName e.g 'LC4HS1', 'LC4HS2', 'LC4HS3' etc..
	hWnd is the dialogs parent window (may be NULL). Returns
	true if configuration changed (user clicks OK) else FALSE.
	Use this function to edit config data stored in the registry.
}

function Lc4hsOpen(DeviceName: LPSTR): THandle; stdcall;
{	DeviceName = 'LC4HS1', 'LC4HS2', 'LC4HS3' etc..
	Returns File handle for subsequent use as 'Card' parameter
	to other API functions. Returns INVALID_FILE_HANDLE if
	fails. Call GetLastError for more info
}

{	For the following functions the Card parameter is a file handle
	returned by a successful call to Lc4hsOpen.

	Return Values:
	All the following functions return TRUE if the call proceeds without an
	error, otherwise FALSE. If the call returns FALSE then call GetLastError 
	for an extended error code.
}

function Lc4hsInit(Card: THandle): BOOL; stdcall;
{	Initialises card. Returns TRUE if OK otherwise FALSE.
	Call GetLastError for error information. This function
	will return TRUE and do nothing if card already initialised.
}

function Lc4hsFinish(Card: THandle): BOOL; stdcall;
{    Finalises card. Does nothing if card not initialised.
}

function Lc4hsGetCardStatus(Card: THandle; var CardStatus: BOOL): BOOL; stdcall;
{	CardStatus points to single BOOL. Set TRUE if card initialised,
	otherwise FALSE.
}

function Lc4hsGetCardVersion(Card: THandle; var CardVersion: DWORD): BOOL; stdcall;
{	CardVersion points to single DWORD which receives card version number.
}

function Lc4hsGetChannelStatus4(Card: THandle; var Status: BOOL4): BOOL; stdcall;

function Lc4hsGetChannelStatus(Card: THandle; Channel: DWORD; var Status: BOOL4): BOOL; stdcall;
{	Status points to array of 4 BOOL.
	Sets the value of Status[N] TRUE if channel N is calibrated, otherwise
	FALSE
}

function Lc4hsGetZeroAD4(Card: THandle; var ZeroAD: DWORD4): BOOL; stdcall;

function Lc4hsGetZeroAD(Card: THandle; Channel: DWORD; var ZeroAD: DWORD4): BOOL; stdcall;
{	ZeroAD points to array of 4 USHORTs
}

function Lc4hsGetCurrentWeight4(Card: THandle; var CurrentWeight: FLOAT4): BOOL; stdcall;

function Lc4hsGetCurrentWeight(Card: THandle; Channel: DWORD; var CurrentWeight: FLOAT4): BOOL; stdcall;
{	This function requests an A/D update from the card then waits for the
	result. The current weight value for all four channels is returned via
	the CurrentWeight parameter which must point to array of 4 FLOAT
}

function Lc4hsPollCurrentWeight4(Card: THandle; var CurrentWeight: FLOAT4): BOOL; stdcall;

function Lc4hsPollCurrentWeight(Card: THandle; Channel: DWORD; var CurrentWeight: FLOAT4): BOOL; stdcall;
{	This function reads the current weight value from the card without first
	requesting an A/D update. The function then requests an update and returns
	immediately without waiting. Data for all four channels is returned via the
	CurrentWeight parameter which must point to array of 4 FLOAT
}

function Lc4hsGetCurrentAD4(Card: THandle; var CurrentAD: DWORD4): BOOL; stdcall;

function Lc4hsGetCurrentAD(Card: THandle; Channel: DWORD; var CurrentAD: DWORD4): BOOL; stdcall;
{	This function requests an A/D update from the card then waits for the
	result. The A/D value for all four channels is returned via the CurrentAD
	parameter which must point to array of 4 WORD
}

function Lc4hsPollCurrentAD4(Card: THandle; var CurrentAD: DWORD4): BOOL; stdcall;

function Lc4hsPollCurrentAD(Card: THandle; Channel: DWORD; var CurrentAD: DWORD4): BOOL; stdcall;
{	This function reads the current weight value from the card without first
	requesting an A/D update. The function then requests an update and returns
	immediately without waiting. The A/D value for all four channels is
	returned via the CurrentAD parameter which must point to array of 4 WORD
}

function Lc4hsGetDigitalOutput(Card: THandle; BitNo: DWORD; var Value: BOOL): BOOL; stdcall;
{       Value points to a single BOOL which is set true if bit number BitNo is set in
	the digital output register.}

function Lc4hsSetDigitalOutput(Card: THandle; BitNo: DWORD; Value: BOOL): BOOL; stdcall;
{	Bit number BitNo is switched ON if Value is TRUE otherwise switched OFF.
}

function Lc4hsGetDigitalInput(Card: THandle; BitNo: DWORD; var Value: BOOL): BOOL; stdcall;
{	Value points to a single BOOL which is set true if bit number BitNo is set in
	the digital input register.
}

function Lc4hsReadIO(Card: THandle; var IOData: TIOSet): BOOL; stdcall;
{  Use this function to read the state of all outputs and inputs at once.
	Low Byte of IOData contains outputs, High byte contains inputs
}


function Lc4hsGetErrorMsg(Code: DWORD; lpBuffer: LPSTR; nSize: DWORD): BOOL; stdcall;
{       Converts an LCIC specific error code (returned by GetLastError) into a string
	Returns TRUE if code recognised, otherwise FALSE. If this function returns
	FALSE then this might be a standard Windows Error Code. See FormatMessage
}

implementation
const
  DLLName = 'Lc4hs.dll';

function Lc4hsSetup; external DLLName;
function Lc4hsOpen; external DLLName;
function Lc4hsInit; external DLLName;
function Lc4hsFinish; external DLLName;
function Lc4hsGetCardStatus; external DLLName;
function Lc4hsGetCardVersion; external DLLName;
function Lc4hsGetChannelStatus4; external DLLName;
function Lc4hsGetChannelStatus; external DLLName;
function Lc4hsGetZeroAD4; external DLLName;
function Lc4hsGetZeroAD; external DLLName;
function Lc4hsGetCurrentWeight4; external DLLName;
function Lc4hsGetCurrentWeight; external DLLName;
function Lc4hsPollCurrentWeight4; external DLLName;
function Lc4hsPollCurrentWeight; external DLLName;
function Lc4hsGetCurrentAD4; external DLLName;
function Lc4hsGetCurrentAD; external DLLName;
function Lc4hsPollCurrentAD4; external DLLName;
function Lc4hsPollCurrentAD; external DLLName;
function Lc4hsGetDigitalOutput; external DLLName;
function Lc4hsSetDigitalOutput; external DLLName;
function Lc4hsGetDigitalInput; external DLLName;
function Lc4hsReadIO; external DLLName;
function Lc4hsGetErrorMsg; external DLLName;
end.
