update matlab plots while logging opc data -凯发k8网页登录
this example shows you how to use a custom callback to plot data acquired during an opc logging task.
the example makes use of the function, which plots recently acquired data in a figure window.
prerequisites:
step 1: create the opc object hierarchy
create a hierarchy of opc objects.
da = opcda('localhost','matrikon.opc.simulation.1'); connect(da); grp = addgroup(da,'callbacktest'); additem(grp,'triangle waves.real8'); additem(grp,'saw-toothed waves.uint2');
step 2: configure property values
configure the logging task to acquire 200 records at 0.1 second intervals.
grp.recordstoacquire = 200; grp.updaterate = 0.1;
specify the function as the recordsacquiredfcn
callback, which must be called after each 10 records are acquired.
grp.recordsacquiredfcncount = 10; grp.recordsacquiredfcn = @display_opcdata;
step 3: acquire data
start the group object. after every 10 records are acquired, the object executes the display_opcdata
callback function. this callback function plots the most recently acquired records logged to the memory buffer.
start(grp) wait(grp)
step 4: clean up
always remove opc objects from memory when you no longer need them.
delete(da)
deleting the client object disconnects the client from the server, and deletes the group and item objects.