Page 1 of 1

OSISoft PI API

Posted: Fri Nov 11, 2016 8:57 pm
by Brandon Parker
Does anyone have any experience translating the PI API (piapi32.dll) from OSISoft?

I'm experienced translating it with a different language, but I'm running into an issue with PureBasic. Can someone point me in the right direction with the function listed below? I am very green with PureBasic, but I plan on eventually porting the program over to PureBasic.
pipt_findpoint
This function returns the point number for the given tagname. The tagname may be a long tagname or tagname. If found, the matching tagname in Point Database format is returned: tagnames are returned with delimiters and always 12 characters long; long tagnames are returned in upper case.

C format

int32 pipt_findpoint(

char PIPTR * tagname,

int32 PIPTR * pt );


Returns

>0
System error

0
Success

-2
Passed tag is all spaces

-5
Tag not found, or not yet connected to a server


Arguments

tagname (passed, returned)

Tagname (null terminated and returned in uppercase)

pt (returned)

Point number


pi Toolkit Reference

ParseFindTag, FindPoint

Usage Notes

It is the calling routine’s responsibility to ensure the tagname buffer is large enough for the returned tagname. Tagnames are 12 characters long, long tagnames are up to 80 characters long. When the PI-API connects to a Server, it determines if long tag names are supported. Before a connection is made it is assumed that long tagnames are not supported. Because of this, calling pipt_findpoint before establishing a server connection will return -5 if the passed tagname contains more than 12 characters.
Any help would be much appreciated!!


{:0)

Brandon

Re: OSISoft PI API

Posted: Fri Nov 11, 2016 9:45 pm
by infratec
Hi,

for me it's not clear what you want to do:

Do you want to write a wrapper for importing the dll in PB?
Or do you want to write an own procedure which does the same as this function?

Bernd

Re: OSISoft PI API

Posted: Fri Nov 11, 2016 9:47 pm
by Brandon Parker
In the event that it will help, here is the VB Declare for the function.

Code: Select all

Declare Function pipt_findpoint Lib "piapi32.dll" (ByVal TagName$, pt&) As Long
Also, I am connecting to the server perfectly fine, but I just started translating code and after the connect, isconnected, and disconnect functions the one above is the first I've attempted.

The function is returning the ptID back, but does not change the tagname to upper case. The return value of the function is -5 which means that it is either not connected to a server (which I know I am) or the tagname doesn't exist (which I know it does). The odd thing is that the program is returning ptID back as -5 as well when I set it to an arbitrary value of 999 at the beginning of the code.

Thanks again!!


{:0)

Brandon

Re: OSISoft PI API

Posted: Fri Nov 11, 2016 10:05 pm
by Brandon Parker
infratec wrote:Hi,

for me it's not clear what you want to do:

Do you want to write a wrapper for importing the dll in PB?
Or do you want to write an own procedure which does the same as this function?

Bernd

Hello Bernd,
Thanks for the reply!! I would just like to be able to call the function in this DLL first of all. I have had PB for quite a while and I am just now deciding to start converting a program over.

For instance, this is how I set up the connect code:

Code: Select all

procName.s = "XYZProgramName"
#PI_Success   = 0
#PI_DLL       = 0
Prototype.l ProtoPIConnect(procName$)
PILibOpen = OpenLibrary(#PI_DLL, "blah\blah directory\blah\piapi32.dll")
If PILibOpen
        
        PIConnect.ProtoPIConnect          = GetFunction(#PI_DLL, "piut_connect")

     If PIConnect(procName) = #PI_Success
            Debug "Connected to PI!"
     EndIf
     CloseLibrary(#PI_DLL)
EndIf
Here is the description of that function from the literature:
piut_connect
Use this function to establish a connection to the default pi home node server if calling from a pi client node. The first four characters of the argument procname will be used for the connection ID string if specified or the default string will be used. The default string will be either the ID string specified using piut_procname or the process name. Calling this function also insures that the client and server PINet versions are compatible.

C format

int32 piut_connect(

char PIPTR * procname );

Returns

>0
System Error

0
Success

-1
Attempt to reconnect within 60 seconds or socket_open has failed

-994
Incompatible PINET protocol version

-1001
Default host not found


Arguments

procname (passed)

Character string identifying the client application to the server

pi Toolkit Reference

PIConnect
And here is the VB Declare:

Code: Select all

Declare Function piut_connect Lib "piapi32.dll" (ByVal ProcName$) As Long
I will say that the other language (not VB btw) is more forgiving, but it did take some time to work out the details in it as well as I'm not sure that things are always cast the same way throughout the DLL.

Thanks!!


{:0)

Brandon

Re: OSISoft PI API

Posted: Sat Nov 12, 2016 10:35 am
by infratec
Hi,

I think your prototype is wrong.

Try this versions:

Code: Select all

Prototype.l pipt_findpoint(tagname.p-bstr, *pt)

Code: Select all

Prototype.l pipt_findpoint(tagname.p-bstr, pt.l)
A string ByVal needs p-bstr.

Bernd

Re: OSISoft PI API

Posted: Sun Nov 13, 2016 1:39 am
by Brandon Parker
infratec wrote:Hi,

I think your prototype is wrong.

Try this versions:

Code: Select all

Prototype.l pipt_findpoint(tagname.p-bstr, *pt)

Code: Select all

Prototype.l pipt_findpoint(tagname.p-bstr, pt.l)
A string ByVal needs p-bstr.

Bernd
Bernd,
Thank you very much for the examples. I tried both and they end with the same result. The tagname is not modified (should return all capital letters) and the ptID is returned as -5. I should mention that I am running PB 5.2 b13 if that names any difference.

I am no expert, but shouldn't the tagname and the ptID be passed as reference since they are both getting modified by the DLL and PI Server that the DLL is connecting to?

Thanks for the help; I will be sure to post any success if I happen to stumble upon it.


{:0)

Brandon

Re: OSISoft PI API

Posted: Sun Nov 13, 2016 1:52 am
by Brandon Parker
And of course.......

Wouldn't you know it.....I just stumbled upon success......

Here are the pertinent bits of code and how I have managed to call the functions.....

The below is not functioning code; just fragments to illustrate what worked.....

Code: Select all

procName.s = "AndonLight"
tag.s = "Mm14.ISO_TB_KW"
ptID.i = 999

Prototype.l ProtoPIConnect(procName$)
Prototype.l ProtoPIDisconnect()
Prototype.l ProtoPIIsConnected()
Prototype.l ProtoPIFindPoint(tagname.i, ptID.i)

PIConnect(procName)
PIIsConnected()
PIFindPointID(@tag, @ptID)
PIDisconnect()

On to the next function; I'll definitely be back.....

Thanks again for the assistance!!!

{:0)

Brandon