Access API's in driver DLL
I am trying to access a driver DLL file API to control movement of a Prior stage on the microscope. A simple Declare works ok, but one that provides feedback from the PC card on postion doesn't e.g. Declare Function OI_InitializeXY Lib "oasis4i" () As Integer (Works fine) but Declare Function OI_ReadXY Lib "oasis4i" (ByRef xpos As Double, ByRef ypos As Double) As Integer (this doesn't). Is this a limitation of the WWB.Net scripting language used in the workbench or am I missing something more basic (please excuse the pun!)?
0
Best Answer
-
Chris,
It looks like a very specific case. What is Iret value? It's an error code, which may give some clue.
Error codes are described on the page 27 of OI manual.
I found some other discussions on internet regarding OI_ReadXY problem (though they don't provide a solution):
https://www.reddit.com/r/LabVIEW/comments/2xfclb/help_getting_a_pci_controller_to_work/
There are other functions, such as OI_ReadAxis(Ex) that can be used to get stage position: https://www.yumpu.com/en/document/view/19178561/oasis-4i-controller-dll-manual/71
Regards,
Yuri0
Answers
Can you specify exactly what doesn't work? Do you get some kind of error message?
Thanks,
Pierre
The error message isn't that useful as it is a low level call and it locks the workbench up and has to be killed with task manager so I have put a timer break in it so I can interrupt it and stop it myself.
To be truthful what I am doing is trying to port in parts of a VB,Net app written by Objective Imaging and create my own script based app to control image capture direct to Premier (we are bit too inpatient to wait for the release incorporating this functionality and we are control freaks at heart!). I have copied the BAS file with their API declarations in its entirety so there are many more calls than I will actually use - I am being a bit lazy on this proof-of-concept stage.
What is noticeable is that after my application load in the workbench only the simple objects (API calls) are visible in the Macro Explorer window and not the ones that return information as I previously described. So rather irritatingly I can intitailise the stage and move it around but cannot find its relative co-ordinates which is a level of control I need to setup tiling and ensure we are viewing the right image within the mosiac for some of the clever analysis we are trying to do of carbon composites.
Sorry, I am new at using the forum and haven't mastered what I can upload or not as yet.
Best,
Chris
Pierre may have more details on it, but I can say that the macro explorer lists only subs or SimpleScript functions, though you may declare and define any function you need (including those with ByRef parameters), you just call them from other macro function (not from Macro Explorer UI).
You mentioned that you use BAS file with declaration, please check that the syntax matches VB.NET (as BAS files were used in earlier versions of VB).
You can look at some pre-installed projects in the Scripts folder or Apps and Premier macros on our solutions zone as examples.
Let us know if you will need more info.
Regards,
Yuri
Sorry for causing confusion but I started programming back in the pre .NET age and I still tend to use the term BAS for a collection of functions and subs without a UI. I am doing the calls from code (I use the Macro Explorer as an 'Object Explorer' again because I am more used to the Visual Studio IDE).
Best,
Chris
Chris
Private Sub tmrRead_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles tmrRead.Tick Dim dX As Double, dY As Double, strErrCode As String 'Read the current position lret = OI_ReadXY(dX,dY) If (lret<>0)Then strErrCode = CStr(lret) MsgBox("It isn't working!! Err code: " & strErrCode,VbMsgBoxStyle.vbOkOnly) tmrRead.Enabled=False Else 'Display it lblPos.Text = "X = " & CStr(Format$(dX, "0.00")) & vbCrLf & "Y = " & CStr(Format$(dY, "0.00")) End If End Sub