Example code for polled messaging, Reset the card */ outportb( h186reset, 0); outp, Start the card */ outportb( hresetoff, 0); outp – Rockwell Automation D17846.2.4 CONTROLNET KT EMULA User Manual

Page 32: Wait a bit for the card to initialize itself, Load initialization string into the kt dualport, Monitor heartbeat flag for transition to 2 */ p, Transmit 10 id host and status */ /* make sure, Cprintf("transmit 10 packets of id host and status, Place an id host and stat message into the dual, Release the send box */ pdp->comm.send.shake2

Advertising
background image

1784-6.2.4 - September 1997

A-2

Example Code for Polled and Interrupt Messaging

Example Code for Polled
Messaging

The following example code shows how to setup for polled messag-
ing over the dual-port.

/* reset the card */
outportb( H186RESET, 0);
outportb( HRESETON, 0);

/* start the card */
outportb( HRESETOFF, 0);
outportb( H186RUN, 0);

/* wait a bit for the card to initialize itself */
delay(4000);

/* Load initialization string into the kt dualport */
cprintf("\r\nStarting up emulation mode...wait 1/2 second\r\n");
pDP->comm.unused1[0] =0xC3;
pDP->comm.unused1[1] =0x00;
pDP->comm.unused1[2] =0x00;
pDP->comm.unused1[3] =0x00;
pDP->comm.online =0x00;
pDP->comm.nodeaddr =0x08;
pDP->comm.shutdown_trig =0x00;
*pRUN=1;
cprintf("Heartbeat:%2d,Run:%2d\r",pDP->comm.heartbeat,*pRun,*pReset);
delay(500);

/* monitor heartbeat flag for transition to 2 */
pHBPrev = pDP->comm.heartbeat;
while (pDP->comm.heartbeat !=2
{

if (pHBPrev != pDP->comm.heartbeat)
{

cprintf("\r\n Heartbeat: %2d, Run %2d, Stop %2d\r",pDP->comm.heartbeat,*pRun,

*pReset); pHBPrev = pDP->comm.heartbeat;

}

}

/* transmit 10 id host and status */
/*
make sure we have the send flags (must be 0) */
if ((pDP->comm.send.shake1 !=1) || (pDP->comm.send.shake2 !=1))
{

cprintf("Critical Error: Send box not available\r\n");
exit(0);

}

cprintf("Transmit 10 packets of ID Host and Status \r\n");
for (i=0; i < 10; ++i)
{

/* wait for the send box to be available */
while ((pDP->comm.send.shake1 != 1) && (pDP->comm.send.shake2 ! = 1))
{
}

/* place an id host and stat message into the dualport */
pDP->comm.send.len = 11;
pDP->comm.send.dst = 1;
pDP->comm.send.lsap = 0;
memcpy(&pDP->comm.send.data.[0],abIDHost,sizeof(abIDHost);

/* release the send box */
pDP->comm.send.shake2 = 0;
pDP->comm.send.shake1 = 0;

/* wait for the response message */
while ((pDP->comm.rev.shake1 !=1) && (pDP->comm.rev.shake2 !=1))
{
}

/* Print the response out */
ptr = pDP->comm.rev.data;
cprintf("Response %2d: -,i);
for (j=0; j < pDP->comm.rev.len.; ++j)
{

cprintf("%02X", *(ptr+j));

}
cprintf("\n\r");

/* release the receive box */
pDP->comm.rev.shake2 = 0;
pDP->comm.rcv.shake1 = 0;

}

Advertising