Just a quick read through...
You do not reset "a" to zero after this routine, think what will happen the next time this routine is called, when a=6.
Code:
seroutrpt: if a<=5 then 'sends serout command 5 times
serout OUT, 2,["~",module]
a=a+1
goto seroutrpt
endif