Appendix A: D320 PLC Communication Protocol
215
else receiving_Index_max=receiving_frame[3]+5;
}
}
else if(index==receiving_Index_max-1)
{
receiving_frame[index]=Recport();
if(receiving_frame[index]!=lower_byte(Crc)) JobID=(JobID & 0x05);
}
else if(index==receiving_Index_max)
{
receiving_frame[index]=Recport();
if(receiving_frame[index]==upper_byte(Crc)) JobID++;
else JobID=(JobID & 0x05);
}; index++;
}
break;
case 10:Success=TRUE;
}
}
unsigned int communication(void)
{
struct time t;
unsigned far *tm;
int ret;
Success=FALSE;
receiving_frame[0]=PlcID;receiving_frame[1]=PC_ID; retrialC=retrial_limit;
watchdog=0; JobID=0; index=0; sending_Index_max=5; Crc=0xFFFF;
do
{
tm=(unsigned far *) 0x046C;
New=*tm;
Job();
if(watchdog>Time_limit)
{
watchdog=0; retrialC--;
JobID=(JobID & 0x05);
}
if(!(((Old^New) & 0x02)==0))
{
watchdog=w1;
Old=New;
}
}while((retrialC!=0) && (Success==FALSE));
if(retrialC==0) ret=1;
else ret=0;
return(ret);
}
void Mword_reading(void)
{
/* Example of Read-Register */
int i;
receiving_frame[2]=3;/* EXAMPLE READ WORD(M000-M0127) */
receiving_frame[3]=3;/* Number Of Byte For Information = 3 */
receiving_frame[4]=0xC0;/* BASE(M000=$00c0) */
receiving_frame[5]=0;/* BASE HIGH */
receiving_frame[6]=128;/* Number Of Byte M000-M127 */
if(communication() == 0)
{
printf("READ M0000-M0127 OK - ");
for(i=0;i<=127;i++) M[i]=receiving_frame[i*2+4] +receiving_frame[i*2 +5]*256;
}
else printf("communication error\n");
}
JobID=10:
Receiving
If the frames that were sent have no
response within 3 seconds, assumes it
failed communication, and retransfers
the data.
The time from the sending and
receiving is counted using the
watchdog timer. Reset the watchdog
timer when a retransfer is being
made. No response after 3
retransmissions indicates a
communication error. (Normal return
value = 0, Abnormal return value = 1)
Reading Function of the register M.
Uses the communication function
code number 3 (reading N
consecutive words) to read the M
area.
Note:
Sending frame[4] = The lower byte of
the abs. address of the words to be
read.
Sending frame[5] = The upper byte of
the abs. address of the word to be
read.
Abs. address of the M0 = 0x0C0
Note:
Sending frame[6] = The number of
words to be read.
Summary of Contents for D320 PLC
Page 1: ...D320 PLC User s Manual...
Page 18: ...6 D320 PLC User s Manual...
Page 28: ...16 D320 PLC User s Manual...
Page 34: ...22 D320 PLC User s Manual...
Page 78: ...66 D320 PLC User s Manual...
Page 176: ...164 D320 PLC User s Manual...
Page 210: ...198 D320 PLC User s Manual...
Page 258: ...246 D320 PLC User s Manual...