Explaination for DLL Funtions
-----------------------------------------------------------------
Function PortOpen(cPort:Integer):Integer;

cPort:		specifies the COM port. 

Open the serial communication port cPort number.

Returns

Returns 1, if successful. Otherwise returns 0. 

Comments


-----------------------------------------------------------------
Function PortClose:Integer;

Close the serial communication port.

Returns

Returns 1, if successful.  Otherwise returns 0.  Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

------------------------------------------------------------------
Function PortConfigure(cPort:Integer;cBaud:LongInt):Integer;

The PortConfigure function Configure the serial communication port.

Parameters

cPort:		specifies the COM port. 
		cPort=0 for COM0, 1 for COM1 and so on.
cBaud:		specifies the baud rate. 
		cBaud=9600 for 9600 baud rate, and so on.

Returns 

Returns 1, if successful. Otherwise returns 0.  Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

------------------------------------------------------------------
Function ItcGetPort:Integer;

This function returns the current serial communication port number.

Returns

Returns 0 for COM0, Returns 1 for COM1 and so on.

------------------------------------------------------------------
Function ItcGetBaudRate:LongInt;

This function returns the current Baud Rates.

Returns

Returns 9600 for 9600 baud rates, return 19200 for 19200 baud rates and so on.

------------------------------------------------------------------
Function ItcChangeBaudRate(NewSpeed:Longint):Integer;

This function change the baud rate of both the serial port of PC and the serial port of ITC-232A.

Parameters

NewSpeed:	specifies the new baud rate required. 
		e.g. NewSpeed = 9600.

Returns 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

------------------------------------------------------------------
Function ItcCommand(Order:string):Integer;

The ItcCommand function sends ITC-232A command set to ITC-232A chip.

Parameters

Order:	specifies the command sending to the ITC-232A chip. 
	e.g. 'pra'.

Returns 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.   The message returned from ITC-232A can be obtained by calling ItcGetValue.

Comments

For Visual Basic and C/C++ user, use the alternative function ItcCommandvb.

------------------------------------------------------------------
Function ItcCommandvb(Order:PChar):Integer;

This function sends ITC-232A command set to ITC-232A chip.

Parameters

Order	specifies the command sending to the ITC-232A chip. 
	e.g. 'pra'.

Returns 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage (or ItcGetErrorMessagevb for VB user).   The message returned from ITC-232A can be obtained by calling ItcGetValue.

------------------------------------------------------------------
Function ItcGetValue:LongInt;

The ItcGetValue function returns the message sent back from ITC-232A.

------------------------------------------------------------------ 
Function ItcGetError:Integer;

This function returns the error code when it is fail to call the functions. The Error Code is as follows:
    1 = ITC232-A reports error: Syntax error
    2 = ITC232-A reports error: Port must be configured or enabled first
    3 = ITC232-A reports error: Command not allowed in current configuration
    4 = ITC232-A reports error: No such port
    5 = ITC232-A reports error: Value out of range or syntax error
    6 = ITC232-A reports error: Pin configured as an output
    7 = ITC232-A reports error: Time out error
    8 = ITC232-A reports error: Frequency too high for required duty cycle
    9 = ITC232-A reports error: Baud rate not supported
   10 = ITC232-A reports error: Port D is always a 4 bit input port
   11 = ITC232-A reports error: SPI requires pin PD3/PS_VDD always high, change and try again
   20 = COM port not supported
   21 = COM port not found
   22 = Baud rate not supported
   23 = Attempt to close a COM port which is not open
   24 = The COM port returned more than 255 characters
   25 = Commands cannot be sent before a COM port is open
   26 = COM port timed out
   27 = COM port already open
   28 = A/D converter resolution is not supported
   29 = Returned value out of range
   30 = I/O-485 address out of range (0..31)
   31 = I/O-485 IC out of range (0, 1 or 3 {or BROAD})
   32 = I/O-485 Broadcast parameter must be 1 or 0

   40 = Motor Control Chip is NOT Ready
   41 = Can not Write to Motor Control Chip
   42 = Speed out of range
   43 = Motor Abortion Fail
------------------------------------------------------------------
Function ItcGetErrorMessage:pchar;

This function returns the error message when it is fail to call the functions.  The alternative function for Visual Basic user is ItcGetErrorMessagevb.

------------------------------------------------------------------
Function ItcIntStatusH:Integer;

This function returns the status of the interrupt IRQH from ITC-232A, and also reset the status.

