For the latest version of JMP Help, visit JMP.com/help.


Publication date: 11/10/2021

Examples of Data Feed

Reading Data

Here is a typical data feed script. It expects to find a string 3 characters long starting in column 11. If it does, it uses it as a number and then adds a row to the data table in the column “thickness.”

feed = Open Datafeed( );
myScript = Expr(
	line = feed << Get Line;
	If( Length( line ) >= 14,
		x = Num( Substr( line, 11, 3 ) );
		If( !Is Missing( x ),
			dt << Add Row( {thickness = x} )
		);
	);
);

Assign the script to the data feed object by using Set Script:

feed << Set Script( myScript );

Set Up a Live Control Chart

Here is a sample script that sets up a new data table and starts a control chart based on the data feed.

 
dt = New Table( "Gap Width" ); // make a data table with one column
dc = dt << New Column( "gap", Numeric, Best );
 
// set up control chart properties
dc << Set Property(
  "Control Limits",
  {XBar( Avg( 20 ), LCL( 19.8 ), UCL( 20.2 ) )}
);
dc << Set Property( "Sigma", 0.1 );
 
// make the data feed
feed = Open Datafeed();
feedScript = Expr(
  line = feed << Get Line;
  z = Num( line );
  Show( line, z ); // if logging or debugging
  If( !Is Missing( z ),
     dt << Add Row( {:gap = z} )
  );
);
feed << Set Script( feedScript );
 
// start the control chart
Control Chart Builder(
       Show Capability( 0 ),
       Variables( Y( :gap ) ),
       Set Subgroup Size( 5 )
);
 

/* Either start the feed from the device or test-feed some data

to see it work (comment out one of the lines):

feed << Connect( Port( "com1:" ), Baud( 9600 ) );*/

For( i = 1, i <= 20, i++,
  feed << Queue Line( Char( 20 + Random Uniform() * .1 ) );
  Wait( .1 ); // simulate a delay in the feed
);

Store the Script in a Data Table

You can further automate the production setting by placing a data feed script such as the one above in an On Open data table property. A property with this name is run automatically each time the table is opened (unless you set a preference to suppress execution). If you save such a data table as a template, opening the template runs the data feed script and creates a new data table.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).