ncConvertForDnetWrite (Convert For DeviceNet Write)

NI-DNET Programmer

ncConvertForDnetWrite (Convert For DeviceNet Write)

Purpose

Convert an appropriate LabVIEW data type for writing data bytes on the DeviceNet network.

Format

LabVIEW

C

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

Input

DnetData in Initial data bytes to write on the DeviceNet network
DnetType DeviceNet data type to convert into
ByteOffset Byte offset of the DeviceNet member to convert into
8[TF] in LabVIEW array of 8 TF to convert from
I32/I16/I8 in LabVIEW I32, I16, or I8 to convert from
U32/U16/U8 in LabVIEW U32, U16, or U8 to convert from
DBL/SGL in LabVIEW DBL or SGL to convert from
abc in LabVIEW string to convert from

Output

DnetData out DeviceNet data bytes (with member inserted)

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).

ncConvertForDnetWrite takes an initial sequence of bytes to write on the DeviceNet network, and given the byte offset and DeviceNet data type for a specific data member, converts an appropriate LabVIEW data type for placement into those data bytes. You provide initial data bytes using DnetData in, convert a LabVIEW data type for each data member changed by your LabVIEW program (possibly replacing all initial bytes with LabVIEW data), then write the bytes onto the DeviceNet network.

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

  • ncWriteDnetIO—Convert a LabVIEW data type for placement into the output assembly.
  • ncSetDnetAttribute—Convert a LabVIEW data type to set as the attribute value.
  • ncWriteDnetExplMsg—Convert a LabVIEW data type for placement into the service request.

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

Parameter Descriptions

DnetData in

Description Initial data bytes to write on the DeviceNet network. These data bytes are normally created as a constant array of U8, then given valid default values. 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.

If you replace all initial data bytes using this function, the default values are unimportant, and you can leave them as zero.
Values Initial data bytes to write on the DeviceNet network

or

DnetData out output terminal of a previous use of this function

DnetType

Description An enumerated list from which you choose the DeviceNet data type to convert into. For each DeviceNet data type, the appropriate LabVIEW data type is listed in parentheses.

When you select the DeviceNet data type BOOL, ncConvertForDnetWrite converts the byte indicated by ByteOffset from an array of eight LabVIEW Booleans. You can index into this array to change 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 into. For the DeviceNet data member you want to replace, 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:
  • ncWriteDnetIO—Specification for your device's output assembly.
  • ncSetDnetAttribute—Data type of the attribute. Unless the attribute's DeviceNet data type is a structure or array, the value for ByteOffset is always 0.
  • ncWriteDnetExplMsg—Specification for the service data of the explicit message request.
Values 0 to 255

8[TF] in

Description If the selected DnetType is BOOL, this input terminal provides the LabVIEW data to convert into a DeviceNet data member. The LabVIEW data type for this input terminal is an array of eight LabVIEW Booleans, indicated as 8[TF]. You can index into this array to change 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 LabVIEW data to convert into a DeviceNet data member

I32/I16/I8 in

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

U32/U16/U8 in

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

DBL/SGL in

Description If the selected DnetType is REAL or LREAL, this input terminal provides the LabVIEW data to convert into a DeviceNet data member. Although the LabVIEW data type for this input terminal is DBL, it can be coerced automatically from SGL.
Values LabVIEW data to convert into a DeviceNet data member

abc in

Description If the selected DnetType is SHORT_STRING or STRING, this input terminal provides the LabVIEW data to convert into a DeviceNet data member. The LabVIEW data type for this input terminal is abc.
Values LabVIEW data to convert into a DeviceNet data member

DnetData out

Description DeviceNet data bytes (with member inserted). These data bytes are written on the DeviceNet network using the ncWriteDnetIO, ncSetDnetAttribute, or ncWriteDnetExplMsg function. If you need to convert multiple DeviceNet data members, you can also wire this output terminal into the DnetData in input terminal of a subsequent use of this function.
Values Data input terminal of ncWriteDnetIO
or
AttrData input terminal of ncSetDnetAttribute
or
ServData input terminal of ncWriteDnetExplMsg
or
DnetData in input terminal of a subsequent use of this function

Examples

LabVIEW

  1. Use ncWriteDnetIO to write Command Assembly 1 to a Position Controller. In this output assembly, the byte at offset 0 consists of 8 BOOL and the bytes at offset 4–7 consist of a Target Position of type DINT. Use ncConvertForDnetWrite to convert appropriate LabVIEW data types for these DeviceNet data members.

  2. Set an attribute Foo using the ncSetDnetAttribute function. The attribute Foo is contained in an object with class ID D5 hex, instance ID 1, attribute ID 5, and its DeviceNet data type is LREAL. Use ncConvertForDnetWrite to convert the appropriate LabVIEW data type for Foo.

C

  1. Demonstrate the same conversions as LabVIEW example 1.
    NCTYPE_UINT8	data[8];
    NCTYPE_UINT8	I;
    NCTYPE_INT32	TargetPos;	/* DINT */
    NCTYPE_BOOL	Enable;		/* BOOL */
    NCTYPE_BOOL	StartTraj;	/* BOOL */
    
       /* Initialize default values of zero.  */
    for (I = 0; I < 8; I++)
       data[I] = 0;
    
       /* If Enable is true, set bit 7 of byte 0.  If StartTraj is 
       true, set bit 0 of byte 0.  */
    if (Enable == NC_TRUE)
       data[0] |= 0x80;
    if (StartTraj == NC_TRUE)
       data[0] |= 0x01;
    
       /* 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 in order to store the value.  */
    *(NCTYPE_INT32 *)(&(data[4])) = TargetPos;
    
    status = ncWriteDnetIO(objh, sizeof(data), data);
  2. Demonstrate the same conversion as LabVIEW example 2.
    NCTYPE_LREAL	foo;
       /* Conversion is performed automatically simply by passing in 
       a pointer to the appropriate C language data type.  */
    foo = 354654.4543;
    status = ncSetDnetAttribute(objh, 0xD5, 0x01, 0x05, 100, 
    			sizeof(foo), &foo);