Do what you can to structure payment so that you are never upside down enough to care. The best way to do that is to make "programming and configuration" the final stage of the project. Make sure all hardware and labor has been paid for and then begin the final stage.
This should guarantee that the only thing owed to you is labor for "bringing the system online". If the client refuses to pay you for this once you are done...awesome. You never have to spend another dollar supporting the system.
Adding... this system also keeps the CI honest. The clients install is done and every part has been ordered and connected. Client doesn't have to worry about the CI never finishing the project.
Avid Stamp Collector - I really love 39 Cent Stamps