Analyse DIALTONE and BUSY during dialing

My * connected to old office PBX via SPA400, and office PBX connected to old public PBX.

During making long distance call I need to dial to public PBX “8” and wait DIALTONE before continue send digits. Some times insted of DIALTONE PBX send BUSY and I had to start dialing from the very begining.

So question is how to detect DIALTONE and BUSY and how to make pause to wait for them ?

Time after sending “8” and receiving DIALTONE or BUSY varies from about 1 to 10 seconds.