User manual

118
Program
Notes
void Job(void)
{
/* JobID=0 : Change to sending-mode for serial port */
/* JobID=1 : Transmit sending-frame */
/* JobID=2 : Change to receiving-mode for serial port */
/* JobID=3 : Address polling of ACK from CPU */
/* JobID=4 : Receive ACK from CPU */
/* JobID=5 : Change to sending-mode for serial port */
/* JobID=6 : Transmit RR-Frame */
/* JobID=7 : Change to receiving-mode for serial port */
/* JobID=8 : Address polling of RES from CPU */
/* JobID=9 : Receive RES from CPU */
/* JobID=10 : Success communication processing */
switch(JobID)
{
case 0: case 5:if (port_number != 5)
{
if (port_number == 4) outportb(0x301,0xFF);
else outportb(PORTADD+0x0C,(inportb(PORTADD+0x0C) |
0x02));
delay(sending_delay);
}
if (JobID == 5) RR_occuring();
watchdog=0; index=0; sending_Index_max=5; Crc=0xFFFF;
JobID++;
break;
case 1: case 6:if (receiving_occuring()) data=Recport();
if (sending_occuring())
{
if (index<sending_Index_max-1)
{
Trsport(receiving_frame[index]);
Crc16(receiving_frame[index]);
if (index==3)
{
if (receiving_frame[3]==0) sending_Index_max=256+5;
else sending_Index_max=receiving_frame[3]+5;
}
}
else if (index==sending_Index_max-1)
{
receiving_frame[index]=lower_byte(Crc);
Trsport(receiving_frame[index]);
}
else if (index==sending_Index_max)
{
receiving_frame[index]=lower_byte(Crc);
Trsport(receiving_frame[index]);
}
else if (index==sending_Index_max)
{
receiving_frame[index]=upper_byte(Crc);
Trsport(receiving_frame[index]); watchdog=0; JobID++;
}; index++;
}
break;
case 2: case 7:if (port_number != 5)
{
delay(receiving_delay);
if (port_number ==4) outportb(0x301,0x00);
else outportb(PORTADD+0x0C,(inportb(PORTADD+0x0C) &
0xFD));
}
JobID++;
break;
case 3:
case 8:if (receiving_occuring())
{
data=Recport();
if(data==PC_ID)
{
Crc=0xFFFF; index=1; receivingIndexmax=5;
receiving_frame[0]=data; Crc16(data); JobID++;
}
}
Communication sequence function
JobID=0 to 4: handle Q and QA frames
JobID=5 to 9: handle RA and R frames
JobID 0,5:
A frame that sends the data from the peripheral device to the PLC. It resets
the watchdog and the CRC. Use a delay after the send to avoid errors due
to communications delays.
JobID 1,6:
Sends the Q and RR data. When there is no error, it resets the watchdog
and proceeds on to the next sequence.
JobID=2,7:
A sequence that senses the sending of the QA and R data to the peripheral
device after the completion of the functions that are received by the PLC
from the previous frame.
JobID=3,8:
Handles the received data, and calculates the CRC of the received data.