An interface may use multiple serial ports to communicate with multiple devices at once.
Plotting from multiple ports
Data send as comma-separated values are process by MPJ as ain0, ain1 and so on. If multiple controllers send analog data, each will be processed as ain0, ain1, etc. This will cause issues with plotting as a channel will receive data from multiple devices.
One means to adjust for this is to set the Pre-Plot setting for analog data to define the serial port and the source data from it. Such as for an analog plot, open the settings (right-click the plot for the menu) and go to Channels. For the pre-plot formula, define the control.value to use, such as:
.png)
This must be done whether using a single plot or multiple.
NOTE: This may cause some jaggedness to the traces on a single plot, since when analog data arrives from any power, all channels are plotted causing a plotted point even though the new data from one serial port may not have been processed yet.
Another means which provides cleaner traces is have the controller send plotted data using the .plotChan instruction to ensure it is plotted with correct timing: !plot.plotChan channel, value
Serial.print("!plot.plotChan 3,");
Serial.println(value1);
Serial.print("!plot.plotChan 4,");
Serial.println(value2);
Serial.print("!plot.plotChan 5,");
Serial.println(value3);
Interactive Data
With interactive data, where MPJ must send data to the controller, using !send from the MPJ side will only send data to the serial port named 'serial'. !send 10
If it is desired to send to a different port, the control must be identified: !serial2.send 10
If the !read instruction is issued by the controller, such as: Serial.println("!read [sldTemp]");
MPJ will process the string to return it to the correct serial port.
The Debug/Immediate Terminal mode only supports use of the control named 'serial'.
|