Design and development of Sequence Function Chart (SFM) graphical configuration software
2026-04-06 04:33:51··#1
This paper outlines the functions, composition, and programming rules of SFC. It introduces the structure of the graphical system of the developed SFC configuration software. A detailed design scheme for the SFC graphical system and its implementation based on VC++ are presented. Practice shows that the SFC configuration software designed and implemented according to this scheme is flexible in configuration and easy to maintain. I. Introduction Sequential Function Chart (SFC) is a graphical configuration language mainly used for writing upper-level strategy configuration programs for industrial process control. It is widely used in PLC systems and upper-level system configuration software. With the rapid development of 4C technology and the increasing automation in the field of industrial process control, the graphical programming mode of upper-level control systems is increasingly favored by users. Developing SFC configuration software has very practical significance [1, 2]. II. Functions and Composition of SFC SFC uses a graphical method to describe the sequential behavior of a control program, based on Petri nets and the IEC848 standard Grafce, but with necessary modifications. The internal organization of a program is structured, and a control problem is decomposed into several manageable parts while maintaining its overall appearance. These parts consist of "steps" and "transitions". Each transition has certain logical conditions. The functions implemented in each step can be described using other languages such as FBD, LD, ST and IL. III. Composition of the SFC configuration software graphical system SFC provides users with a convenient, fast and intuitive graphical programming mode. Its graphical system is the core of the entire configuration software. The SFC configuration software graphical system developed by the author has the following components, as shown in Figure 1. [align=center][img=286,207]http://www.cechinamag.com/images/Article/0e5ad53a-ebc9-4e28-8b81-cc7024918685/s6.jpg[/img] Figure 1 Composition of the configuration software graphical system[/align] (1) Editing window with good visual effects. In order to provide users with a clean and intuitive programming environment, the editing window should provide users with a good visual effect. (2) User toolbar. (3) User right-click shortcut menu. (4) Horizontal and vertical rulers. The setting of horizontal and vertical rulers facilitates users' navigation in the editor, and at the same time has the function of selecting the whole row and the whole column. IV. SFC Graphic System Design Scheme(I) Determination of Language Element Management Mode The management of the SFC graphics system mainly solves the object management problem caused by the addition, deletion, and movement of language element single units and macro bodies. There are two modes to choose from: one-dimensional linear mode and two-dimensional planar mode. In terms of storage management, both use linked lists and arrays, the difference lies in the mechanism of searching and locating language element objects. 1. One-dimensional linear mode In this management mode, all language element objects are distributed in several different types of linked lists and arrays for storage. When searching and locating a certain type of language element object, the linked list itself and the array itself are used directly for operation: the search or traversal method is used to obtain the language element object that meets the conditions. This mode saves memory and the program is easy to implement. However, the running efficiency is not high when there are many language element objects. 2. Two-Dimensional Plane Mode In this management mode, in addition to distributing all language element objects into several different types of linked lists and arrays for storage, a "grid map" is also established in memory to form a mapping from the display position of each element in the editing area to its logical address in memory. When searching for or locating a certain type of language element object, the grid map is used to quickly locate the corresponding language element object in memory. This mode consumes more memory; however, it can greatly improve the efficiency of software operation when there are many language element objects and facilitates the management of language element objects. Considering that users frequently perform various operations on language elements during software operation, the memory location calculation of language elements is very frequent, and the efficiency of software operation is a very important indicator. However, the scale of general SFC programs is usually not very large, so the two-dimensional planar language element management mode was selected and determined to be used in this software. The graphical representation of grid information is shown in Figure 2. [align=center] [img=265,54]http://www.cechinamag.com/images/Article/0e5ad53a-ebc9-4e28-8b81-cc7024918685/s7.jpg[/img] Figure 2 Graphical representation of grid information[/align] According to the SFC programming rules, each grid can only store a maximum of 3 language elements. Therefore, the grid is divided into three parts: upper, middle, and lower. Each part stores two important descriptive information about the language element at that location: the type of the language element and the index value of the language element in the corresponding linked list and array. (II) Operations of basic language elements1. Selection, addition, deletion, attribute modification, and movement of individual and macro blocks of language element objects • Selection operations: including clicking, dragging with a "rubber band", using horizontal or vertical rulers, and shortcut buttons in the upper left corner of the editing area. • Add Operation: Select a language element from the language toolbox, click within the client editing area, and a new individual will be added to the corresponding language element object array, automatically configuring certain data of the object (such as grid position coordinates, selection status, etc.). • Delete Operation: Selected objects can be deleted using the keyboard, the "Edit" menu, or the right-click shortcut menu. • Attribute Configuration and Modification: The "Attribute Configuration" dialog box allows for the configuration and modification of language element attributes. • Move Operations: This includes moving individual language element objects and moving macros composed of multiple objects. Because SFC programming has certain rules, the relative positions of language elements must adhere to a rather complex set of rules (e.g., two steps cannot be directly connected), and cannot be placed arbitrarily. Therefore, the design must not only comprehensively consider the rules but also prioritize user convenience. 2. Dynamic Scaling of "Branch" and "Join" Elements: The "branch" ([table][tr][td][/td][/tr][/table]) and "joint" ([table][tr][td][/td][/tr][/table]) elements in SFC language elements have characteristics different from other language elements. Because these two elements can have multiple branch points (a "branch" can have multiple branch points, and a "joint" can have multiple join points), their design and implementation should include dynamic scaling capabilities. (III) Automatic Connection Function Between Language Elements Some elements in SFC language elements can be directly connected. For example, consider two language elements A and B. Element A's grid coordinates in the editing area are (x, y, z1), and element B's grid coordinates are (x, y+1, z2). Here, z1 and z2 are the hierarchy values within the grid (0, 1, 2 represent the upper, middle, and lower levels, respectively). The values of z1 and z2 ensure that A and B are not directly adjacent on the grid diagram. When A and B meet certain conditions, a direct connection can be established between them. Many language elements in SFC possess this direct connection property. This design uses a rule-based algorithm. After adding or moving a language element, it checks whether there are directly connectable elements in the upper and lower grids of that element; if so, a connection is automatically established between the two elements. (IV) Language Element Function Groups To improve user programming efficiency, several language elements are combined to form language element function groups, which are provided to users in the form of macroblocks, such as step-transformation function groups and branch-merge function groups. Function groups containing different numbers of language elements are obtained by setting the group size. (V) Long Connection Function During user programming, the distribution of SFC language elements is not always directly adjacent between grids. For example, for any two language elements A and B, A's grid coordinates in the editing area are (x, y, z1), and B's grid coordinates in the editing area are (x, y+n, z2) (n≥2). When A and B meet the connection condition, a long connection can be formed between A and B. 1. Determining the Connection Direction. The direction of the connection to be implemented by the user is determined based on the mouse input position of the starting element of the connection. It is not necessary to precisely position the mouse input position on the connection terminal of the element; the software can automatically determine the direction of the connection as long as the mouse is within the upper or lower area of the element block. 2. Automatically determines whether a connection to the endpoint element is possible. Once the connection starting point is determined, an intelligent algorithm automatically determines whether the element at the current mouse position can be the endpoint element, and prompts the user through mouse cursor deformation. 3. Visualized connection design. 4. Support for fuzzy user input. Users do not need to precisely position the mouse input position on the element's connection terminal; they only need to be within the upper or lower area of the element block and confirm, and the software can precisely connect the line to the upper or lower connection terminal of the element. (VI) Clipboard Function and OLE Drag and Drop To facilitate user operation, clipboard and drag-and-drop functionality is provided for SFC elements in various languages, allowing users to easily and quickly transfer and share data across multiple SFC configuration sub-windows. (VII) Text Annotation Function In terms of design implementation, the text annotation function and the SFC language element function are separated and managed separately. In terms of display mode, two layers are used: the top SFC language element layer and the bottom user annotation layer. The two layers can be displayed and hidden through the optional layer switching function. The text annotation function includes adding, deleting, moving, and commenting. The operation of text annotation in the editing area does not affect the language element. V.SFC [b]Graphics system based on VC++[/b] The configuration scheme is implemented using the VC++ language. The highly user-friendly integrated development environment and powerful functions of VC++ greatly improve the efficiency of users in software development. Due to space limitations, only the VC++ implementation of some important items in the functional design is given here [3]. (I) Construction of basic language element objects Using C++, the language elements are abstracted into C++ classes. One base class and seven subclasses derived from this base class are constructed, corresponding to the seven basic language elements in SFC. The base class CSFCComponent describes the basic characteristics of the SFC language elements in the graphics system: Class CSFCComponent { Public: BYTE m_Grid Y; //Grid coordinates X BYTE m_Grid X [table][tr][td][/td][/tr][/table];//Grid coordinates Y Bool m_bSelected;//Selection state CSFCComponent(); virtual~CSFCComponent(); }; The three language elements of step, transition, and jump are quite similar. In addition to inheriting all the properties of CSFCComponent, they also have other unique properties. The following is an example of the construction of step. Construction of step object: Class CSFCSterx public CSFCComponent { public …//Other properties of step object Void Draw(CDC* pdc, int index, int grid_width, int grid_height); CSFCStep(); virtual~CSFCStep(); }; Parallel branch, parallel merge, single branch, and single merge are quite similar. The following is an example of the construction of parallel branch. Class CSFCParallelbranch public CSFCComponent { public Void Draw(CDC* pdc, int grid_width, int grid_height); BYTE m_GridNum; // Number of grids spanned CSFCParallelbranch(); virtual ~CSFCParallelbranch(); }; A connection object is a special type of object that implements connections between language elements. It is constructed as follows: Class CSFCLink { public void Draw(CDC* pdc, int grid_width, int grid_height); BYTE gridx; // Position coordinates of the connected language element; BYTE gridy_upper, gridy_lower; // Upper and lower position coordinates of the connected language element BYTE layer_upper, layer_lower; // Grid level values of the connected language element; CSFCLink(); &nbs [table][tr][td][/td][/tr][/table]p; virtual ~CSFCLink(); }; (II) Implementation of the Two-Dimensional Plane Management Mode for Language Element Objects Construct the following data structure to represent the grid information in the grid map. Type def strict GRID_INFO { Selector component_type[3]; // The type of language element. The three elements represent the upper, middle, and lower levels of the grid, respectively. WORD array_index[3]; // The index value of the language element in the linked list or array of its corresponding type. It is used as the logical address of the language element in memory. The three elements represent the index value of the language element in the corresponding array in the upper, middle, and lower levels of the grid, respectively. }; This grid map constitutes a mapping from the display position of each element in the editing area to the logical address of its memory distribution. Among them, selector is the SFC language element selector, an enumeration type, defined as follows. Typedef enum selector{ null, mouse_select, step, transition, parallel_branch, parallel_joint, alternative_branch, alternative_joint, jump, link, text step_transition_group, transition_step_group, alternative_group, text_move, text_rubberbcandselect, longlink_cut}; When a user selects different language elements in the SFC language element toolbox, the currently selected sub-variable takes different values. The collection of grids constitutes a grid map, defined as follows: GRID_INFO**m_GridMap. Its program implementation is: This->m_GridMap = (GRID_INFO**)::malloc(size of (void*)*this->m_gridy_num); for (int y = 0; y <= this->m_gridy_num - 1; y++) { this->m_GridMap[y] = (GRID_INFO*)::malloc(size of (GRID_INFO)*this->m_gridx_num); } // Initialize the grid map: for (y = 0; y <= this->m_gridy_num - 1; y++) { ::memset(this->m_GridMap[y], 0, size of (GRID_INFO)*this->m_gridx_num); } (III) Implementation of Clipboard Function and OLE Drag and Drop In the SFC configurator project, clipboard function and OLE drag and drop for SFC basic language elements and text annotation objects were implemented. Since SFC basic language elements and text belong to two different categories, two different design implementation modes were adopted for their clipboard and operations. The clipboard and OLE operation of text uses the clipboard format defined by the Windows system level to realize data transmission and sharing within and between processes. This technology is relatively mature and easy to implement. However, for data objects composed of basic language elements, their data format is custom and not within the scope of the system-level clipboard format. Custom data transmission format is required [4]. Research, analysis and experiments have concluded that to realize data sharing outside the system-level clipboard format, the following two key links should be implemented: (1) Define a clipboard format to identify the clipping operation to be performed by the user and the address of the user data area in the system. (2) Implement the data sharing protocol between the data generator and the user, and customize the format of the entity data put into the clipboard. The data types in the SFC configurator are numerous and the content is relatively complex. Each element must adhere to strict logical sorting rules. When designing and implementing clipboard and OLE drag-and-drop functions, comprehensive consideration should be given. In addition to copying and cutting the SFC component currently selected by the user to the clipboard, the connection and sorting position of the elements before copying and cutting should also be recorded on the clipboard. Based on this, a clipboard format named "sfc_selected_components" was defined in this project. During copy/cut operations, the following steps are performed: ① Register the clipboard format; ② Open the clipboard; ③ Clear the clipboard; ④ Calculate the amount of global memory to be used based on the data of the object to be operated; ⑤ Release the memory allocated last time and allocate the memory required for this operation; ⑥ Store the data; ⑦ Close the clipboard. Compared with the clipboard, the implementation of OLE drag-and-drop technology is basically the same in terms of data access principle, but the form is more concise. The main difference lies in the way the system global address of data storage is passed. In addition, the OLE drag-and-drop protocol is relatively simple and does not involve compatibility issues with other data types [5]. (IV) Text Annotation Function The text annotation object is constructed as follows: Class CText { Public: CRect m_rec; // Uses the large scroll coordinate system as the reference, not the local small coordinate system DWORD text_color; LOGFONT if; // Records the font data used for text display Bool m_bSelected; // Whether selected: default false CPoint top_left; // Records the top left corner position of the text CString text; // Text content, default is empty CRect jisuan_rect(CPoint, point, int hangshu, CString longest_str, CDC* pdc); Void draw(CDC* pdc); CText(); virtual~CText(); }; Class CSFCText public CText { public: void draw(CDC* pdc); CSFCText(); virtual~CSFCText(); } The copy, cut, and paste operations of the text annotation object are implemented in the CopyText, CutText, and PasteText functions of CSF-CView. VI. Conclusion The design scheme and implementation based on VC++ of the SFC configuration software graphical system described above have been fully implemented in the SFC subsystem of the "WorldFIP Fieldbus Control System Upper Strategy Configuration Software" developed by the author, and have been applied to the engineering configuration of the WorldFIP fieldbus control system. Practice shows that the SFC configuration software designed and implemented according to this scheme is flexible and easy to maintain. It is user-friendly, highly convenient and intuitive in human-machine interface, which greatly improves the efficiency of user configuration programming and has great promotion and application value. References [1] Wang Jinbiao. Fieldbus and Fieldbus Control System [J]. Chemical Automation and Instrumentation, 1997, (2). [2] Fang Laihua, Wu Aiguo, He Yi. Research on Core Technology of Configuration Software [J]. Chemical Automation and Instrumentation, 2004, (1). [3] Qi Shu Studio. VC++6.0 Development Techniques and Case Analysis [M]. Beijing: Tsinghua University Press, 1999. [4] New WINDOWS API Reference Compilation Group. New WINDOWS API Reference Complete Collection [M]. Beijing: Electronic Industry Press, 2000. [5] Pan Aimin. COM Principles and Applications [M]. Beijing: Tsinghua University Press, 1999.