In modern manufacturing the ability of retracing produced components is crucial for quality management and process optimization. Tracking is essential, especially for analyzing the influence of the production parameters on the final quality of the castings. In the iron foundry industry, common marking methods, such as a datamatrix code, cannot be used due to harsh environmental conditions and the rough surface of the cast parts. This work presents a new coding and reading system that guarantees unique marking in the casting process.The coding is built up over several beveled pins and is read out using an optical 2D handheld scanner. With a deep convolutional neural network approach of object detection and classification, a stable image processing algorithm is presented. With a first prototype a reading accuracy of 99.86% for each pin was achieved with an average scanning time of 0.43 s. The presented code is compatible with existing foundry processes, while the handheld scanner is intuitive and reliable. This allows immediate benefits for process optimization.