I have included a handler for RX data as shown in the code below.
`//
// dj2 Interface Object - Simple abstraction of the interface connected to the imp
//
class dj2_if {
// Hardware interface
serPort = null;
nCTSo = null;
nRTSi = null;
constructor(sPort, ctsIO, rtsIO) {
// Configure the imp's hardware
serPort = sPort;
serPort.configure(57600, 8, PARITY_NONE, 1, NO_CTSRTS, _HandleRxChar);
// other constructor code
}
// Internal handler for incoming serial data
function _HandleRxChar() {
local ch = serPort.read();
while (ch != -1) {
server.log("handleRx for " + ch);
_ProcessRxChar(ch);
// See if there is any additional data
ch = serPort.read();
}
}
}
dj2if <- dj2_if(hardware.uart57, hardware.pin1, hardware.pin2);
`
I get the following error when a character is received.
Sat May 11 2013 12:33:24 GMT-0600 (MDT): Device booting Sat May 11 2013 12:33:24 GMT-0600 (MDT): Device configured to be "dj2_serial" Sat May 11 2013 12:33:24 GMT-0600 (MDT): ERROR: the index 'serPort' does not exist Sat May 11 2013 12:33:24 GMT-0600 (MDT): ERROR: at _HandleRxChar:181
It is like the variable serPort is not defined in the handler in the instantiated object. Am I doing something wrong? If so, how do I fix this? Other methods in the object use serPort successfully to write to the serial port (serPort.write(ch)). These methods are called directly by the main code and are not callbacks.