my code is set in a way that the on state is only 20ms. Can I just apply a +5V at the gate and check if there is 12V difference between drain and source?
That's a very odd way to connect the transistor of an opto-isolator, with the resistor in the emitter. This is because the emitter voltage is always about 0.7v below the base. You should really put the resistor in the collector with one end to Vcc, and ground the emitter. This way you should better saturate the transistor and get maximum voltage swing driving the MOSFETs. You will though have to invert the logic of the drive from the processor. It may be that with your configuration the MOSFETs aren't getting enough gate drive.
Also if you are concerned to release a solenoid quickly, connecting the flywheel diode directly across the coil actually delays the turn-off as the diode just forward biases when the FET turns off and the solenoid current just keeps flowing while the energy stored in the magnetic field dissipates. If you put a resistor in series with the diode it dissipates the energy quicker and the solenoid can release more quickly as the time constant L/R is shorter. You can make the resistor quite high as long as you respect the peak Vdd of the FETs. For 300mA and 12v, a 100R resistor would allow the drain voltage to peak at 42v, so as long as the FET can stand that you're OK. If not reduce the resistor - if you made it the same as the solenoid coil resistance you would double the voltage on the FET momentarily.
I did not know it. I might try it for net projects. For this one I won't.
In the configuration you suggested there is no resistor at the Mosfet Gate to ground?
I did the above - I put a 5V from the Arduino 5V pin at the anode pin of the optocoupler (I was reading 4.75V which make sense as there is the diode voltage drop)
I then placed the red prob of the DMM at the Drain of the Mosfet and the black prob on the Mosfet Source. I read only 2V. Those it make sense?
No it isn't odd, that 6K8 resistor keeps the gate of the MOSFET connected to the source when the opto transistor is open.
Otherwise the gate will not turn OFF.
It has nothing to do with the opto transistor volt drop.
In the common emitter connection, provided the LED is being sufficiently driven, the transistor will saturate with a collector load of 6k8 or 10k. Its collector voltage would then be about +0.3v. The minimum gate threshold voltage of the FET is 1v for 250 microamps IDS according to its data sheet so it would be turned well off at this voltage. When the LED is not being driven the collector voltage will go to Vcc2 - if that is 5v say then the FET will be well turned on. The only benefit I can see of the common collector config is that the FET is off if the Arduino is disconnected.
@jhaine
When the opto led is ON, the opto transistor is ON and the gate of the MOSFET is pulled to VCC2.
The MOSFET turns ON.
When the opto led is OFF, the opto transistor is OFF and the gate of the MOSFET is pulled to GND2.
The MOSFET turns OFF.