Navigation: Interface Design Concepts >

Controller Interactive Data

 

 

 

 

Data from MakerPlot-J can be sent to the controller by either sending it from MPJ or requesting a read from the controller. For example, if it is desired for the controller to get the value of a slider, called sldPower:

The Event code for the slider or another control can send the value using:
!send [sldPower]

The controller will need code to accept the incoming data such as:
if (Serial.available() > 0)
          data = Serial.parseInt();

The controller can request the data using MPJ's read instruction (identical function of send but more grammatically correct to read) and then accept the incoming value:

Serial.println("!read [sldPower]");  // tell MPJ to send back the value of sldPower
data = Serial.parseInt();

Multiple Data Values to Send

Sending a single value works easily, but if you wish to send multiple values it's important to be able to identify the source of the data for proper synchronization so that the controller's code is receiving the proper value for that use.

'One' means 'would be to first send an identifier and then the value', such as wanting to set sliders for Speed, Temperature or a toggle button state of On/Off (1/0).

For sldSpeed, use event code such as:
!send S
!send [sldSpeed]

For sldTemperature, use event code such as:
!send T
!send [sldTemperature]

For the Run toggle button, use event code such as:
!send R
!send [tglbRun]

On the controller side, reading the first value will define the source of the data and the second will read the value:

if (Serial.available() > 0) {

    int data=0;

    data = Serial.read();

    switch (data){                    // act on the specified data

      case 'S':

      speed = Serial.parseInt();

      break;

     

      case 'T':

      temperature = Serial.parseInt();

      break;

 

      case 'R':

      run = Serial.parseInt();

      break;

    }

  }
 

Reading Multiple Values

Reading multiple values one at a time can work well, though it is recommended to flush the serial buffer before each read to ensure old data is not being used, but it can be time consuming to request and accept each value. A comma-separated string of values can be read at once and parsed on the controller side to speed up operations.

 

The installed example code interactive_ang_dig.ino file demonstrates reading an entire sequence of values and parsing them to correct values in the Arduino. Additionally, the example code reads twice for error checking returned data.

 

Default Serial Control Read/Send

!send and !read are used only when using the default Serial Control name of 'serial'. If the control is named differently, or other serial controls are used they must be declared in the instruction. Also, the serial controls have addition send instructions.

 

!serial2.send [sldPower]
!serial2.sendNoEOL [sldPower]  // send with no end of line of a carriage return
!serial2.sendBytes 10,20,30,40  // send data as byte values, 0-255.

 

From the controller side, !read can also be used alone; MPJ serial control will modify the !read so that data is sent back to through the reading serial COM port used to read by the controller.

 

 

 

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC