problem with sending SMS by serial port devices

I use sim900 module for sending SMS. But sometimes Vera cannot communicate with the module and crashes.I use luup code for sending SMS by SIM900 . my luup code is:
function send_sms(phone_number, user_name)
2 – both phone_number and user_name are strings
3 local sid = “urn:micasaverde-com:serviceId:SimpleSerial1”
4 local did = 162
5 – first check is modem is alive
6 kwikLog(“Running function send sms…”,true)
7 luup.call_action(sid,“Send”, {Message = “at”}, did)
8 – wait until modem replies
9 repeat
10 local rcv_data = luup.variable_get (sid, “Received”, did)
11 kwikLog(“waiting for answer from modem… " … rcv_data)
12 until (rcv_data == “OK”)
13 --14 kwikLog(“Modem is alive!”)
15 --16 – concatenate the phone number and SMS com mand
17 number_string = “at+cmgs=” … '”’ … phone_number … ‘"’
18 – now initiate text message to the given number
19 luup.call_action(sid,“Send”, {Message = number_string}, did)
20 repeat
21 local rcv_data = luup.variable_get (sid, “Received”, did)
22 kwikLog("waiting for answer from modem… " … rcv_data)
23 until (rcv_data ~= “”)
24 kwikLog(“Now it’s ready to send the text message…”)
25 –
26 warning_msg = “Attention!! An alarm is active!” … string.char(0x1a)
27 luup.call_action(sid,“Send”, {Message = warning_msg}, did)
28 repeat
29 local rcv_data = luup.variable_get (sid, “Received”, did)
30 kwikLog("waiting for answer from modem… " … rcv_data)
31 until (rcv_data == “OK”)
32 kwikLog(“Message delivered successfully!”)
33 end
I need to know how I can prevent from crashing Vera?