Current methods of manually checking whether materials meet the required standards are inefficient and harmful to workers' health. To address the complexity and variability of real-world systems, it is imperative to establish highly consistent digital models for subsequent operations. However, there is a challenge in unifying various modules and components into a single system and optimizing them for functionality. A mechatronic solution is proposed for material sorting within the production manufacturing process, leveraging Siemens TIA Portal and NX 2007. The solution involves constructing a physical platform and realizing a digital twin system to enable real-virtual interaction via communication protocols. Initially, a virtual material sorting simulation and debugging platform is established using NX software, while operations are conducted in the TIA Portal. Subsequently, the control program is designed within the TIA Portal, and Virtual PLCs are created using PLCSIM Advanced for virtual debugging and analysis, confirming the solution's feasibility. Following this, the physical material sorting platform is developed, utilizing Siemens S7-1500 PLC to manage inverter and servo motor operations. Ultimately, the OPC UA communication protocol facilitates information exchange between the physical PLC and the virtual platform, establishing effective linkage between the virtual system and the physical model to ensure coordination and consistency. Results demonstrate real-time synchronization and virtual sorting operations during joint real-virtual debugging. This digital twin design solution is poised to significantly enhance manufacturing efficiency, reduce initial hardware costs in factory design, and augment automation and intelligence in production.