Hi folks, I work on MCP based on Arduino. I read/write offsets through FSUIPC by LUA script. Unfortunately I have one problem. I tried to explain it with parking brake. I have on push button. The code in arduino:

Code:
...
void pushButton(){
  button = digitalRead(prkgbrake);
   if (button == HIGH && exbutton == LOW && millis() - last > ddelay){
      Serial.write("brake:1\n")
      while( digitalRead(prkgbrake) == HIGH){
    }
  }
}
...
and this is LUA script

Code:
....
x = com.open("COM3", 115200, 0)

function offset(handle, str)
  ipc.log(str)
end

event.com(dev, 20, 1, 0, "readSerial")
The problem is that if I push several times push button I get at first correct messages
Code:
brake:1
brake:1
brake:1
brake:1
but then I get something like that
Code:
brake:1
br
ake:1
brake:1brake:1
brak
e:1
Could someone help me where is the problem, and how to solve it? Thank you in advance