As you may know Heidenhain controllers by design have no built in part counter. However, the most recent CNCnetPDM device driver for Heidenhain TNC and iTNC devices now allows you to automatically acquire part counter data without any user intervention required at the machine.
FIG 1: Workpiece counter output (TNC 640)
The technique can be setup in a few steps and works reliable for older TNC 426, 430 and newer iTNC 530, TNC 320, 620 and 640 controllers.