• I'm not sure what the terminology is called.... I am trying to instantiate an object within another object.. I am getting these errors:

    Uncaught Error: Field or method does not already exist, and can't
    create it on undefined at line 2 col 10
    this.ph.updateResTemp(tempCompensation);­

          ^ in function "getPhValue" called from line 2 col 22   bot.getPhValue(90.5);
                      ^
    

    Code:

    I2C1.setup({scl:b6, sda:b7});
    
    Serial4.setup(9600, {tx:C10,rx:C11});
    
    function s7s (theAddress) {
      this.address = theAddress;
      this.displayTable = {
        "Clear" : 0x76,
        "dp"    : {
          "cmd" : 0x77,
          "location"   : [
              0b00000001, //Digit 0
              0b00000010, //Digit 1
              0b00000100, //Digit 2
              0b00001000  //Digit 3
          ]
        }
      };
    }
    
    s7s.prototype.writeValueToDisplay = function () {
      var toChar = "";
    
      var a = this.address;
      var clrCMD = this.displayTable.Clear; //Display clear command
      var dpCMD = this.displayTable.dp.cmd; //Decimal point command
      var dpLocation = this.phDisplay.displayTable.dp.location;­ //Decimal point location map
    
      I2C1.writeTo(a, clr); //Clear display
    };
    
    function Sensor (theType, theAddress) {
      this.type = theType;   //i.e. PH
      this.address = theAddress;  //i2c Address
      this.sensorResult = 0; //Store sensor result
      this.cmdTable = {
        "Calibrate" : {  //List of Calibration commands and timeout value.
          "clear" : { "cmd" : "Cal,Clear",      "wait" : 300  },
          "mid"   : { "cmd" : "Cal,mid,7.00",   "wait" : 1300 },
          "low"   : { "cmd" : "Cal,low,4.00",   "wait" : 1300 },
          "high"  : { "cmd" : "Cal,high,10.00", "wait" : 1300 },
          "query" : { "cmd" : "Cal,?",          "wait" : 300  }
        },
        "Information" : {  //Device Information
        },
        "LED" : {  //Enable / Disable or Query the LEDs
          "L0" : { "cmd" : "L,0", "wait" : 300 },
          "L1" : { "cmd" : "L,1", "wait" : 300 },
          "L?" : { "cmd" : "L,?", "wait" : 300 }
        },
        "Reading" : {  //Takes a single reading
          "R" : { "cmd" : "R", "wait" : 1000 } //Takes a single temperature compensated reading
        },
        "Serial"      : {  //Switch back to UART mode
        },
        "Sleep"       : {  //Enter low power sleep mode
        },
        "Status"      : {  //Retrieve status information
        },
        "Temperature" : {  //Set or Query the temperature compensation
          "T"  : { "cmd" : "T,19.5", "wait" : 300 },  //Where the temperature is any value; floating point, or int, in ASCII form
          "T?" : { "cmd" : "T,?",   "wait" : 300 }  //Query the set temerature
        },
        "Factory"     : {  //Factory reset
        },
      };
    }
    
    Sensor.prototype.getSensorType = function () {
      return this.type; //Get Sensor type
    };
    
    Sensor.prototype.getSensorAddress = function () {
      return this.address; //Get Sensor address
    };
    
    Sensor.prototype.getSensorReading = function() {
      var a = this.address;
      var d = I2C1.readFrom(a, 7);
      return d;
    };
    
    Sensor.prototype.getSensorResult = function () {
      var a = this.address;
      var c = this.cmdTable.Reading.R.cmd;
      var w = this.cmdTable.Reading.R.wait;
      var that = this;
    
      I2C1.writeTo(a, c);
    
      setTimeout(function (e) { callback(that.getSensorReading()); }, w);
    };
    
    Sensor.prototype.storeSensorResult = function () {
    };
    
    Sensor.prototype.updateResTemp = function (temp) {
      var a = this.getSensorAddress();
      var c = this.cmdTable.Temperature.T.cmd;
      var w = this.cmdTable.Reading.R.wait;
      var that = this;
    
      Serial4.print(a + " " + c + "\r\n");
    
      I2C1.writeTo(a, c);
      setTimeout(function (e) { that.getSensorReading(); }, w);
    };
    
    function processData () {
      //Sensor Objects
      var ph = new Sensor("ph", 0x63);
      var ec = new Sensor("ec", 0x64);
    
      //Sensor Displays
      var phDisplay = new s7s(0x71);
      var ecDisplay = new s7s(0x72);
    }
    
    processData.prototype.getResTempValue = function () {
    
    };
    
    processData.prototype.getRoomTempValue = function () {
    
    };
    
    processData.prototype.getRoomHuminityVal­ue = function () {
    
    };
    
    processData.prototype.getPhValue = function (tempCompensation) {
      this.ph.updateResTemp(tempCompensation);­
    };
    
    processData.prototype.getEcValue = function (tempCompensation) {
    
    };
    
    Serial4.on('data', function (data) {
      Serial4.print(data);
    
      var edisonData = data;
      Serial4.print("Edison sent: " + edisonData);
    
    });
    
    var bot = new processData();
    
    setInterval(function (e) {
      bot.getPhValue(90.5);
    }, 3000);
    
About

Avatar for d0773d @d0773d started