It is very simple to read from a barcode or smart card/RFID reader if the barcode reader can be connected to the PLC using RS232. Most bar code readers return data as ASCII string terminated by a Carriage Return (CR character, ASCII 13) so you can simply use the INPUT$(1) command to read the data from the COM1 port. The PLC keeps a 256 bytes circular buffer for incoming serial characters so you don't have to be monitoring the serial port all the time. As long as the data are read before the buffer overflows (i.e. more than 256 bytes are received) the buffered data will not be lost.
First, decide how often you need to check whether the bar code has read something. e.g. every 0.5s, then form a circuit:
Clk:0.5s Fn_#1
|---||--------{dCusF}
Within function #1:
A$ = INPUT$(1) ' read from COMM port 1
IF LEN(A$)=0 RETURN: ENDIF ' nothing from barcode
' so just return
.... ' continue what you need to do
In the above code, if A$ receive an empty string from the COMM1 port it means there is no data available, so the function just quit. Otherwise, continue to process the data received in the string. You can convert strings to integer such as:
X = VAL(A$) or for hexadecimal string,
Y = HEXVAL(A$)
function such as MID$() can be used to extract a certain
segment of a string from the string variable.