Guide to I/O System 20120305
Copyright © 20052014 SSAB AB Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no FrontCover Texts, and no BackCover Texts.
Table of Contents About this Guide ..................................................................................................................................8 Introduction..........................................................................................................................................9 Overview............................................................................................................................................10 Levels....................................
Pb_Profiboard.......................................................................................................................21 Slave objects.............................................................................................................................21 Pb_Dp_Slave........................................................................................................................21 ABB_ACS_Pb_Slave......................................................................................
Siemens_Di2_PnModule......................................................................................................29 Siemens_Do4_PnModule.....................................................................................................29 Siemens_Do2_PnModule.....................................................................................................29 Siemens_Do32_PnModule...................................................................................................
Link file.....................................................................................................................................57 Velleman K8055............................................................................................................................58 Agent object..............................................................................................................................58 USB_Agent............................................................................
IoAgentRead....................................................................................................................79 IoAgentWrite...................................................................................................................79 IoAgentSwap...................................................................................................................79 Rackmetoder...............................................................................................................
About this Guide The Proview Guide to I/O System is intended for persons who will connect different kinds of I/O systems to Proview, and for users that will gain a deeper understanding of how the I/O handling or proview works. The first part is an overview of the I/O systems adapted to Proview, and the second part a description of how to adapt new I/O systems to Proview.
Introduction The Proview I/O handling consists of a framework that is designed to ● be portable and runnable on different platforms. ● handle I/O devices on the local bus. ● handle distributed I/O systems and communicate with remote rack systems. ● make it possible to add new I/Osystems with ease. ● allow projects to implement local I/O systems. ● synchronize the I/Osystem with the execution of the plcprogram, or application processes.
Overview The I/O devices of a process station is configured by creating objects in the Proview database. The objects are divided in two trees, the Plant hierarchy and the Node hierarchy. The Plant hierarchy describes how the plant is structured in various process parts, motors, pumps, fans etc. Here you find signal objects that represents the values that are fetched from various sensors and switches, or values that are put out to motors, actuators etc.
I/O System This chapter contains descriptions of the I/O systems that are implemented in Proview.
PSS9000 PSS9000 consist of a set of I/O cards for analog input, analog output, digital input and digital output. There are also cards for counters and PID controllers. The cards are placed in a rack with the bus QBUS, a bus originally designed for DEC's PDP11 processor. The rack is connected via a PCI QBUS converter to an x86 PC, or connected via Ethernet, so called Remoterack. The system is configured with objects from the SsabOx volume. There are objects representing the Rack and Carde levels.
Attributes Description ThreadObject Thread object for the plc thread that should handle the rack. Only used if Process is 1. StallAction No, ResetInputs or EmergencyBreak. Default EmergencyBreak. Di card All digital inputcards have a common baseclass, Ssab_BaseDiCard, that contains attributes common for all di cards. The objects for each card type are extended with channel objects for the channels of the card. Ssab_BaseDiCard Attributes RegAddress Description QBUS address.
Attributes Description Process Process that handles the rack. 1 the plcprogram, 2 io_comm. ThreadObject Thread object for the plc thread that should handle the rack. Only used if Process is 1. InvMask1 The invert mask states which channels are inverted. Handles channel 116. InvMask2 See InvMask1. Handles channel 17 – 32. FixedOutValue1 Bitmask for channel 1 to 16 when the I/O handling is emergency stopped. Should normally be zero. FixedOutValue2 See FixedOutValue1.
Ssab_AI16uP The object configures an analog inputcard of type Ai16uP. The card has 16 channels, whose AiChan objects is internal attributes in the card object. The object is positioned as a child to a Rack_SSAB or Ssab_RemoteRack object. Attributes, see BaseACard. Ssab_AI32uP The object configures an analog inputcard of type Ai32uP. The card has 32 channels, whose AiChan objects are internal attributes in the card object. The object is positioned as a child to a Rack_SSAB or Ssab_RemoteRack object.
Fig PSS9000 configuration example
Profibus Profibus is a fieldbus with nodes of type master and slave. The usual configuration is a monomastersystem with one master and up to 125 slaves. Each slave can handle one or several modules. In the Proview I/O handling the master represents the agent level, the slaves the rack level, and the module the card level. Proview has support for the mastercard Softing PROFIboard PCI (see www.softing.com) that is installed in the PCIbus of the process station.
Address The address of the slave is stated in the Address attribute. The address has a value in the intervall 0 125 that is usually configured with switches on the slave unit. SlaveGsdData The map SlaveGsdData contains informational data. UserPrmData The map UserPrmData contains the parameter that can be configured for the current slave.
Module A slave can handle one or several modules. There are modulare slaves with one single module, where the slave and the module constitutes on unit. and there are slaves of rack type, into which a large number of modules can be inserted. The Profibus configurator displayes on map for each module that can be configured for the current slave. Each slave is given an object name, e.g. M1 M2 etc. Modules on the same slave has to have different object names. Also the module type is stated.
Class all the subclasses to Pb_Module are listed. If you find a class corresponding to the current module type, you select this class, otherwise you select the baseclass Pb_Module. The difference between the subclasses and the baseclass is that in the subclasses, the dataarea is specified with channel objects (se section Specify the data area). When all the modules are configured you save by clicking on 'Ok' and leave by clicking 'Cancel'.
ChanDi object. Representation is set to Bit8, Bit16, Bit32 or Bit64 dependent on the size of the word, and in Number the bit number that contains the channel value is stated (first bit has number 0 ). Analog inputs An analog input is usually transferred as a integer value and specified with a ChanAi object. Representation matches the integer format in the transfer.
ABB_ACS_Pb_Slave Slave object for a frequencyconverter ABB ACS800 with protocol PPO5. Siemens_ET200S_IM151 Slaveobject for a Siemens ET200S IM151. Siemens ET200M_IM153 Slave object for a Siemens ET200M IM153. Module objects Pb_Module Baseclass for a profibus module. The object is created by the Profibus configurator. Placed as child to a slave object. ABB_ACS_PPO5 Moduleobject for a frequencyconverter ABB ACS800 with protocol PPO5.
Profinet Profinet is a real time ethernet standard for automation. A Profinet IO system consists of three devicetypes. • The IO Controller, which controls the automation task. • The IO Device, which is a field device, monitored and controlled by an IO Controller. • The IO Supervisor is a software used for setting parameters and diagnosing individual IO devices. Each device can consist of several modules and submodules. Typically you have one controller controlling multiple IO devices.
Network Settings Set the properties for the network settings. DeviceName This is the most important setting and defines the device on the network. When IO communication starts the Profinet stack will first look up all the devices on the network by the name. IP Address This is the ipaddress of the device. Subnet mask The subnet mask of the device. Normally it should be set to 255.255.255.0.
MAC Address The MAC Address should be given on the format XX:XX:XX:XX:XX:XX. SendClock The send clock factor is the number to multiply with 31,25 µs that results in the send clock. A send clock factor of 32 will give a send clock of 1 ms. ReductionRatio Reduction ratio applied to the send clock to form the send cycle time. A send clock factor of 32 and a reduction ratio of 32 will give send cycle time of 32 ms.
ModuleType Pick the correct module type for this slot. ModuleClass Pick the Proview Profinet module class for this slot. The class PnModule will be valid for all types of modules. If this is picked, IO channels will automatically be created as children to the PnModule object corresponding to the data area for this module. In many cases there exist prepared subclasses of the PnModuleclass for the specific module. This is for example the case for a Siemens ET200M device.
Profinet viewer There is a tool for searching a network for Profinet devices. In the Proview environment the viewer is started by issuing the command: profinet_viewer [device] Where 'device' is for example eth0. By default the profinet_viewer will connect to eth1. The tool will start searching the network for available devices by issuing a broadcast message. Active devices will respond. After a certain time (a few seconds) you will get a list of the found devices.
Agent object PnControllerSoftingPNAK Agent object for a profinet controller of type Softing Profinet Stack. The object is placed in the nodehierarchy below the $Node object. Device objects PnDevice Baseobject for a profinet device. Reside below a profinet agent object. In the attribute GSDMfile the gsdmlfile for the current device is stated. When the gsdmlfile is supplied the device can be configured by the Profinet configurator. Siemens_ET200S_PnDevice Device object for a Siemens ET200S.
Siemens_Ai2_PnModule Module object for a Siemens ET200 module with 2 analog inputs. Siemens_Ao2_PnModule Module object for a Siemens ET200 module with 2 analog outputs. Siemens_Di4_PnModule Module object for a Siemens ET200 module with 4 digital inputs. Siemens_Di2_PnModule Module object for a Siemens ET200 module with 2 digital inputs. Siemens_Do4_PnModule Module object for a Siemens ET200M module with 4 digital outputs.
Siemens_Ai8_PnModule Module object for a Siemens ET200 module with 8 analog inputs. Siemens_Ao8_PnModule Module object for a Siemens ET200 module with 8 analog outputs. Siemens_Ai4_PnModule Module object for a Siemens ET200 module with 4 analog inputs. Siemens_Ao4_PnModule Module object for a Siemens ET200 module with 4 analog outputs.
Ethernet Powerlink Powerlink is a real time ethernet protocol. Proview implements the openPOWERLINKV1.08.2 stack through Linux userspace, the stack is precompiled with Proview. This make the implementation very flexible as you can use any ethernet NIC. There is no need for special hardware to achieve hardreal time performance. A Powerlink network consists of two devicetypes. A MN (MN = Managing Node) and one or several CN (Controlled Node), max 239 CNs.
Proview as a MN In Proview I/O handling the MN represents the agent level, CN the rack level and the module the card level. When using Proview as a Powerlink MN you create a instance of the Epl_MN class in the Node hierarchy. For every CN connected to the Powerlink network you add objects of the Epl_CN class, or objects of subclass to this class. The CN objects are placed as children to the MN object. Some configuration is done by editing the attributes of this objects.
openCONFIGURATOR (CDCfile) openCONFIGURATOR can be downloaded from http://sourceforge.net/projects/openconf/, it is developed by a company named Kalycito. Below is a guide of how to use openCONFIGURATOR and create a small Powerlink network. You start openCONFIGURATOR by right clicking on a MN object in the nodehierarchy and then click “ConfigureEpl”. You can either create a new project or open a existing.
On the left the Powerlink network of the current project is displayed. Click the MN object, on the right you will now be able to insert the cycle time, after you insert the time press “Save” button. The fastest cycle time available in your Powerlink network depend on the capabilities of the present CNs, how many CNs used in the network and the total size of the process image (The MN stack used by with Proview is tested successfully with cycle times 1 – 100ms).
Click “View” and select “Advanced view”. Right click on one of the CNs and click “Replace with XDC/XDD...”, locate the xdc/xdd file associated with the current CN (provided by the manufacturer). Repeat this for all CNs. Click all CN objects one by one and change the “PollResponse Timeout” to 270us, press “Save” button.
Now you have to create the mapping for the in and output areas. With most CNs you have to create the mapping by yourself. If you want/have to specify what data to be sent and received by the CN you begin by expanding the slave, click the plus sign left of the slave you want to map. Now you can see all the objects located in the slave, some objects is used to configure the slave and some objects contain process data (usually you only map objects containing process data).
The objects containing the mapping is located at the following addresses: 0x1800, 0x1A00, 0x1600, 0x1400, if they don't exist you have to create them manually, this can be done by right clicking on PDO and click “Add PDO...”, enter the address e.g 0x1800 and press “Ok”. For every object you want the CN to send, you have to create a subindex in the 0x1A00 object. Right click on the object with address 0x1A00 and click “Add SubIndex...”, enter 0x01, press “Ok”.
Click the TPDO object and a view of the transmit mapping will visible on the right. Every row represents one object the CN will send, to create more rows you add more subindex to the 0x1A00 object as described above. In each row you input the offset, length, index and subindex of the object you want the CN to send (“Node Id” column should be 0x0, you only change it if you use crosstalk ). The first row always have offset 0x0000 (it is the first object in the output area).
When the mapping is completed you click the subindex objects one by one in the object at address 0x1A00 and 0x1600 and check the box next to the text “Include subindex in CDC generation”. When you've checked all the boxes, the configuration is done. Press “Build Project” button, all of the mapping and configuration will automatically be inserted to the MN obd, a directory (cdc_xap) will be created in the working directory of the project. The configuration file mnobd.cdc is generated in this directory.
All that remains is to insert Epl_Module objects (or subclass objects to this class) as children to the Epl_CN objects (or objects of subclass to Epl_CN). When doing this it is a good idea to compare your nodehierarchy with the xap.h file, they should match. openCONFIGURATOR will 16bit align 16bit variables and 32bit align 32bit variables, it will also 32bit align the whole in and out areas. In Proview you don't have to compensate for the padding variables added by openCONFIGURATOR (added when align).
Modbus TCP Client MODBUS is an application layer messaging protocol that provides client/server communication between devices. Proview implements the MODBUS messaging service over TCP/IP. MODBUS is a request/reply protocol and offers services specified by function codes. For more information on the MODBUS protocol see the documents: MODBUS Application Protocol Specification V1.1b MODBUS Messaging on TCP/IP Implementation Guide V1.
Modules With help of Modbus_Module's you define what type of actions you want to perform on the slave and at which address. The action is defined by a function code which means either reading or writing data to the Modbus slave. You also specify the address at which to read or write. The number of data to be read or written is defined by how you define the data area (see below).
This function code is used to read the contents of a contiguous block of holding registers in a remote device. A register is 2 bytes long. Typically the input data area is defined by a number of ChanIi's which represent the number of registers you want to read. The representation on the ChanIi should be set to UInt16 or Int16. ChanAi and ChanDi is also applicable. In case of ChanDi the representation should be set to Bit16.
1 register (2 bytes) digital input data, 6 lowest bits represent the inputs 1 register (2 bytes) digital input status 1 register (2 bytes) echo digital output 1 register, digital output status 1 register, analog input channel 1 1 register, analog input channel 2 1 register, echo analog output channel 1 1 register, echo analog output channel 2 Output area 1 register digital output data, 6 lowest bits represent the outputs 1 register, analog output channel 1 1 register, analog output channel 2 Configuration T
The input area is configured with channels as shown below. It consists of 6 ChanDi with representation Bit16 and numbered 05 meaning that in the first register (2 bytes, 16 bits) we will read the 6 lowest bits to the channels. The same is done for the statuses of the digital input channels. The rest of the input registers is read with ChanIi's with representation UInt16. The output area is configured as shown below.
Master object Modbus_Master Baseobject for a Modbus master. You need to have a masterobject to be able to handle Modbus TCP communication at all. This is new since version V4.6.0 and was added to be able to handle the slaves in a little bit more intelligent way. Connect which plcthread that will run the communication with the slaves. Slave objects Modbus_TCP_Slave Baseobject for a Modbus slave. Reside in the node hierarchy and is placed as a child to a Modbus_Masterobject.
Module objects Modbus_Module Baseclass for a Modbus module. Placed as child to a slave object. Wanted function code is chosen. See futher information in the help for this class.
Modbus TCP Server With the Modbus TCP Server it is possible for external SCADA and storage systems to fetch data from a Proview system via Modbus TCP. It can also be used to exchange data between Proview systems The server is configured with a Modbus_TCP_Server object in the node hierarchy, and below this with a Modbus_TCP_ServerModule object. Data areas The Modbus_TCP_ServerModule object handles two data areas.
Fig Modbus Server configuration
Fig Modbus Server channel configuration
Hilscher cifX Hilscher cifX is a family of I/O cards handling a number of different I/O buses, CANopen, CC Link, DeviceNet, EtherCAT, EtherNet/IP, Modbus TCP, Powerlink, Profibus, Profinet and Sercos III. The interface to Proview is the same for all the boards and buses. The board and the devices/slaves on the bus are configured in the SYCON.net configurator on Windows. The configuration is exported to a configuration file, that is copied to the process station.
Fig Export the configuration This will create a configuration file, in some cases two files, that should be copied to the process station. cifX driver configuration The Linux cifX driver should be installed on the process station. Follow the instructions to build and load the driver. A directory tree for the driver configuration should be created under opt/cifx. On /opt/cifx the bootloader, eg NETX100BSL.bin, should be placed.
Fig Hilscher cifX configuration The master object contains a Diagnosis object that displays the state of the board. Note that the Status attribute are displayed in decimal form, and has to be converted to hexadecimal form to be identified in the cifX manuals.
Fig cifX diagnosis
MotionControl USB I/O Motion Control USB I/O is a device manufactured by Motion Control, www.motioncontrol.se. The device is connected to the USB port on the pc. The unit contains 21 channels of different types, divided into 3 ports, A, B and C. The first four channels (A1 – A4) are Digital outputs of relay type for voltage up to 230 V. The next four channels (A5 – A8) are Digital inputs with optocouplers.
Card object MotionControl_USBIO The card object is positioned under the rack object. Process should also here be 1 and the object should be connected to a plc thread. State the card identity, that is found on the circuit card, in the Address attribute. The watchdog is activated if a value is set in WatchdogTime, that states the timeout time in seconds. Channels The channels of the card are configured under the card object with channels objects.
RawValRangeLow 0 RawValRangeHigh 1023 ChannelSigValRangeLow 0 ChannelSigValRangeHigh 5 For example, to configure ActualValue range to 0 – 100, set SensorSigValRange 0 5 and ActValRange 0 – 100. Ao configuration The Ao channels has rawvalue range 0 – 5 and signalvalue range 0 – 5, i.e.
Velleman K8055 Velleman K8055 is an USB experiment board with 2 Ai, 5 Di, 8 Do and 2 Ao. It is can be purchased as a kit, K8055, or as an assembled board, VM110. The card can be used to test Proview with some simple application. Note that there are no watchdog or stall function on the board. The board is quite slow, a read write cycle takes about 25 ms. On the board are two switches for address setting, SK5 and SK6.
Process and PlcThread has to be stated. Card object Velleman_K8055_Board Beneath the rack object, a card object of type Velleman_K8055_Board is configured. You can have up to 4 cards in one system. State Process and PlcThread, and state the card address in the Address attribute. Channels All channelobjects reside internally in the card object, Velleman_K8055_Board.
lpwr_cifx_dummy lpwr_nodave_dummy lpwr_epl_dummy Fig Velleman K8055 configuration
Arduino Uno Interface to Arduino USB boards, e.g. Uno and Mega2560. Initialization of the Arduino board Install the Arduino environment on your development station. Connect the Arduino board to the development station and examine the device, normally /dev/ttyACM0 on linux. Open the sketch $pwr_inc/pwr_arduino_uno.ino in the Arduino Development Environment. Select board type in Tools/Board in the menu, and serial port in Tools/Serial Port. Press the Upload button.
See www.arduino.cc for more information. USB port baud rate For scan times faster than 50 ms you need to increase the baud rate of the USB port. The default baud rate of 9600 gives a read write cycle of about 45 ms. By increasing the baud rate to 38400 this time is reduced to 7 ms, which makes it possible to use scan times down to 10 ms. To change the baud rate you –configure the baud rate in the BaudRate attribute in the Arduino_Uno object. –change the baud rate value in the Serial.
Rack object Arduino_USB A Arduino_USB object is configured under the node object. State the Process (Plc) and plc thread in the PlcThread attribute. Card object Arduino_Uno Beneath the rack object, a card object of type Arduino_Uno is configured. You can have several cards in one system. State Process and PlcThread and the device name of the USB port, e.g. /dev/ttyACM0. Channels Digital channels Create channel objects under the Arduino_Uno object.
ChannelSigValRangeLow 0 ChannelSigValRangeHigh 5 Fig Arduino Uno configuration
Fig Arduino Uno channel configuration
GPIO GPIO, General Purpose I/O, are available on some micro processors. As they are connected directly to the processor chip, they have very limited current and voltage tolerance, and are not ideal t use for process control. Usually some intermediate electronic circuit is needed for this type of applications. The GPIO implementation in Proview uses the support for GPIO in the Linux kernel. GPIO has to be specified in the kernel setup.
OneWire 1Wire is a serial bus system with low speed data transfer. The rack level is configured with a OneWire object, and below this, the card objects for components attached to the 1Wire circuit. The 1Wire implementation in Proview uses the support for 1Wire in the Linux kernel. 1Wire has to be specified in the kernel setup. 1Wire devices has an identity that has to be stated in the Address attribute of the card object. The identity should be stated in decimal form.
Fig 1Wire configuration with a DS18B20 temperature sensor
Adaption of I/O systems This section will describe how to add new I/O systems to Proview. Adding a new I/O system requires knowledge of how to create classes in Proview, and baseknowledge of c programming. An I/O system can be added for a single project, for a number of projects, or for the Proview base system. In the latter case you have to install and build from the Proview source code.
connection between the sensor in the plant and the channel on the I/O card, also the signalobjects are connected to the channel object. Plcprograms, HMI and applications refer to the signalobject that represents the component in the plant, not the channelobject, representing a channel on an I/O unit. Area objects Values that are fetched from input units and values that are put out to output units are stored in special area objects.
Methods The task of the methods are to initiate the I/O system, perform reading and writing to the I/O units, and finally disconnect the I/O system. How these tasks are divided, depend on the construction of the I/O system. In a centralized I/O on the local bus, methods for the different card objects can attach the bus and read and write data themselves to their unit, and the methods for the agent and rack object doesn't have much to do.
io_init, function to initiate the framework pwr_tStatus io_init( io_mProcess process, pwr_tObjid thread, io_tCtx *ctx, int relativ_vector, float scan_time ); io_sCtx, the context of the framework struct io_sCtx { io_sAgent *agentlist; /* List of agent structures */ io_mProcess Process; /* Callers process number */ pwr_tObjid Thread; /* Callers thread objid */ int RelativVector; /* Used by plc */ pwr_sNode *Node; /* Pointer to node object */ pwr_sClass_IOHandler *IOHandler; /* Pointer to IO Handler object *
pwr_tUInt32 pwr_tUInt32 int int int io_sCard void struct s_Rack } io_sRack; size; /* Size of rack data area in byte */ offset; /* Offset to rack data area in agent */ scan_interval; /* Interval between scans */ scan_interval_cnt;/* Counter to detect next time to scan */ AgentControlled;/* TRUE if kontrolled by agent */ *cardlist; /* List of card structures */ *Local; /* Pointer to method defined data structure*/ *next; /* Next rack */ Data structure for a card typedef struct s_Card { pwr_tClassId Class; /
class, but there are som common attributes (Process, ThreadObject and Description). In the $ClassDef objects, the Flag word should be stated if it is an agent, rack or card object, and the methods are defined with specific Method objects. It is quite common that several classes in an I/O system share attributes and maybe even methods. An input card that is available with different number of inputs, can often use the same methods. What differs is the number of channel objects.
Fig Example of a cardclass with a superclass an 32 channel objecs Flags In the Flag attribute of the $ClassDef object, the IOAgent bit should be se for agent classes, the IORack bit for rack classes and the IOCard bit for card classes.
Fig IORack bit set for a rack class Attributes Description Attribute of type pwrs:Type$String80. The content is displayed as description in the navigator. Process Attribute of type pwrs:Type$Uint32. States which process should handle the unit. ThreadObject Attribute of type pwrs:Type$Objid. States which thread in the plcprocess should handle the uing. Fig Standard attributes Method objects The method objects are used to identify the methods of the class.
Agents For agents, $Method objects with the name IoAgentInit, IoAgentClose, IoAgentRead and IoAgentWrite are created. Racks For racks, $Method objects with the names IoRackInit, IoRackClose, IoRackRead och IoRackWrite are created. Cards For cards $Method objects with the names IoCardInit, IoCardClose, IoCardRead och IoCardWrite are created.
Fig Connect method Methods For the agent, rack and card classes you write methods in the programming language c. A method is a c function that is common for a class (or several classes) and that is called by the I/O framework for all instances of the class. To keep the I/O handling as flexible as possible, the methods are doing most of the I/O handling work.
static pwr_tStatus IoAgentClose( io_tCtx io_sAgent ctx, *ap) IoAgentRead Read method for an agent. static pwr_tStatus IoAgentRead( io_tCtx io_sAgent ctx, *ap) IoAgentWrite Write method for an agent. static pwr_tStatus IoAgentWrite( io_tCtx io_sAgent ctx, *ap) IoAgentSwap Swap method for an agent.
Cardmetoder IoCardInit static pwr_tStatus IoCardInit( io_tCtx io_sAgent io_sRack io_sCard ctx, *ap, *rp, *cp) IoCardClose static pwr_tStatus IoCardClose( io_tCtx io_sAgent io_sRack io_sCard ctx, *ap, *rp, *cp) IoCardRead static pwr_tStatus IoCardRead( io_tCtx io_sAgent io_sRack io_sCard ctx, *ap, *rp, *cp) IoCardWrite static pwr_tStatus IoCardWrite( io_tCtx io_sAgent io_sRack io_sCard ctx, *ap, *rp, *cp) IoCardSwap static pwr_tStatus IoCardSwap( io_tCtx io_sAgent io_sRack io_sCard io_eEvent ctx, *
Project If the I/O system is a part of a project, the registration is made in a c module that is linked with the plc program. In the example below, the classes Ssab_Rack and Ssab_AiuP are registered in the file ra_plc_user.c #include "pwr.h" #include "rt_io_base.
errh_Info( "Init of IO rack %s", rp>Name); return 1; } /* Close method */ static pwr_tStatus IoRackClose( io_tCtx ctx, io_sAgent *ap, io_sRack *rp) { io_sRackLocal *local; /* Close Qbus driver */ local = rp>Local; close( local>Qbus_fp); free( (char *)local); return 1; } /* Every method to be exported to the workbench should be registered here.
} io_sLocal; /* Init method */ static pwr_tStatus IoCardInit( io_tCtx io_sAgent io_sRack io_sCard { pwr_sClass_Ssab_BaseDiCard *op; io_sLocal *local; int i, j; ctx, *ap, *rp, *cp) op = (pwr_sClass_Ssab_BaseDiCard *) cp>op; local = calloc( 1, sizeof(*local)); cp>Local = local; errh_Info( "Init of di card '%s'", cp>Name); local>Address[0] = op>RegAddress; local>Address[1] = op>RegAddress + 2; local>Qbus_fp = ((io_sRackLocal *)(rp>Local))>Qbus_fp; /* Init filter */ for ( i = 0; i < 2; i++) { /* The
{ io_sLocal *local; io_sRackLocal *r_local = (io_sRackLocal *)(rp>Local); pwr_tUInt16 data = 0; pwr_sClass_Ssab_BaseDiCard *op; pwr_tUInt16 invmask; pwr_tUInt16 convmask; int i; int sts; qbus_io_read rb; pwr_tTime now; local = (io_sLocal *) cp>Local; op = (pwr_sClass_Ssab_BaseDiCard *) cp>op; for ( i = 0; i < 2; i++) { if ( i == 0) { convmask = op>ConvMask1; invmask = op>InvMask1; } else { convmask = op>ConvMask2; invmask = op>InvMask2; if ( !convmask) break; if ( op>MaxNoOfChannels == 16) break; }
/* Filter */ if ( local>Filter[i].Found) io_DiFilter( local>Filter[i].sop, &data, local>Filter[i].Data); /* Move data to valuebase */ io_DiUnpackWord( cp, data, convmask, i); } return 1; } /* Every method to be exported to the workbench should be registred here.
int i, j; op = (pwr_sClass_Ssab_BaseDoCard *) cp>op; local = calloc( 1, sizeof(*local)); cp>Local = local; errh_Info( "Init of do card '%s'", cp>Name); local>Address[0] = op>RegAddress; local>Address[1] = op>RegAddress + 2; local>Qbus_fp = ((io_sRackLocal *)(rp>Local))>Qbus_fp; /* Init filter for Po signals */ for ( i = 0; i < 2; i++) { /* The filter handles one 16bit word */ for ( j = 0; j < 16; j++) { if ( cp>chanlist[i*16+j].SigClass == pwr_cClass_Po) local>Filter[i].
int qbus_io_write int pwr_tTime i; wb; sts; now; local = (io_sLocal *) cp>Local; op = (pwr_sClass_Ssab_BaseDoCard *) cp>op; for ( i = 0; i < 2; i++) { if ( ctx>Node>EmergBreakTrue && ctx>Node>EmergBreakSelect == FIXOUT) { if ( i == 0) data = op>FixedOutValue1; else data = op>FixedOutValue2; } else io_DoPackWord( cp, &data, i); if ( i == 0) { testmask = op>TestMask1; invmask = op>InvMask1; } else { testmask = op>TestMask2; invmask = op>InvMask2; if ( op>MaxNoOfChannels == 16) break; } /* Inver
if ( op>ErrorCount == op>ErrorSoftLimit) errh_Error( "IO Error soft limit reached on card '%s'", cp>Name); if ( op>ErrorCount >= op>ErrorHardLimit) { errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp >Name); ctx>Node>EmergBreakTrue = 1; return IO__ERRDEVICE; } continue; } } return 1; } /* Every method to be exported to the workbench should be registred here.
edit mode and create a VolumeReg object with the name CVolMerk1. The volume identity for user class volumes should chosen in the interval 0.0.2249.1254 and we choose 0.0.99.20 as the identity for our class volume. In the attribute Project the name of our project is stated, mars2. Fig Classvolume registration Open the classvolume Next step is to configure and create the class volume in the project. This is done in the directory volume.
Fig Configuration of the classvolume in the directory volume and start of classeditor In the classeditor classes are defined with specific classdefinition objects. We are going to create two classes, a rack class, MotionControl_USB and a card class MotionControl_USBIO. Note! The class names has to be unique, which actually is not true for these names any more as they exist in the volume OtherIO. Create a rack class In our case the card class will do all the work and contain all the methods.
Fig The IO and IORack bits in Flags Below the $ClassDef object the attributes of the class are defined. We create a $ObjBodyDef object and below this a $Attribute object with the name Description and with type (TypeRef) pwrs:Type $String80.
Fig Attribute object Create a card class There is a baseclass for card objects, Basecomponent:BaseIOCard, that we can use, and that contains the most common attributes in a card object. We create another $ClassDef object with the name MotionControl_USBIO, and set the IOCard and IO bits in the Flags attribute.
Fig The IO and IOCard bits in Flags We create an $ObjBodyDef object and an $Attribute object to state BaseIOCard as a superclass. The attribute is named Super and in TypeRef Basecomponent:ClassBaseIOCard is set. We will now inherit all attributes and methods defined in the class BaseIOCard.
Fig Configration of the superclass BaseIOCard We add another attribute for the card status, and for the status we create an enumeration type, MotionControl_StatusEnum, that contains the various status codes that the status attribute can contain.
Fig Definition of an enumeration type The type of the status attribute is set to the created status type, and in Flags, the bits State and NoEdit is set, as this attribute is not to be set in the configurator, but will be given a value in the runtime environment.
Fig Status attribute of enumeration type Normally you also add attributes for the channel objects in the card class, but as the USB I/O device is so flexible, the same channel can be configured as a Di, Do or Ai channel, we choose not to place the channel objects as attributes. They will be configured as individual objects and placed as children to the card object in the root volume. USB I/O contains a watchdog that will reset the unit if it is not written to within a certain time.
Fig Template object Next step is to add the methods to the class description. While the card contains both inputs and outputs, we need to create Init, Close, Read and Write methods. These will be configured with method objects of type $Method. First we put a $RtMethod object, named IoMethods, under the $ClassDef object. Below this, we create one $RtMethod object for each method. The objects are named IoCardInit, IoCardClose, IoCardRead and IoCardWrite.
Fig I/O method configuration From the superclass BaseIOCard we inherit a method to connect the object to a plc thread in the configurator. Build the classvolume Now the classes are created, and we save, leave edit mode, and create loadfiles for the class volume by activating Functions/Build Volume in the menu. An includefile containing c structs for the classes, $pwrp_inc/pwr_cvolmerk1classes.h, is also created when building the volume.
Write methods The next step is to write the ccode for the methods. The cfile ra_io_m_motioncontrol_usbio.c are created on $pwrp_src. As Proview has a GPL license, also the code for the methods has to be GPL licensed if the program is distributed to other parties. We therefor put a GPL header in the beginning of the file.
// Configure 4 Do and 4 Di on Port A op>Status = USBIO_ConfigDIO( &local>USB_Handle, 1, 240); if ( op>Status) errh_Error( "IO Init Card '%s', Status %d", cp>Name, op>Status); // Configure 8 Ai on Port B op>Status = USBIO_ConfigAI( &local>USB_Handle, 8); if ( op>Status) errh_Error( "IO Init Card '%s', Status %d", cp>Name, op>Status); // Configure 3 Di and 2 Ao on Port C op>Status = USBIO_ConfigDIO( &local>USB_Handle, 3, 7); if ( op>Status) errh_Error( "IO Init Card '%s', Status %d", cp>Name, op
io_sCard *cp) { io_sLocal *local = cp>Local; pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp>op; int value = 0; int i; unsigned int m; pwr_tUInt32 error_count = op>Super.ErrorCount; // Read Di on channel 4 8 op>Status = USBIO_ReadDI( &local>USB_Handle, 1, &value); if ( op>Status) op>Super.ErrorCount++; else { // Set Di value in area object m = 1 << 4; for ( i = 4; i < 8; i++) { *(pwr_tBoolean *)cp>chanlist[i].
if ( op>Super.ErrorCount >= op>Super.ErrorHardLimit) { errh_Error( "IO Card ErrorHardLimit reached '%s', IO stopped", cp>Name); ctx>Node>EmergBreakTrue = 1; return IO__ERRDEVICE; } return IO__SUCCESS; } // Write method static pwr_tStatus IoCardWrite( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp) { io_sLocal *local = cp>Local; pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp>op; int value = 0; float fvalue; int i; unsigned int m; pwr_tUInt32 error_count = op>Super.
cop>OutPolyCoef0; op>Status = USBIO_WriteAO( &local>USB_Handle, 2, fvalue); if ( op>Status) op>Super.ErrorCount++; } // Check Error Soft and Hard Limit // Write warning message if soft limit is reached if ( op>Super.ErrorCount >= op>Super.ErrorSoftLimit && error_count < op>Super.ErrorSoftLimit) errh_Warning( "IO Card ErrorSoftLimit reached, '%s'", cp>Name); // Stop I/O if hard limit is reached if ( op>Super.ErrorCount >= op>Super.
mars2_modules = $(pwrp_obj)/ra_io_m_motioncontrol_usbio.o \ $(pwrp_obj)/rt_io_user.o # Main rule mars2 : $(mars2_modules) @ echo "****** Mars2 modules built ******" # Modules $(pwrp_obj)/ra_io_m_motioncontrol_usbio.o : \ )/ra_io_m_motioncontrol_usbio.c \ $(pwrp_inc)/pwr_cvolmerk1classes.h $(pwrp_src $(pwrp_obj)/rt_io_user.o : $(pwrp_src)/rt_io_user.c Link file We choose to call the methods from the plc process, and have to link the plc program with the object modules of the methods.
Fig The Node hierarchy We set the attribute Number, which states the index in the channel list, to 0 for the first channel object, 1 for the second etc. We set Process to 1 in the rack and card objects, and connects these objects to a plc thread by selecting a PlcThread object, and activating Connect PlcThread in the popup menu for the rack and card object. For the analog channels, ranges for conversion to/from ActualValue unit, has to be stated.
Fig Ai channel When reading the Ao channels, you receive the signal value 05 V, and a configuration for ActualValue range 0100 can be seen in Fig Ao channel.
Fig Ao channel We also have to create signal objects in the plant hierarchy of types Di, Do, Ai and Ao, and connect these to each channel respectively. There also has to be a PlcPgm on the selected thread, to really create a thread in runtime. The remaining activities now are to build the node, distribute, check the linkage of the USB I/O device, connect it to the USB port and start Proview.