Fun with Rotary Encoders

  Serial.println(count);

is going to send something like '1', '7', '', and '' to the serial port.

void serialEvent(Serial p) {

is, because there is no Serial::bufferUntil() call, going to be called every time serial data arrives (as in when the '1' arrives, when the '7' arrives, when the '' arrives, and when the '' arrives).

  while (myPort.available() > 0) {
    inBuffer = myPort.readBytes();
    myPort.readBytes(inBuffer);

Only one of the readBytes() methods should be called. The second one, where the buffer is supplied is preferred. The first one creates a new array. The second one populates the array that you created.

It is populated with whatever data is available. When you print the data with another carriage return and line feed, stuff really spreads out.

Use the bufferUntil() method, so you only get called once when the '' or once when the '' arrives (I may have the cr/lf order backwards).

Use only one of the methods of reading the data.

Strip off the carriage return and line feed (or don't send them; send a ! after the data and bufferUntil() the ! arrives).

Don't create a new String and then assign that String instance to val. Assign the output of new String to val, instead.