Appendix A: D50 PLC Communication Protocol 169
printf("----------------\nPLC-ID (CPU ID) :");
scanf("%d",&PlcID);
if(PlcID<256)
{
Mword_reading();
Kword_writing();
}
else
exit(0);
}
}
void RR_occurring(void)
{
receiving_frame[2]=0;
receiving_frame[3]=1;
receiving_frame[4]=0;
}
void Trsport(unsigned int data)
{
if (port_number == 5) outportb(PORTADD,data);
else outportb(PORTADD+0x08,data);
}
unsigned int Recport(void)
{
unsigned int dt;
if (port_number == 5) dt=inportb(PORTADD);
else dt=inportb(PORTADD+0x08);
return(dt);
}
BOOL sending_occurring(void)
{
BOOL tf;
if (port_number == 5) tf=((inportb(PORTADD+0x02) & 0x80)==0x80);
else tf=((inportb(PORTADD+0x0D) & 0x20)==0x20);
return(tf);
}
BOOL receiving_occurring(void)
{
BOOL rf;
if (port_number == 5) rf=((inportb(PORTADD+0x02) & 0x20)==0x20);
else rf=((inportb(PORTADD+0x0D) & 0x01)==0x01);
return(rf);
}
void Crc16(unsigned int data)
{
unsigned int i;
Crc=Crc^(data & 0x00FF);
for(i=0;i<=7;i++)
{
if((Crc & 0x0001) == 0x0001) Crc=(Crc>>1)^0xA001; /* 0x0001 : mult-nominal
expression */
else Crc=Crc>>1;
}
}
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 */
CPU-ID: Input PLC ID (0 to 255)
Read the register value for the M area
(M0 to M127)
Store the value for the M area in the
K area (K0 to K127)
RR (Request Response) request
function.
Sends data to the communication
port.
Reads the received data from the
communication port.
Outputs the data when a send event
occurs.
Inputs the data when a Receive event
occurs.
CRC Calculation:
Encodes the communication data in
the byte stream. When one
communication function is complete,
it is attached to the most recent frame,
or is compared with the attached CRC
to check for data errors.
Communication sequence
functions:
Job ID=0~4 Q,QA Frame handling
Job ID=5~9 RA,R Frame handling
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com