ncConvertFromDnetRead (Convert From DeviceNet Read)

NI-DNET Programmer

ncConvertFromDnetRead (Convert From DeviceNet Read)

Purpose

Convert data read from the DeviceNet network into an appropriate LabVIEW data type.

Format

LabVIEW

C

Not applicable, but see Examples at the end of this section

Input

DnetData in Data bytes read from the DeviceNet network
DnetType DeviceNet data type to convert from
ByteOffset Byte offset of the DeviceNet member to convert

Output

DnetData out DeviceNet data bytes (unchanged)
8[TF] out Converted LabVIEW array of 8 TF
I32/I16/I8 out Converted LabVIEW I32, I16, or I8
U32/U16/U8 out Converted LabVIEW U32, U16, or U8
DBL/SGL out Converted LabVIEW DBL or SGL
abc out Converted LabVIEW string

Function Description

Many fundamental differences exist between the encoding of a DeviceNet data type and its equivalent data type in LabVIEW. For example, for a 32-bit integer, the DeviceNet DINT data type uses Intel byte ordering (lowest byte first), and the equivalent LabVIEW I32 data type uses Motorola byte ordering (highest byte first).

ncConvertFromDnetRead takes a sequence of bytes read from the DeviceNet network, and given the byte offset and DeviceNet data type for a specific data member in those bytes, converts that DeviceNet data member into an appropriate LabVIEW data type.

You typically use ncConvertFromDnetRead with the following NI-DNET functions:

  • ncReadDnetIO—Convert a member of the input assembly to its LabVIEW data type.
  • ncGetDnetAttribute—Convert the attribute to its LabVIEW data type.
  • ncReadDnetExplMsg—Convert a member in the service response to its LabVIEW data type.

Since DeviceNet data types are similar to C language data types, C programming does not need a function like ncConvertFromDnetRead. By using standard C language pointer manipulations, you can convert a DeviceNet data member into its appropriate C language data type. For more information about converting DeviceNet data members into C language data types, refer to the Examples at the end of this section.

Parameter Descriptions

DnetData in

Description Data bytes read from the DeviceNet network. These data bytes are read from the DeviceNet network using ncReadDnetIO, ncGetDnetAttribute, or ncReadDnetExplMsg. If you need to convert multiple DeviceNet data members, you can wire this input terminal from the DnetData out output terminal of a previous use of this function.
Values Data output terminal of ncReadDnetIO
or
AttrData output terminal of ncGetDnetAttribute
or
ServData output terminal of ncReadDnetExplMsg
or
DnetData out output terminal of a previous use of this function

DnetType

Description An enumerated list from which you select the DeviceNet data type to convert. For each DeviceNet data type, the list displays the resulting LabVIEW data type in parentheses.

When you select the DeviceNet data type BOOL, ncConvertFromDnetRead converts the byte indicated by ByteOffset into an array of eight LabVIEW Booleans. You can index into this array to use specific Boolean members. The Boolean at index zero is the least significant bit (bit 0), the Boolean at index one is the next least significant (bit 1), and so on.
Values BOOL (8[TF])
SINT (I8)
INT (I16)
DINT (I32)
USINT (U8)
UINT (U16)
UDINT (U32)
REAL (SGL)
LREAL (DBL)
SHORT_STRING (abc)
STRING (abc)

ByteOffset

Description Byte offset of the DeviceNet member to convert. For the DeviceNet data member you want to convert, this is the byte offset in DnetData in where the member begins. Byte offsets start at zero.

You can find information on the format of your DeviceNet data in the following functions:

  • ncReadDnetIO—Specification for your device's input assembly.
  • ncGetDnetAttribute—Data type of the attribute. Unless the attribute's DeviceNet data type is a structure or array, the value for ByteOffset is always 0.
  • ncReadDnetExplMsg—Specification for the service data of the explicit message response.
Values 0 to 255

DnetData out

Description DeviceNet data bytes (unchanged). The data bytes of DnetData in are passed through the VI to this output terminal unchanged. To convert another DeviceNet data member, this data can be passed on to another call to this function.
Values Same as DnetData in

8[TF] out

Description If the selected DnetType is BOOL, this output terminal provides the converted DeviceNet data member. The LabVIEW data type for this output terminal is an array of eight LabVIEW Booleans, indicated as 8[TF]. You can index into this array to use specific Boolean members. The Boolean at index zero is the least significant bit (bit 0), the Boolean at index one is the next least significant (bit 1), and so on.
Values Converted DeviceNet data member

I32/I16/I8 out

Description If the selected DnetType is SINT, INT, or DINT, this output terminal provides the converted DeviceNet data member. Although the LabVIEW data type for this output terminal is I32, it can be coerced automatically to I16 or I8.
Values Converted DeviceNet data member

U32/U16/U8 out

Description If the selected DnetType is USINT, UINT, or UDINT, this output terminal provides the converted DeviceNet data member. Although the LabVIEW data type for this output terminal is U32, it can be coerced automatically to U16 or U8.
Values Converted DeviceNet data member

DBL/SGL out

Description If the selected DnetType is REAL or LREAL, this output terminal provides the converted DeviceNet data member. Although the LabVIEW data type for this output terminal is DBL, it can be coerced automatically to SGL.
Values Converted DeviceNet data member

abc out

Description If the selected DnetType is SHORT_STRING or STRING, this output terminal provides the converted DeviceNet data member. The LabVIEW data type for this output terminal is abc.
Values Converted DeviceNet data member

Examples

LabVIEW

  1. Use ncReadDnetIO to read Response Assembly 1 from a Position Controller. In this input assembly, the byte at offset 0 consists of 8 BOOL, and the bytes at offset 4–7 consist of an Actual Position of type DINT. Use ncConvertFromDnetRead to convert these DeviceNet data members into appropriate LabVIEW data types.

  2. Get the Device Type attribute using the ncGetDnetAttribute function. The Device Type is contained in the Identity Object (class ID 1, instance ID 1, attribute ID 2), and its DeviceNet data type is UINT. Use ncConvertFromDnetRead to convert the Device Type into an appropriate LabVIEW data type.

C

  1. Demonstrate the same conversions as LabVIEW example 1.
    NCTYPE_UINT8	data[8];
    NCTYPE_INT32	ActualPos;	/* DINT */
    NCTYPE_BOOL	CurrentDir;	/* BOOL */
    NCTYPE_BOOL	TrajInProg;	/* BOOL */
    status = ncReadDnetIO(objh, sizeof(data), data);
    
       /* Take the address of the data byte at offset 4, cast that 
       address to point to the appropriate C language data type, then 
       dereference the pointer.  */
    ActualPos = *(NCTYPE_INT32 *)(&(data[4]));
    
       /* If bit 4 of byte 0 is set, then CurrentDir is true. If bit 
       0 of byte 0 is set, the TrajInProg is true.  */
    CurrentDir = (data[0] & 0x10) ? NC_TRUE : NC_FALSE;
    TrajInProg = (data[0] & 0x01) ? NC_TRUE : NC_FALSE;
  2. Demonstrate the same conversion as LabVIEW example 2.
    NCTYPE_UINT16	device_type;
    NCTYPE_UINT16	actual_length;
       /* Conversion is performed automatically simply by passing in 
       a pointer to the appropriate C language data type.  */
    status = ncGetDnetAttribute(objh, 0x01, 0x01, 0x02,
    			100, sizeof(device_type), &device_type,
    			&actual_length);