## 2 Materials and Methods
### System Design
#### 2.1.4 Function Design and Software Design  
The motor position of M2, and the current of the gold mesh and PD can be accessed through the Experimental Physics and Industrial Control System (EPICS) [33]. EPICS is an open-source, distributed software framework that is widely used in the control of large-scale scientific facilities in order to access and control devices through networks. EPICS provides a standardized, extensible interface that enables different types of devices and control systems to communicate and work together, and it also provides a rich set of tools and libraries, such as Channel Access, Database Access, Alarm Handler, Archive Engine, etc., to facilitate development and management. Voltage signals of \(\mathrm{S_{L}}\) and \(\mathrm{S_{R}}\), collected by Moxa ioLogik E2240 controller, can be read out through a MXIO library provided by Moxa. The software of the automatic feedback system was developed in Browser/Server (B/S) architecture with Flask ([[https://flask.palletsprojects.com](https://flask.palletsprojects.com)]([https://flask.palletsprojects.com](https://flask.palletsprojects.com)), accessed on 30 December 2022) and React ([[https://reactjs.org](https://reactjs.org)]([https://reactjs.org](https://reactjs.org)), accessed on 30 December 2022). Flask is a micro web framework written in Python. It is designed to be lightweight and easy to use, making it a popular choice for building web applications and APIs. Flask provides a simple and flexible interface for developers to create web applications, with features such as URL routing, template rendering, and support for extensions. React is an open-source JavaScript library for building user interfaces. It is designed to be declarative and efficient, allowing developers to build complex user interfaces with ease. React uses a virtual DOM (document object model) to optimize the rendering performance, and supports server-side rendering and mobile development. As the control software for the spectroscopic end station and STXM end stations are separated on different computers, the B/S architecture is more convenient for operating across multiple computers and control systems. Users can easily download the data of all signals in CSV format from the browser for further research. Additionally, all signals will be recorded in seconds and stored in a local SQLite database after the server starts. This ensures that all data are safely stored and easily accessible for future analysis. During the implementation of the feedback logic, a threshold value limitation was added to prevent M2 from vibrating around its optimal position and reducing the motor return difference. Additionally, an offset for \(\mathrm{S_{RL}}\) was added as a calibration of light flux since the signal of the mesh grid may not be accurate based on the incident position at the mesh structure. The details of these two improvements and some tests are discussed in Section 2.2. In order to avoid errors in the operation of the automatic dimming program,  
Figure 4: The measurement results of the left and right blade voltage signals and gold mesh current signal \(\mathrm{I_{0}}\), along with M2 position changes at 920 eV. When the signals of the left and right blade are equal, the corresponding gold mesh signal is almost at the maximum value. an alarm signal output is set in the program. An error signal is activated and sent to the imaging or XAS end stations when the \(\mathrm{S_{V}}\) exceeds 30%. Figure 5 illustrates the procedure of the tunning loop. The user can set the step of the M2 motor, offset and \(\mathrm{V_{0}}\) in the browser user interface and operate the feedback system. When the system is turned on, a feedback request with the parameters of the step, offset and \(\mathrm{V_{0}}\) is sent to the server. The server then immediately reads out all signals and checks the threshold value limitation. If the \(\mathrm{S_{V}}\) is greater than \(\mathrm{V_{0}}\), M2 must move one step accordingly and finishes one feedback request.