I think your problem is that you are not waiting for the final result code (i.e. OK, ERROR and a few others) before sending the next command. The problem with that is that the new command will trigger an abort of the ongoing command if it is not finished. To quote V.250:
5.6.1 Aborting commands
...
Aborting
of commands is accomplished by the
transmission from the DTE to the DCE
of any character.
So ALWAYS when sending AT commands, you MUST wait for the final result code before sending the next command.
Might I suggest refactoring serialport.WriteLine("ATxxx" + Environment.NewLine)
into a sendCommand(serialport, "ATxxx")
function? And then you can add waiting for the final result code at the end of that function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…