drbitboy
Lifetime Supporting Member
Following on the previous post, with this method it is possible to also check for the length of the received code
The [RX Count] will normally be 29 when the carriage return is found as the last character.
That said, the baud rate is 9600, or around 10kbits/s. With the serial port configured for 8N1, there are 10 bits per character (8 data bits + 1 start bit + 1 stop bit), so 10kbits/s / (10bits/character) = 1kcharacter/s or 1ms/character. Scan times may be as low as 1ms, but not much less, so the PLC will be receiving as many as 1 character per scan.
Since it takes two scans to execute a rising edge on a rung, it will take two scans to de-activate and re-activate the RECV instruction, and the video claims that that will clear the internal (UART?) receive buffer, so characters could be lost.
All that is prelude to saying that perhaps the code should test for no less than 28 or 27 characters in a valid code.
The [RX Count] will normally be 29 when the carriage return is found as the last character.
That said, the baud rate is 9600, or around 10kbits/s. With the serial port configured for 8N1, there are 10 bits per character (8 data bits + 1 start bit + 1 stop bit), so 10kbits/s / (10bits/character) = 1kcharacter/s or 1ms/character. Scan times may be as low as 1ms, but not much less, so the PLC will be receiving as many as 1 character per scan.
Since it takes two scans to execute a rising edge on a rung, it will take two scans to de-activate and re-activate the RECV instruction, and the video claims that that will clear the internal (UART?) receive buffer, so characters could be lost.
All that is prelude to saying that perhaps the code should test for no less than 28 or 27 characters in a valid code.