User manual

119
Program
Notes
break;
case 4:
case 9:if(receiving_occuring())
{
if(index<receiving_Index_max-1)
{
receiving_frame[index]=Recport();
Crc16(receiving_frame[index]);
if(index==3)
{
if(receiving_frame[3]==0) receiving_Index_max=256+5;
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=watchdog+1;
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\n");
for(i=0;i<=127;i++) M[i]= receiving_frame[i*2+4] + receiving_frame[i*2
+5]*256;
}
else printf("communication error\n");
}
void Kword_writing(void)
{
/* Example of Write-Register */
int i;
receiving_frame[2]=4; /* EXAMPLE write WORD(K000-K063) */
receiving_frame[3]=130; /* Number Of Byte For Information */
receiving_frame[4]=0x40; /* BASE(K000=$0140) LOW */
receiving_frame[5]=1; /* BASE HIGH */
for(i=0;i<=63;i++)
{
receiving_frame[i*2 +6]= lower_byte(K[i]);
receiving_frame[i*2 +7]= upper_byte(K[i]);
}
JobID=4,9:
Stores the received data in the internal receive buffer and compares the
CRC value sent by the PLC to the calculated CRC value. It notifies the
system that a successful communication is made when the two values
match, and proceeds on to the next sequence.
JobID=10:
Notifies the successful sending and 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.
Resets the watchdog time when a retransfer is being made. No response
after 3 transmissions indicates a communication error. (Normal return
value = 0, Abnormal return value = 1)
Reading function of the M register
Uses the communication function code 3 (reading N consecutive words) to
read the M area.
Note:
Sending frame [4] = The lower byte of the absolute address of the words to
be read.
Sending frame [5] = The upper byte of the absolute address of the word to
be read.
Absolute address of M0 = 0x0C0
Note: Sending frame [6] = The number of words to be read.
Sends a function code requesting to read the M area, and stores the
received data in the buffer.
Writing Function of the K Register
Uses the communication function code 4 (writing N consecutive words) to
store the specified value in the K000 to K063 word.
Note:
Absolute address of K0 = 0x0140