C++ Program Seems to Overload PLC?
I am working on a project and the goal is to create a waterfall that can change the flow of the water to look like a user imported image, similar to the one here 
In order to channge the flow of the water we are using solenoids, about 200 of them. I wrote a c++ program that takes a user uploaded image and converts into a 2d array of 1s and 0s. Then using a for loop it reads to each solenoid row by row the value in the array. if the value is 1 it will send TRUE to the solenoid so it can open or stay open then if its 0 it will send FALSE to the solenoid so it can close or stay close.
After building the program in eclipse and trying to run it on the plc we ran into an issue where all of the connected outputs would turn on then turn off then display a BF-D error. After this we tried to run a simple code that uses structured text to just turn on and off all of the solenoids and we were not getting any responce(this code usually works). When turned the plc off and back on it seemed to try and run the PLC program again but just ended up doing the samething turning on then turning off.
Attached below is the code for the program that we tried to run on the plc, this code is motified version that used the array from the start instead of using opencv for the image converion and also a gif of what happened to the PLC is attached as well, in this video we did not connect all of port to an output on the I/O module because we were trouble shooting to see if it was power problem.
The I/Os being used are two DO16/1 five DO32/1 and one DI8/1 DO8/1
edit: Tried to upload the code in a .txt file but it said unsupported format. Also the code is set to wait 20ms before reading the next row.

In order to channge the flow of the water we are using solenoids, about 200 of them. I wrote a c++ program that takes a user uploaded image and converts into a 2d array of 1s and 0s. Then using a for loop it reads to each solenoid row by row the value in the array. if the value is 1 it will send TRUE to the solenoid so it can open or stay open then if its 0 it will send FALSE to the solenoid so it can close or stay close.
After building the program in eclipse and trying to run it on the plc we ran into an issue where all of the connected outputs would turn on then turn off then display a BF-D error. After this we tried to run a simple code that uses structured text to just turn on and off all of the solenoids and we were not getting any responce(this code usually works). When turned the plc off and back on it seemed to try and run the PLC program again but just ended up doing the samething turning on then turning off.
Attached below is the code for the program that we tried to run on the plc, this code is motified version that used the array from the start instead of using opencv for the image converion and also a gif of what happened to the PLC is attached as well, in this video we did not connect all of port to an output on the I/O module because we were trouble shooting to see if it was power problem.
The I/Os being used are two DO16/1 five DO32/1 and one DI8/1 DO8/1
edit: Tried to upload the code in a .txt file but it said unsupported format. Also the code is set to wait 20ms before reading the next row.
Comments
I'm wondering if there is some sort of power issue, which might be "solved" by unplugging all the output devices.
Do you have a diagram showing the DC power distribution to the PLC and all the I/O modules?
How much current is drawn by each solenoid?
How are the solenoids wired to the I/O modules? Are there any interposing relays, or back-emf suppression devices? (a diagram might be useful)
Are there any clues in the Output.log file on the PLC, that might indicate a problem?
If you would prefer to send us this information directly by email, please let us know.
Also, it would be worth contacting a technical specialist from your local Phoenix Contact office. They can usually give personal support on application-specific issues like this.
Though attached or some schematics on how we set everything up
The diagram shows the old plc we are now using a plcnext controller
Is there any information in the Output.log file on the PLC that indicates what the problem might be?
Also for the C++ code I used "usleep(20000)" in order to set a delay before reading another row could this be a possible error?
I can highly recommend getting in touch with a technical specialist in your local Phoenix Contact office. They can usually offer personal support on application-specific issues like this.