1 / 10

Example asyn driver Modbus

Example asyn driver Modbus. Mark Rivers, Marty Kraimer, Eric Norum University of Chicago Advanced Photon Source. Modbus. MODBUS is an application layer messaging protocol Positioned at level 7 of the OSI model

jerzy
Download Presentation

Example asyn driver Modbus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example asyn driver Modbus Mark Rivers, Marty Kraimer, Eric Norum University of Chicago Advanced Photon Source SLAC asyn class, Day 1, August 26, 2010

  2. Modbus • MODBUS is an application layer messaging protocol • Positioned at level 7 of the OSI model • Provides client/server communication between devices connected on different types of buses or networks • Typically used for communication with I/O systems, including Programmable Logic Controllers (PLCs) • Supports following communication links: • TCPTCP/IP using standard port 502. • Serial RTU protocol, using RS-232, RS-422, or RS-485. • Directly transmits each byte as 8 data bits, so uses "binary" rather than ASCII encoding. • Start and end of message frames is detected by timing rather than by specific characters. • Serial ASCII protocol, using RS-232, RS-422, or RS-485. • Encodes each byte as 2 ASCII characters. • Start and end of message frames is detected by specific characters (":" to start a message and CR/LF to end a message). • Less efficient than RTU, but may be more reliable in some environments. SLAC asyn class, Day 1, August 26, 2010

  3. Modbus • Data types • Single bits • 16-bit registers • Modbus communications • Request message sent from the Modbus client to the Modbus server. • Server replies with a response message. • Modbus request messages contain: • An 8-bit Modbus function code that describes the type of data transfer to be performed. • A 16-bit Modbus address that describes the location in the server to read or write data from. • For write operations, the data to be transferred. SLAC asyn class, Day 1, August 26, 2010

  4. Modbus SLAC asyn class, Day 1, August 26, 2010

  5. SLAC asyn class, Day 1, August 26, 2010 Other PLC manufacturers will use different Modbus addresses. Other PLC manufacturers will use different Modbus addresses.

  6. SLAC asyn class, Day 1, August 26, 2010 Other PLC manufacturers will use different Modbus addresses. Other PLC manufacturers will use different Modbus addresses. Other PLC manufacturers will use different Modbus addresses.

  7. Modbus asyn Driver Architecture • EPICS asyn device support • General purpose device support provided with asyn • No special device support needed or provided with modbus. • EPICS asyn port driver that functions as a Modbus client. • Communicates with EPICS device support (layer 1) using the standard asyn interfaces (asynUInt32Digital, asynInt32, etc.). • Sends and receives device-independent Modbus frames via the standard asynOctet interface to the "interpose interface" (layer 3). • These frames are independent of the underlying communications protocol • One asyn driver handles a single function code and contiguous Modbus address range • asyn "interpose interface" layer • Handles the additional data required by the underlying communications layer (TCP, RTU, ASCII). • Communicates via the standard asynOctet interface to both the overlying Modbus driver (layer 2) and to the underlying asyn hardware port driver (layer 4). • asyn port driver • handles the low-level communication (TCP/IP or serial). • One of the standard port drivers provided with asyn, i.e. drvAsynIPPort or drvAsynSerialPort, not part of modbus package SLAC asyn class, Day 1, August 26, 2010

  8. Modbus Read Function Codes • For read function codes the driver spawns a poller thread. • Poller thread reads the entire block of Modbus memory assigned to this port in a single Modbus transaction. • Values stored in a buffer in the driver. • Delay between polls is set when the port driver is created, and can be changed later at run-time. • Values are read by EPICS using the standard asyn interfaces (asynUInt32Digital, asynInt32, etc.) • Values that are read are the last stored values from the poller thread. • EPICS read operations are thus synchronous, i.e. they do not block because no Modbus I/O is required. • For read functions it is possible to set the EPICS records to "I/O Intr" scanning. • Improves efficiency, because such records only process when needed, they do not need to be periodically scanned. SLAC asyn class, Day 1, August 26, 2010

  9. Modbus Write Function Codes • For write function codes the driver does not itself create a separate thread. • Driver does the Modbus I/O immediately in response to the write operations on the standard asyn interfaces. • This means that EPICS write operations are asynchronous, i.e. they do block because Modbus I/O is required. • When the modbus driver is created it tells asynManager that it can block, and asynManager creates a separate thread that executes the write operations. • Word write operations using the asynUInt32Digital interface (with a mask parameter that is not 0x0 or 0xFFFF) are done using read/modify/write operations. • Allows multiple Modbus clients to write and read single words in the same block of Modbus memory. • However, it does not guarantee correct operation if multiple Modbus clients (or the PLC itself) can modify bits within a single word. • This is because the Modbus server cannot perform the read/modify/write I/O as an atomic operation at the level of the Modbus client. • For write operations it is possible to specify that a single read operation should be done when the port driver is created. • This is normally used so that EPICS obtains the current value of an output device when the IOC is SLAC asyn class, Day 1, August 26, 2010

  10. Modbus Write Function Codes • For write function codes the driver does not itself create a separate thread. • Driver does the Modbus I/O immediately in response to the write operations on the standard asyn interfaces. • This means that EPICS write operations are asynchronous, i.e. they do block because Modbus I/O is required. • When the modbus driver is created it tells asynManager that it can block, and asynManager creates a separate thread that executes the write operations. • Word write operations using the asynUInt32Digital interface (with a mask parameter that is not 0x0 or 0xFFFF) are done using read/modify/write operations. • Allows multiple Modbus clients to write and read single words in the same block of Modbus memory. • However, it does not guarantee correct operation if multiple Modbus clients (or the PLC itself) can modify bits within a single word. • This is because the Modbus server cannot perform the read/modify/write I/O as an atomic operation at the level of the Modbus client. • For write operations it is possible to specify that a single read operation should be done when the port driver is created. • This is normally used so that EPICS obtains the current value of an output device when the IOC is SLAC asyn class, Day 1, August 26, 2010

More Related