How-To: Provide life data from Java
From FactorityWiki
This How-To gives you the information how to provide life data for factority out of Java programs.
Contents |
Source
Main program (W2Server.java)
import de.wireware.APICore; import de.wireware.APIDatapt; import de.wireware.APIDataptI; import de.wireware.WireWareException; public class W2Server { public static final int DEF_TO = 5000; public static void main (String[] args_) throws WireWareException, InterruptedException { APICore.Initialize("", DEF_TO); // Create the named machine object int machineI = APIDataptI.CreateMachine("Test", 0, DEF_TO); // Create two integer datapoints and one boolean int datapointI_1 = APIDataptI.CreateDatapoint(machineI, "test1", APIDatapt.WIREWARE_DATAPOINT_TYPE_INT, 0, DEF_TO); int datapointI_2 = APIDataptI.CreateDatapoint(machineI, "test2", APIDatapt.WIREWARE_DATAPOINT_TYPE_INT, 0, DEF_TO); int datapointI_3 = APIDataptI.CreateDatapoint(machineI, "test3", APIDatapt.WIREWARE_DATAPOINT_TYPE_BOOLEAN, 0, DEF_TO); // Loop for a very long time int cnt1 = 1024; int cnt2 = 0; boolean bool3 = false; while ( true ) { if ( cnt1 > 1000000 ) { break; } cnt1++; cnt2++; bool3 = !bool3; // Update the datapoints APIDataptI.SetDatapointValue_Int(datapointI_1, cnt1, DEF_TO); APIDataptI.SetDatapointValue_Int(datapointI_2, cnt2, DEF_TO); APIDataptI.SetDatapointValue_Int(datapointI_3, bool3 ? 1 : 0, DEF_TO); // Sleep for a short time Thread.sleep(1); } // All open handles have to be closed before terminating APIDataptI.CloseDatapoint(datapointI_1, DEF_TO); APIDataptI.CloseDatapoint(datapointI_2, DEF_TO); APIDataptI.CloseDatapoint(datapointI_3, DEF_TO); APIDataptI.CloseMachine(machineI, DEF_TO); APICore.Shutdown(DEF_TO); } }
Compiling the sample
- Just use your favourite Java IDE and add the WireWare.jar to your classpath
Running the sample
- Just run the W2Server class
Note: You may have to point the Java system property "java.library.path" to the directory in which the WireWare.dll resides.
Example: java -Djava.library.path=c:\windows W2Server
References
How-To: Create a simple machine park view: This describes how to create a view in the machine park, which shows data, which is provided in this example.