Returns

Returns 1 if the interrupt IRQH is caught.  Otherwise 0.

------------------------------------------------------------------
Function ItcIntStatusL:Integer;

This function returns the status of the interrupt IRQL from ITC-232A, and also reset the status.

Returns

Returns 1 if the interrupt IRQL is caught.  Otherwise 0.

------------------------------------------------------------------
Function ItcAnalog8(Channel:Integer):Integer;

This function forces the 8-bit ADC (MC145041) to convert a analog value. This value can be returned by the function ItcGetAnalogValue.

Parameters

Channel : Channel=0 for Channel 0; Channel=1 for Channel 1 and so on.
	  There are 10 Channels provided by the board.

Returns: 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------

Function ItcAnalog10(Channel:Integer):Integer;

This function forces the 10-bit ADC (MC145051 or TLC1543) to convert a analog value. This value can be returned by the function ItcGetAnalogValue.

Parameters

Channel : Channel=0 for Channel 0; Channel=1 for Channel 1 and so on.
	  There are 10 Channels provided by the board.

Returns: 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------
Function ItcAnalog12(Channel:Integer):Integer;

This function forces the 12-bit ADC (TLC2543) to convert a analog value. This value can be returned by the function ItcGetAnalogValue.

Parameters

Channel : Channel=0 for Channel 0; Channel=1 for Channel 1 and so on.
	  There are 10 Channels provided by the board.

Returns: 

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------
Function ItcResetADC:integer;

The function resets the ADC in the board.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------
Function ItcGetAnalogValue:LongInt;

The function returns the ADC converted value.

-----------------------------------------------------------------

Function ItcInitialize485:Integer;

Initialize the I/O-485 board.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------
Function ItcAddress485(Station,IC,Brcst:Integer):Integer;

This function is for selecting a ITC-232A chip specified by parameter 'IC',  in a I/O-485 board specified by parameter 'Station'. 

Parameters:

Station:		specifies station number from 0 to 31.
IC:		IC=1 for U1, IC=2 for U2
Brcst:		specifies broadcast mode.  
		Brcst=0 for non-broadcast mode. 
		Brcst=1 for broadcast mode.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

Comments:

For more detail about I/O-485, please refer to the manual of I/O-485.

-----------------------------------------------------------------

Function MotorInit:Integer;

This function initialize the ST4 board.  It configures the ITC-232A chip in the  ST4 Board, resets the Position Counter, resets all the CY-500 chips.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

------------------------------------------------------------------

function MotorNumberStep(WhichMotor:Integer;Number:LongInt):Integer;

This function sets the Number of steps the motor going to turn.

Parameters:

WhichMotor:  	specifies the motor to be configured.
		0:	Motor 1
		1:	Motor 2
		2: 	Motor 3
		3:	Motor 4
Number:		specifies the Number of Step range from 1 to 65536.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

-----------------------------------------------------------------

Function MotorSpeed(WhichMotor:Integer;Speed:double;AccStep:LongInt;CrysFreq:double):Integer;

This function configures the speed and the accerelation of the motor.

Parameters:

WhichMotor:	the same as the one in the function MotorNumberStep.
Speed: 		specifies the motor speed in Steps/Second.
AccStep:		specifies the number of steps within which the motor
 		finishes acceleration. 
		e.g. AccStep=50 means the Motor reaches the full speed
		specified by the parameter 'Speed' after 50 steps.
		If AccStep=1 or 0, then the motor is in non-acceleration
		mode.
CrysFreq:		specifies the frequency of the crystal for CY-500.
		It should be 6.0 for 6MHz crystal.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

Commends:

When AccStep>1, the motor is in acceleration mode.  To set back to non-acceleration mode, set AccStep to 1 instead of 0. 

-----------------------------------------------------------------
function MotorDirection(WhichMotor:integer;Cw:integer):Integer;

This function set the turning direction of the motor specified by WhichMotor parameter.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.
	Cw:	specifies the direction.
		 0: 	Counterclockwise
		 1: 	Clockwise.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

----------------------------------------------------------------
function MotorGo(WhichMotor:Integer):Integer;

This function turns the motor N steps.  N is specified by the MotorNumberStep function.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

Commends:

The motor will not turn if the trigger mask is zero, or the MotorPause function  is called.  If this is the case, call the MotorContinue function or set the trigger mask to one by calling the MotorTrigger function, to turn the motor.

----------------------------------------------------------------
function MotorJog(WhichMotor:Integer):Integer;

