User`s manual

XP8300/XP8400/SE1100 Advanced Programming s 89
Sample Program
The relay board demonstration program can be used to locate all XP8300
and XP8400 expansion boards. The program then loops, activating the
relays on each board. For each board, the program concludes with an all-
on/all-off sequence. To locate each board, the program polls all 64
possible addresses, then displays the logical address in Dynamic Cs
STDIO window for each board that responds.
/******************************************************
Relay Board Demo for XP8300 and XP8400
******************************************************/
#define ON 1
#define OFF 0
main(){
int board,relay,found,list[64];
Reset_PBus(); // always do this, first thing
delay(1000); // pause 1000ms for reset
// Locate relay boards. Build list
// and print board IDs
found=0;
printf("\nLogical relay addresses found: ");
for( board=0; board<64; board++ ){
if( plc_poll_node(plcrel_addr(board)) ){
list[found++] = board;
printf(" %d ",board);
if( found%10 == 0 ) printf("\n");
}
}
// Activate relays on each board
// found
while( 1 ){ // loop forever
for( board=0; board<found; board++ ){
for( relay=0; relay<8; relay++ ){
plc_set_relay(list[board],relay,ON);
delay(333);
plc_set_relay(list[board],relay,OFF);
}
for( relay=0; relay<8; relay++ ){
plc_set_relay(list[board],relay,ON); // all
}
delay(750);
for( relay=0; relay<8; relay++ ){
plc_set_relay(list[board],relay,OFF);// all
}
}
}
}
delay( int ms ){ // Max delay time = 2375 ms
unsigned int ival, i, j;
ival = (int)(ms * 27.30667) + 1;
for( i=0; i<ival; i++ ) j = j;
}