If the serial number sent to the device is 9 characters, which is the standard size for serial numbers, then the starting code and secret key numbers are not received correctly. The reason is that the ";" symbol between the serial number and the starting code is not discarded, but kept as part of the starting code.
There is an easy fix, slightly modifying the getSerialNumber() function.