This function turns the motor infinite steps. 

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

----------------------------------------------------------------
function MotorStop(WhichMotor:Integer):Integer;

This function stops the motor, and set the position counter to 2147483647.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

----------------------------------------------------------------
function MotorPause(WhichMotor:Integer):Integer;

This function stops the motor temperately.  It is equivalent to set the trigger mask to zero.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

---------------------------------------------------------------
function MotorContinue(WhichMotor:Integer):Integer;

This function is oposite to the MotorPause function.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

---------------------------------------------------------------
function MotorPowerOn(WhichMotor:Integer):Integer;

This function turns on the motor power supply.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

--------------------------------------------------------------- 
function MotorPowerOff(WhichMotor:Integer):Integer;

This function turns off the motor power supply.  When the motor is turning, the power can not be turn off by this function.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

---------------------------------------------------------------
Function MotorGetHomeFlag(WhichMotor:Integer):Integer;

This function returns the Home Flag, set the Home Flag to zero, release the motor which is locked in the Home Position, and set the position counter to zero if the motor touched its Home button.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if the motor touched its Home Button.  Otherwise returns 0.

--------------------------------------------------------------
function MotorGetTrigMask: Integer;

This function returns the Trigger mask for the four motors.

Returns:

		Motor 4	Motor 3	Motor 2	Motor 1
	 0:	N-T	N-T	N-T	N-T
	 1:	N-T	N-T	N-T	T
	 2:	N-T	N-T	T	N-T
	 3:	N-T	N-T	T	T
	 4:	N-T	T	N-T	N-T
	 5:	N-T	T	N-T	T
	 6:	N-T	T	T	N-T
	 7:	N-T	T	T	T
	 8:	T	N-T	N-T	N-T
	 9:	T	N-T	N-T	T
	10:	T	N-T	T	N-T
	11:	T	N-T	T	T
	12:	T	T	N-T	N-T
	13:	T	T	N-T	T
	14:	T	T	T	N-T
	15:	T	T	T	T

where 'N-T' means the motor is not triggered and 'T' means the motor is triggered.  When the motor is not triggered, the motor will not turn while the MotorGo function is called.  This is equivalent to the MotorPause function.  When the motor is triggered, the motor will turn if the MotorGo function is called.  This is equivalent to the MotorContinue function.

-------------------------------------------------------------- 
function MotorGetReadyFlag(WhichMotor:Integer):Integer;

This function returns the motor ready flag.  When the motor is not ready, it will not accept any command.  When the motor is turning, the motor is not ready.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if the motor is ready to accept command.  Otherwise returns 0.

--------------------------------------------------------------
function MotorGetPosition(WhichMotor:integer):LongInt;

This function returns the value of the motor position counter.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

--------------------------------------------------------------
Function MotorCommand(WhichMotor:Integer;Cmd:String):Integer;

This function sends the motor commands to the motor.  For more details of 
the motor commands set, please refer to the CY-500 manual.  

Parameters:

WhichMotor:	the same as the one in the MotorNumberStep function.
       Cmd:		the motor command.   

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

Comments:

Almost all the functions with the prefix 'Motor' are the subset of this function.  Using this function, you can develop your own motor control functions by refer to the CY-500 manual. 

--------------------------------------------------------------
Function MotorTrigger(Motor1,Motor2,Motor3,Motor4:Integer):Integer;

This function set the trigger mask.

Parameters:

Motor1:		0:  Motor Not Triggered
		1:  Motor Triggered
Motor2:		0:  Motor Not Triggered
		1:  Motor Triggered
Motor3:		0:  Motor Not Triggered
		1:  Motor Triggered
Motor4:		0:  Motor Not Triggered
		1:  Motor Triggered

Returns:

Returns 1, if successful. Otherwise returns 0.   Error Message can be obtained by calling ItcGetError or ItcGetErrorMessage.

Comments:

the MotorPause and MotorContinue functions are the subset of this function.  If you want two or more motors start simultaneously, you can set them not triggered first, then call the MotorGo function and set them triggered.

-------------------------------------------------------------
Function MotorReset(WhichMotor:Integer):Integer;

This function performs a hardware reset to the Motor specified by the WhichMotor parameter, and set position counter to zero.

Parameters:

WhichMotor: 	the same as the one in the MotorNumberStep function.

Returns:

Returns 1, if the motor is ready to accept command.  Otherwise returns 0.

-------------------------------------------------------------
