ncOpenDnetIO (Open DeviceNet I/O)
Purpose
Configure and open an NI-DNET I/O Object.
Format
LabVIEW
C
NCTYPE_STATUS | ncOpenDnetIO( NCTYPE_STRING IntfName,
NCTYPE_UINT32 DeviceMacId,
NCTYPE_UINT32 ConnectionType,
NCTYPE_UINT32 InputLength,
NCTYPE_UINT32 OutputLength,
NCTYPE_UINT32 ExpPacketRate,
NCTYPE_OBJH_P ObjHandle); |
Input
IntfName | Name of DeviceNet interface |
DeviceMacId | MAC ID of the remote device |
ConnectionType | Type of I/O connection |
InputLength | Number of input bytes |
OutputLength | Number of output bytes |
ExpPacketRate | Expected rate of I/O message (packet) production |
Output
ObjHandle | Object handle you use with all subsequent function calls for the I/O Object |
Function Description
ncOpenDnetIO configures and opens an NI-DNET I/O Object and returns a handle that you use with all subsequent function calls for that object.
The I/O Object represents an I/O connection to a remote DeviceNet device. The I/O Object usually represents I/O communication as a master with a remote slave device. If your computer is essentially being used as the primary controller of your DeviceNet devices, you should configure I/O communication as a master.
You can also configure the I/O Object for I/O communication as a slave with a remote master. If your computer is essentially being used as a peripheral device for another primary controller, you can configure I/O communication as a slave. This is done by setting the I/O Object's DeviceMacId to the same MAC ID as the Interface Object (IntfMacId parameter of ncOpenDnetIntf).
The I/O Object supports as many master/slave I/O connections as currently allowed by the DeviceNet Specification (version 2.0). This means that you can use polled, strobed, and COS/cyclic I/O connections simultaneously for a given device. As specified by the DeviceNet Specification, you can only use one master/slave I/O connection of a given type for each device (MAC ID). For example, you cannot open two polled I/O connections for the same device.
Use the I/O Object to do the following:
- Read data from the most recent message received on the I/O connection (ncReadDnetIO).
- Write data for the next message produced on the I/O connection (ncWriteDnetIO).
Parameter Descriptions
IntfName
Description | Name of the DeviceNet interface as an ASCII string with format "DNETx", where x is a decimal number starting at zero that indicates which DeviceNet interface is being used. You associate DeviceNet interface names with physical ports using Measurement & Automation Explorer (MAX). |
Values | "DNET0", "DNET1", ..."DNET31" In LabVIEW, you select the interface name from an enumerated list. The LabWindows/CVI function panel also provides an enumerated list. |
DeviceMacId
Description | MAC ID (device address) of the remote DeviceNet device. Many devices use physical switches to set their MAC ID. For such devices, you can usually determine the device's MAC ID by examining those switches. MAC ID 63 is usually reserved for new devices (many devices use 63 as the factory default). If you do not know the MAC ID of your DeviceNet device, NI-DNET provides a utility which can display the MAC ID for you. This utility, Configurator, is described in the NI-DNET User Manual. For I/O communication as a master to a remote slave device (the usual case), DeviceMacId is the MAC ID of the remote DeviceNet slave device, and thus must be different than the MAC ID of your DeviceNet interface. If you want to configure I/O communication as a slave with a remote master, set DeviceMacId to the same MAC ID as your DeviceNet interface (the IntfMacId parameter of your previous call to ncOpenDnetIntf). By associating the I/O Object with your DeviceNet interface in this manner, you indicate that it represents I/O communication as a slave. |
Values | 0 to 63 |
ConnectionType
Description | Type of master/slave I/O connection. The connection type is either Polled, Strobed, change-of-state (COS), or Cyclic. As specified by the DeviceNet Specification, you can use only one master/slave I/O connection of a given type for each device (MAC ID). For example, you cannot open two polled I/O connections for the same device. If you do not know the I/O connection types supported by your DeviceNet device, NI-DNET provides a utility which queries the device for both this information and the device's supported input and output lengths. This utility, Configurator, is described in the NI-DNET User Manual. Change-of-state (COS) and cyclic I/O connections are acknowledged by default. If you want to suppress acknowledgments for these I/O connections, set the Ack Suppress driver attribute to true prior to starting communication. For more information, refer to the description of the I/O Object. |
Values | Poll (constant NC_CONN_POLL, value 0) Strobe (constant NC_CONN_STROBE, value 1) COS (constant NC_CONN_COS, value 2) Cyclic (constant NC_CONN_CYCLIC, value 3) In LabVIEW, you select the connection type from an enumerated list. The LabWindows/CVI function panel also provides an enumerated list. |
InputLength
Description | Number of input bytes for the I/O connection. This is the number of bytes read from the I/O connection using the ncReadDnetIO function. The following information is specific to the ConnectionType setting. Poll, COS, and Cyclic For these I/O connection types, the input length is the same as the number of bytes consumed from the remote device. Strobe as master (DeviceMacId not equal to IntfMacId)For this I/O connection, the input length is the same as the number of bytes consumed from the strobe response message, and must have a value from 0 to 8. Strobe as slave (DeviceMacId equal to IntfMacId)For this I/O connection, the input length must have a value of 1. The input data consists of a single Boolean value (bit) obtained from the master's strobe command message using IntfMacId. This Boolean value is returned from the ncReadDnetIO function as a single byte. |
Values | Poll, COS, and Cyclic: 0 to 255 Strobe as master (DeviceMacId not equal to IntfMacId): 0 to 8 Strobe as slave (DeviceMacId equal to IntfMacId): 1 |
OutputLength
Description | Number of output bytes for the I/O connection. This is the number of bytes written to the I/O connection using the ncWriteDnetIO function. The following information is specific to the ConnectionType setting. Poll, COS, and Cyclic For these I/O connections types, the output length is the same as the number of bytes produced to the remote device. Strobe as master (DeviceMacId not equal to IntfMacId)For this I/O connection, the output length must have a value of 1. The output data consists of a single Boolean value (bit) which is placed into the strobe command message using DeviceMacId. This Boolean value is provided to the ncWriteDnetIO function as a single byte. Strobe as slave (DeviceMacId equal to IntfMacId)For this I/O connection, the output length must have a value from 0 to 8. The output length is the same as the number of bytes produced in the strobe response message. |
Values | Poll, COS, and Cyclic: 0 to 255 Strobe as master (DeviceMacId not equal to IntfMacId): 1 Strobe as slave (DeviceMacId equal to IntfMacId): 0 to 8 |
ExpPacketRate
Description | Expected rate of I/O message (packet) production in milliseconds. As specified in the DeviceNet Specification, the expected packet rate is used to trigger data productions. The expected packet rate is also used for the watchdog timer to verify that the device on the other side of the I/O connection still exists and is producing data as expected. The expected packet rate of each I/O connection is a major factor in determining the overall performance of your DeviceNet network. The following information is specific to the ConnectionType setting and the PollMode setting of your Interface Object. Strobe with Automatic poll mode When using the Automatic poll mode, the ExpPacketRate setting is ignored for strobed I/O Objects. The rate of production for the strobe command message is determined automatically by NI-DNET. Strobe with Scanned or Individual poll modeWhen using the Scanned or Individual poll mode, you must set the ExpPacketRate to the same value for all strobed I/O Objects. Since a single strobe command message is produced for all strobed I/O connections, the rate of production for that message must be identical for all strobed I/O Objects. Poll with Automatic poll modeWhen using the Automatic poll mode, the ExpPacketRate setting is ignored for polled I/O Objects. NI-DNET automatically determines the rate of production for the poll command messages. Poll with Scanned poll modeWhen using the Scanned poll mode, since all poll and strobe requests are produced at the same time, you normally set the ExpPacketRate for all polled/strobed I/O Objects to a common value. If you need to isolate devices that are slow to respond to poll requests, it is possible to use different ExpPacketRate values while still maintaining the benefits of scanned I/O. You can set all ExpPacketRate values for polled I/O Objects as two groups, one foreground group, and a second background group whose ExpPacketRate is an exact multiple of the foreground group's. All strobed I/O must use the same rate as the foreground group for polled I/O. For example, you can set some polled I/O (and all strobed I/O) to a common foreground rate of 100 ms, and other polled I/O to a background rate of 500 ms. To maintain overall network determinism, the background poll requests are interspersed evenly among each foreground scan. Poll with Individual poll modeWhen using the Individual poll mode, the ExpPacketRate determines the rate at which the poll request of each polled I/O Object is produced. Although all strobed I/O Objects must still use the same rate, each polled I/O Object communicates at a rate which is independent of all other I/O connections. Change-of-state (COS) with any poll modeFor COS I/O Objects, the ExpPacketRate is used solely to verify that the I/O connection still exists. If no change in data produces I/O message within the expected packet rate, the previous data is produced again to maintain the I/O connection. Since this rate is used solely to maintain the I/O connection, it is often set to a large value, such as 10000 (10 seconds). In addition to the expected packet rate, COS I/O connections also produce an I/O message when a change is detected in the data. These I/O change messages do not occur at a predetermined rate. The time between each I/O change message depends on when an actual change takes place and how fast the device can measure new data and detect changes. Cyclic with any poll modeFor cyclic I/O Objects, the ExpPacketRate determines the rate at which the I/O message is produced. Each cyclic I/O Object communicates at a rate which is independent of all other I/O connections. Note regarding I/O as a slave (DeviceMacId equal to IntfMacId)The ExpPacketRate setting applies only to I/O Objects used for communication as a master (the usual case). For I/O Objects used for communication as a slave, this setting is ignored because the remote master determines the expected packet rate on behalf of your slave I/O connection. |
Values | 1 to 60000 |
ObjHandle
Description | If the ncOpenDnetIO function is successful, a handle to the newly opened I/O Object is returned in ObjHandle. This handle is used with all subsequent function calls for that I/O Object. The functions most commonly used with the I/O Object are ncReadDnetIO and ncWriteDnetIO. |
Values | The encoding of ObjHandle is internal to NI-DNET. |
Examples
LabVIEW
Open an I/O Object using interface "DNET2", device MAC ID 15, connection type Poll, input length 14, output length 6, and expected packet rate 40 ms.
C
Open an I/O Object using interface "DNET0", device MAC ID 12, connection type Strobe, input length 2, output length 1, and expected packet rate 100 ms.
NCTYPE_STATUS status;
NCTYPE_OBJH objh;
status = ncOpenDnetIO("DNET0", 12, ,NC_CONN_STROBE, 2, 1, 100, &objh);