<< Click to Display Table of Contents >> Navigation: »No topics above this level« DCAN variable objects |
A DCAN variable object represents a CAN object on the CAN bus. A CAN object is defined using the CAN ID. All CAN messages are assigned to the CAN object using this CAN ID.
Message doubling can occur when using CAN in a malfunctioning environment (see CiA "CAN Data Link Layer"). In this case, the same CAN message is received twice.
For this reason, the following points need to be taken into consideration in a malfunctioning environment:
- No "Toggle" messages or counted messages may be evaluated
- No messages with relative data (such as increments) may be sent
- Data segments may only be transferred with a protected protocol or with sequence numbers.
CAN objects can hold a maximum of 8 data bytes. The data format of the variable object can either be set by the user or by the DCAN line.
DCAN Variable objects can be defined for either send or receive operation within a station object. This definition takes place with the object attribute property (AT parameter). "AT=w" is specified for send operations, "AT=e" for receive operations. Send and receive operation on the same CAN object is not possible. In receive operation, CAN data is transferred as an event to the application (POBJ_EVENT_DATA event type). Specifying the refresh time (RF parameter) has no significance.
RTR send objects are not supported by the SJA1000 driver.
CAN variable objects can also be operated as CAN RTR objects. An RTR object can be defined either as a send ("AT=w") or receive ("AT=r") object. RTR (Remote Transmission Request) is a method standardized for CAN where a station (Producer) sends a CAN message (data frame - RTR bit not set) only after a read request (remote frame - RTR is set) from another station (Consumer). The read request and response have the same CAN ID and are only differentiated by the RTR bit.
If a DCAN line variable object is created as an RTR receive object (Consumer, "AT=r"), then a RTR read request is sent to the CAN bus with the specified refresh time. As with "normal" PLC variables from other lines, data acquisition can also be controlled here by the PVICOM application. For this, the Value - 1 is set as the refresh time. The application itself determines when the read request is carried out by calling the PviReadRequest or PviXReadRequest and using access type POBJ_ACC_DATA. RTR receive objects work with timeout monitoring. After an RTR read request, the response from the opposite station needs to be received within the given time. If this doesn't happen, then Timeout Error 14987 is reported. The maximum response time can be defined using the /TR parameter in the connection description of the station object.
DCAN line variable objects can also be created as RTR send objects (Producer, "AT=w"). The send object is supplied with data by calling the PviWriteRequest or PviXWriteRequest function. However, the maximum number of send objects is limited and depends on the CAN card being used. A maximum of 12 can be used with the B&R standard CAN interface. Up to 256 send objects can be used with the LS172 card. With the LS172 card, RTR send objects can only be used with an ID less than or equal to 2047 even when using extended frames (29-bit identifiers).
Received data for a CAN object is normally monitored for changes. That means the application is only informed of changes to CAN data. Monitoring for changes can be disabled (specification "AT=de") with the variable attribute "d" (direct). This transfers all received CAN data to the application.
With the "d" object attribute, all received CAN data occupy application memory in PVI until it is read by the application. Therefore, the "d" attribute should be used with extreme care and only when absolutely necessary.
When transferring data, the DCAN line does not carry out byte swapping since CAN data is already in Intel format anyway (least significant byte first).
The CAN object ID must be entered in the connection description. Code letters can be used to determine how the CAN objects function.
Connection description syntax:
/RO=[L][R]<CAN ID>
or
[L][R]<CAN ID>
These code letters are not case sensitive. These code letters can be combined in any way.
Code letter "L" |
Description |
Not specified |
The user can set any data format (e.g. a structure). Note that CAN objects can only transfer a maximum of 8 data bytes. The total length of the set data format determines the length of the data to be transferred in the write direction (sending). In the read direction (receiving), the data is copied dependent on its length. For example, the user defined "i32" (4-byte integer) as a data format. If a CAN message with 2 bytes of data is received, then only the first 2 bytes of the integer value are copied. All other bytes remain undefined. If a data format is not defined when creating the DCAN variable object, then the line automatically uses "VT=u8 VN=8" (byte array with 8 byte length). This variant is especially suitable for CAN objects with a fixed data length. The user has the option of setting the format of a structure, array, or signal variable using the CAN data. This allows PVI functions like type casting, variable addressing, event hysteresis, or data functions to be used. |
Specified |
Regardless of the user setting, a data format of "VT=u8 VN=9" (byte array with 9 byte length) is set by the DCAN line. The length of the CAN object data to be sent or received is passed in the first byte. Bytes 2-9 are used to pass the data. When writing, the user has to enter the length of the data in the first byte. Values between 0 (zero) and 8 are valid for the data length. This variant is intended for CAN objects with differing data lengths but can also (of course) be used for CAN objects with a fixed data length. |
Code letter "R" |
Description |
Not specified |
Standard CAN object for send or receive operation This definition takes place with the object attribute property (AT parameter). "AT=w" is specified for send operations, "AT=e" for receive operations. |
Specified |
RTR send or receive object This definition takes place with the object attribute property (AT parameter). "AT=w" is specified for the send object, "AT=r" is specified for the receive object. The refresh time property is also evaluated for receive objects. |
Example of object description:
CD="/RO=1597" VT=i32 AT=e
After receiving a CAN message with CAN ID 1597, data is mapped to a 4-byte integer.
CD="/RO=L1597" AT=e
After receiving a CAN message with CAN ID 1597, the data length and the data in the CAN message are mapped to a 9-byte array.
CD=1597 VT=i32 AT=w
With the write access to the variable object, the 4-byte integer data is sent together with the CAN ID 1597 as a CAN message.
CD=LR1597 AT=r RF=500
RTR read object for CAN ID 1597. A read request is sent every 500 ms.
CD=R1597 VT=i16 AT=w
RTR write object for CAN ID 1597. 2-byte integer data is sent after an external read request.