Trying to wrangle serial data from an Arduino

Ideally, I would want the program to sense the width and height of the scan array automatically, as it can be configured by the user. Thanks anyway for the suggestion, it helps a lot.