4 Replies Latest reply on Aug 8, 2018 5:00 PM by gachen

    pisn_putsnapshot

    lishuangshuang

      How to use java language to add new functions to PI real time library。

        • Re: pisn_putsnapshot
          VasanthakumarR

          Hi Lishuang,

           

          Check the for either PI WebAPIPI WEB API (it is intended to replace PI Web Services in the future) , or PI JDBC.

          You can find the documentation for those products under the "downloads" tab.

           

          Following are the additional details for your reference,

           

          -Vasanth.

            • Re: pisn_putsnapshot
              vkaufmann

              I want to chime in here to say that PI Web Services is and has been deprecated in favor of the PI Web API so the advised approach to accessing PI data from a JAVA client is to use the PI Web API.

               

              --Vince

              2 of 2 people found this helpful
              • Re: pisn_putsnapshot
                lishuangshuang

                public int saveDataToPi(int pt,float rval,int istat,int timedate){

                  int flag = 0;

                  try {

                  JNative jnt = new JNative("piapi32.dll", "pisn_putsnapshot"); // pisn_putsnapshot  (insert ),

                  jnt.setRetVal(Type.INT);

                 

                  Pointer p0 = new Pointer(new HeapMemoryBlock(1024));

                  p0.setIntAt(0, pt);

                  jnt.setParameter(0, p0);

                 

                  Pointer p1 = new Pointer(new HeapMemoryBlock(1024));

                  p1.setFloatAt(1, rval);

                  jnt.setParameter(1, p1);

                 

                  Pointer p2 = new Pointer(new HeapMemoryBlock(1024));

                  p2.setIntAt(0, istat);

                  jnt.setParameter(2, p2);

                 

                  Pointer p3 = new Pointer(new HeapMemoryBlock(1024));

                  p3.setIntAt(0, timedate);

                  jnt.setParameter(3, p3);

                 

                  jnt.invoke();

                  jnt.dispose();

                 

                  System.out.println(jnt.getRetValAsInt());

                 

                  } catch (Exception e) {

                  e.printStackTrace();

                  }

                  return flag;

                  }

                ——————————————————————————————————————————————————————————

                this  is my code, I want to insert a piece of data to PI ,how to do this。

                  • Re: pisn_putsnapshot
                    gachen

                    I would suggest looking into Vince's suggestion of using PI Web API as the data access method with Java. I see two main advantages to this over what you are currently trying to do:

                    1. PI API, which is what you are using by referencing piapi32.dll, is deprecated and no longer in active development. This means that you are more likely to find current support (bug fixes, help, resources, documentation, etc) with using PI Web API than PI API.
                    2. PI Web API provides a RESTful endpoint to both read/write data to PI, making it largely client platform agnostic. This also improves the security posture of your Java client, as you should no longer need to make use of the Java Native Interface, which you are currently doing to reference and use the piapi32.dll.
                    2 of 2 people found this helpful