Author Topic: Connecting to Barcode or Smart Card Readers  (Read 36225 times)

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Connecting to Barcode or Smart Card Readers
« on: December 13, 2005, 08:05:38 AM »
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.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

improtec

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:Connecting to Barcode or Smart Card Readers
« Reply #1 on: March 21, 2012, 06:14:16 AM »
Hi, some card reader use RS-485 with wiegan protocol, it is posibble to get it with the RS-485 port of the Tri-PLC ?
« Last Edit: March 21, 2012, 06:31:43 AM by improtec »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Connecting to Barcode or Smart Card Readers
« Reply #2 on: March 21, 2012, 09:31:02 AM »
According to: http://en.wikipedia.org/wiki/Wiegand_protocol

Wiegand is a 3 wire signal which is not RS485. If your reader actually convert the signal into RS485 and send out as individual bytes then it may be possible to use the INCOMM (n) command to read each byte of data from PLC's RS485 serial port #n. Once the byte are read into the data memory you can then apply any kind of extraction/conversion of the data to interpret the result.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS