Home Image-Pro Automation (Macros, Apps, Reports)

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!)?

Best Answer

Answers

  • Hello,

    Can you specify exactly what doesn't work? Do you get some kind of error message?

    Thanks,

    Pierre
  • Hi 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
  • Hi 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
  • Hi 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
  • To add more clarity - I have timer set to 1 sec to allow me to capture the fail in the macro and the declarations and constants are in a separate Public module. My label should be updating with the co-ordinates stored on the card from my OI_ReadXY call:
        Private Sub tmrRead_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles tmrRead.Tick
            Dim dX As Double, dY As Double
    
            'Read the current position
            lret = OI_ReadXY(dX,dY)
            If (lret<>vbOK)Then
                MsgBox("It isn't working!!",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
    
  • Yuri thanks - your comments made me check the return code which was a success! It turns out that I was trapping the result rather than the error!! The mistake was in using the 'vbOk' constant rather than the return value itself.  I am now successfully getting my data back from the Oasis card and can move on to some serious automation programming - with a better focus on the error control and more use of CASE SELECT.  Thanks again,

    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
Sign In or Register to comment.