The manner of ending the information may be one or a combination of the following.
1 End character detection: The end character is any character used to indicate the end of the message. Set ec-1, SMB89 (or SMBl89) to an end character; the information receiving function checks each received character after finding the starting condition to start receiving characters, and judges whether the finger is set to match whether it matches the ending character, if receiving To the end character, store it in the information buffer and the message receiving function ends. Usually the same character is used for all information to end. AS (1, II code protocol, the user can use the end character detection.
2 character interval timer timeout: The character interval time is the time from the end of one character (stop bit) to the end of the next character (stop bit). Set c/m-O, tmr-1, SMW92 (SMwl92) one-character timeout. Such as
If the time interval between the two characters received by the information receiving function exceeds the character timeout timer setting, the information receiving function ends. The inter-character timeout timer setting should be greater than the time at which the specified baud rate is transmitted for one character (including start bit, data bit, finger set check bit, and stop bit). The user can end a message by using a character interval timer combined with end character detection or maximum character count.
3 information timer value: from the beginning of the information, after a specified period of time, the information timer ends a message. Set c/m-1, tmr-1, SMW92 (SMwl92) to a message timeout. The information receiving function starts the information timer when the start condition finger set starts to receive the character, and the information receiving time ends when the information timer expires. Similarly, the user can end a message by using a character interval timer combined with end character detection or maximum character count.
4 Maximum character count: When the number of characters received by the message receiving function is greater than SMB94 (or SMBl94), the message receiving function ends. The receive command requires the user to set a desired maximum number of characters, thereby ensuring that user data after the information buffer is not overwritten.
The maximum character count is always used in conjunction with the end character, the inter-character timeout timer, and the information timer as the end condition. ’
5 Check error: When the received character has a parity error, the message receiving function ends automatically. A parity error may occur only when the check digit is set in SMB30 (or SMBl30).
6 User End: The user can terminate the message receiving function by setting SMB87 (or SMBl87) to 0.
In order to fully adapt to the support of various communication protocols, character interrupt control can be used to receive data. An interrupt is generated each time the communication port receives a character. The received characters are stored in SMB2 before the execution of the interrupt program connected to the receive character interrupt event, and the check status (if allowed) is stored in SM3. O. ‘ ’
SMB2 is a free port receive character buffer. In free port mode, each received character is stored in this unit for user program access. SMB3 is used in free port mode and contains a parity error flag. This bit is set when a check error is detected while receiving a character, and all other bits of the byte are reserved.
Note that SMB2 and SMB3 are common to port 0 and port 1. When the received character comes from port 0, an interrupt program is connected to the event (interrupt event 8). At this time, SMB2 stores the character received from port 0, and SMB3 stores the check status of the character; when the received character comes from the port 1. The interrupt program connected to the event (interrupt event 25) is executed, the character received from port 1 is stored in SMB2, and the check state of the character is stored in SMB3.
The function of this program is the communication between the upper PC and the PLC. The PLC receives a string of characters sent by the host PC until the carriage return is received, PI. c sends the information back to Pc.
The main program of the free port protocol communication instruction application example, the function implemented by the program is to receive a string until a newline character is received. After the reception is completed, the information is sent back to the sender. Interrupt 0 is the receive completion interrupt routine. The function implemented by interrupt 0 is to add a 10ms timer to trigger the transmission and return if the reception status shows the reception end character. Interrupt l is triggered by a 10ms timing trigger. Interrupt 2 is a send character interrupt event.




