I have a lot of experience with serial communications, and I am not going for simple, I am going for robust, but they are often the same thing. Reading 29 characters per rising edge of Read_Complete will work -
until it doesn't: all that needs to happen is one short 27-character bar code to be scanned; it could be caused by EMR noise near the RS-232 cable. Then, instead of seeing a sequence of 29-character reads ending with a carriage return (<CR>) character like this:
abcdefghijklmnopqrstuvwxyzBC<CR>
abcdefghijklmnopqrstuvwxyzBC<CR>
abcdefghijklmnopqrstuvwxyzBC<CR>
abcdefghijklmnopqrstuvwxyzBC<CR>
...
the RECV/read will set Read_Complete to 1 after each of these 29-character reads:
abcdefghijklmnopqrstuvwxyzBC<CR>
abcdefghijklmnopqrstuvwxyzB<CR>a <= Note 1
bcdefghijklmnopqrstuvwxyzBC<CR>a
bcdefghijklmnopqrstuvwxyzBC<CR>a
...
Note 1: the Gryphon scans - and sends - a short 27-char code followed by a carriage return, with final '
C' missing, to be read by the RECV instruction; in the PLC the
<CR> is effectively shifted one to the left and the leading '
a' from the next (
blue) scan fills in as the 29th character read. So the Read_Completed does not become 1 until 29 characters are read - the RECV is only counting 1-byte, 8-bit characters, it is not parsing where the carriage return occurs.
Now the code is comparing 'C<CR>' to 'BC' on every Read_Completed. And the code will never recover, unless one long 29-character code is scanned accidentally.
I just realized, if we RECV/read one byte at a time into %R01014, and do a 1-byte
left MULTI SHIFT BYTE, of 29 bytes starting at %R01000, on the
rising edge only of Read_Complete whenever the character received is not the carriage return (register word %R01014 is not 13), then we can keep using the 28 characters starting at %R01000, and %R01013 will be 'BC' (or not) when %R01014 is 13.
The nice part about this approach is that it can run continuously (so the display will update), and only needs to be checked when the part is in position 1.
That said, we may need to turn the RECV/read off for one scan after a Read_Complete to ensure Read_Complete returns to 0 after each character, because the PLC might not be able to keep up with 9600baud * ~1(bit/s)/baud * 1character/~10bit = 1000character/s.
Again, how is the Gryphon configured with regard to triggering? Note that we can use the SEND instruction so transmit an E or D to Enable or Disable, respectively, the scanner, and we could make that dependent on rising and falling edges of the prox for position 1.