Low level communication
In addition to the high-level instruction set, the TwinCAT RFID library also offers the possibility of low-level communication. This is solved implicitly. The same function block is used.
Any telegrams up to a maximum size of 1024 bytes can be received and sent up to a size of 300 bytes.
A complete telegram is composed as follows:
| Prefix | Addressing | Raw data | CRC | Suffix |
Depending upon the proprietary protocol specification, individual components may be missing. In general, however, the composition is the same.
Sending
The eRFC_SendRawData command from the instruction set is used for sending (see RFID command set). The raw data to be sent is specified in the input structure ST_RFID_Control.
In order to send a low level telegram, only the raw data is specified. The other telegram components are automatically supplemented by the TwinCAT RFID library. Checking data such as CRC are likewise generated and added internally.
If the protocol requires recoding of certain bytes within the raw data, this is also done automatically by the TwinCAT RFID library.
If an RS485 interface is involved, the addressing must be specified separately. It may not be contained in the specified raw data. By default, the addressing is performed automatically by the library. However, it can be parameterized via the input variables in ST_RFID_Control.
The raw data last sent can be viewed at any time at the output of the function block by means of the structure ST_RFID_RawData. This is independent of the command used.
Receiving
The raw data last received can be viewed at any time at the output of the function block by means of the structure ST_RFID_RawData. The associated addressing is output in the structure ST_RFID_ReaderInfo.
When using the command SendRawData, a direct evaluation of the received response cannot be guaranteed.
Example: If a read command is sent manually as a byte sequence by means of the SendRawData command, then received transponder data are not written at an address specified in ST_RFID_AccessData. Evaluation/storage of the data should therefore also be done manually with the help of the raw data structure ST_RFID_RawData, which is always specified. The specified raw data consists of the received telegram, but without prefix, suffix, checksum, CRC or shift sequence coding. If the received telegram has not been regularly evaluated by the function block, this is additionally indicated by an error.
In order to be able to use the received data, these must be copied, for example, to a byte array.
Example of the assignment of received data with the aid of the MEMCPY() function:
fbRFIDReader : FB_RFIDReader;
arrReceivedData : ARRAY [0..511] OF BYTE;
MEMSET( ADR(arrReceivedData), 0, SIZEOF(arrReceivedData) );
MEMCPY( ADR(arrReceivedData),
fbRFIDReader.stRawData.pReceivedRsp,
MIN(fbRFIDReader.stRawData.iReceivedRspLen, SIZEOF(arrReceivedData)) );
Balluff RFID Reader: The end identifier (LF CR) is used as a suffix for the recognition of telegrams. Previous data are combined into a telegram as soon as these 2 bytes are detected in the data stream.