/*
 XP81ID.C
 
 XP81xx  Digital Input/Output
 This sample program demonstrates higher level digital input and output
 function calls.  It will detect XP81xx boards attached to the PLCBus.
 
 Hardware Requirements:
 	1.	Any controller supporting the PLCBus natively, BL1400(Micro-G)
 		or BL1500(Micro-G2).
 	2.	XP81xx, schematic

 Software Requirements:
 	1.	lib.dir
 	2.	default.h
 	3.	libraries listed below

 Instructions:
 	Detecting the board -
 	Compile and run this program to scan all eight possible XP81xx board
 	addresses. Boards that were located will be displayed on the monitor.

 Uses:
	vdriver.lib provides virtual driver.

	eziocmmn.lib provides and specifies common routines.

	eziopbdv.lib provides specific PLCBus device routines.
 	
 	ezioplc.lib provides methods to access the PLCBus with a controller
 		supporting the PLCBus natively.
 		
 	eziomgpl.lib provides methods to access the PLCBus with a BL1400(Micro-G)
 		or	BL1500(Micro-G2),which uses one PIO port to simulate the PLCBus driver.
 	
 	plcXP81In(int boardaddress) reads an input from the board
 	eioResetPlcBus() resets the PLC-bus
 	eioPlcRstWait() waits long enough for all boards on the PLC-bus to reset
*/
 
#use vdriver.lib
#use eziocmmn.lib
#use eziopbdv.lib
#use ezioplc.lib		//	uncomment #use ezioplc.lib for PK2100(Rugged Giant),
							// PK2200(Little Star),BL1200(Little PLC), BL1600(Little G)
//#use eziomgpl.lib	//	uncomment #eziomgpl.lib for BL1400(Micro-G) or BL1500(Micro-G2)

char TITLE[] = {"XP81xx Board Detection"};

main()
{
	int i;

	VdInit();
	printf("%s\n\n", TITLE);
	eioResetPlcBus();			//	reset the PLCBus
	eioPlcRstWait();			//	delay ensures the PLCBus boards reset

	//	locate all possible jumper-set addresses from 0 to 7 and display status
	for (i = 0; i <= 7; ++i) {
		if (plcXP81In(i*32)==-1)			// do a read to locate the board
			printf("Board %d is not located\n",i);
		else
			printf("Board %d is located\n",i);
		}
}
