Digital output on PL 1216

Post any questions you may have about our current range of USB data loggers
Post Reply
LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Digital output on PL 1216

Post by LPH »

Hi,

i'm using a PL1216 to integrate an exposure (laser) to get the dose. I'm writing an application that opens a shutter to start exposure and closes it when the reference dose is reached.

To my problem: to control the shutter i want to use the digital output from PL1216. When i test i do not get any signal on programed channel (D0 in this case).

Another issue, to get TTL compatible signal, is there some preffered way to transform signal?

Below is the testfile, VB 2008 Express, i used to test for signal on digital output.

Guidance would be greatly appreciated!

//Patrik

Public Class Form1

Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Short) As Integer
Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Short) As Integer
Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Short, ByVal enabled As Short, ByVal enable_auto As Short, ByVal auto_ms As Short, ByVal channel As Short, ByVal dir As Short, ByVal threshold As Short, ByVal hysterisis As Short, ByVal delay As Single) As Short
Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Short 'also tried as integer outside paranthesis

Dim status As Long
Dim ready As Integer
Dim handleX As Integer
Dim initialized As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call pl1000SetTrigger(handleX, False, 0, 0, 0, 0, 0, 0, 0) ' No trigger, not sure if it is nesessary to disable trigger

status = pl1000OpenUnit(handleX)
initialized = handleX <> 0
If initialized Then

Label1.Text = "Device opened"

Call pl1000SetDo(handleX, 1, 0)
Label1.Text = "Device opened - Signal on"

Dim timeOut As DateTime = Now.AddMilliseconds(10000) '"Pause" for xxx milliseconds
Do
Application.DoEvents() 'Keep the app from freezing and allow Windows to continue processing the applications messages.
Loop Until Now > timeOut 'Keep looping until the elasped time of xxx milliseconds.

Call pl1000SetDo(handleX, 0, 0)
Label1.Text = "Device opened - Signal off"

Call pl1000CloseUnit(handleX)
Label1.Text = "device closed"

Else
MsgBox("Cannot initialize device")
End If

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

Hi

Have you checked the error status returned by pl1000SetDo?

Also you have declared your handle as an Integer. This should be a short (16-bit) variable.

Robin

LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Re: Digital output on PL 1216

Post by LPH »

Hi Robin,

feel a bit silly not have done that...

It returns PICO_NO_SIGNAL_GENERATOR

Isn't there one in the PL1216?

//Patrik

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

Hi Patrick

The pl1000.dll driver does not return that error code (13). The possible error codes for each function call are given in the manual.

I think you possibly have a data type error. Are you using .net? A long in .net is 64 bits rather than 32.

As I mentioned in my previous post, I think this might also be the cause of the error.

Robin

LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Re: Digital output on PL 1216

Post by LPH »

Hi Robin,

yes I use .net (at least I think so, I use VD 2008 express, when I type a function or object I get suggestions and when typing "." I get suggestions for method. Isn't that implying .net? Im not a programmer so please excuse the, perhaps stupid question)

About the error code, I checked the list of ALL error codes, not for the function. However, the function does return 13, below is the code I use. I haven't looked in to adjusting data types due to .net, not sure what to look for.

//Patrik

Public Class Form1

Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Short) As Integer
Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Short) As Integer
Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Short, ByVal enabled As Short, ByVal enable_auto As Short, ByVal auto_ms As Short, ByVal channel As Short, ByVal dir As Short, ByVal threshold As Short, ByVal hysterisis As Short, ByVal delay As Single) As Short
Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Short

Dim status As Short
Dim ready As Integer
Dim handleX As Short
Dim initialized As Integer
Dim initializedDo As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call pl1000SetTrigger(handleX, False, 0, 0, 0, 0, 0, 0, 0) ' No trigger, not sure if it is nesessary to disable trigger

status = pl1000OpenUnit(handleX)

initialized = handleX <> 0
If initialized Then

Label1.Text = "Device opened"

status = pl1000SetDo(handleX, 1, 0)
MsgBox(status)
initializedDo = handleX <> 0

If initializedDo Then

Label1.Text = "Device opened - Signal on"
End If

Dim timeOut As DateTime = Now.AddMilliseconds(10000) '"Pause" for xxx milliseconds
Do
Application.DoEvents() 'Keep the app from freezing and allow Windows to continue processing the applications messages.
Loop Until Now > timeOut 'Keep looping until the elasped time of xxx milliseconds.

Call pl1000SetDo(handleX, 0, 0)
Label1.Text = "Device open - Signal off"

Call pl1000CloseUnit(handleX)
Label1.Text = "device closed"

Else
MsgBox("Cannot initialize device")
End If

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

Hi

PICO_STATUS is a 32-bit type, so you need to change Dim status As Short to Dim status As Integer.

This should give you a sensible status code

Robin

LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Re: Digital output on PL 1216

Post by LPH »

Hi again...

no, still same error code. Also tried declaring the function as integer, should it be short or integer?

Really dont know what to do but ask for help ;-)

Thanks a lot for assistance so far.

//Patrik

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

Hi

I should have said that you also need to change

Code: Select all

Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Short
to

Code: Select all

Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Integer
Let me know how you get on

Robin

LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Re: Digital output on PL 1216

Post by LPH »

Hi Robin,

tried that, that was what I meant by "declaring the function as integer" in previous post. Tried again to be sure, still same error code.

I'm a bit confused regarding data type for functions in pl1000.dll. In the vb (excel) example, for instance pl1000SetTrigger is declared as short. How do I know what the data type for functions (or rather what they return) should be?

//Patrik

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

The data types used in VBA (Excel) are different to those used in .net.

VBA:

http://msdn.microsoft.com/en-us/library/aa164260.aspx

Visual Basic:

http://msdn.microsoft.com/en-us/library/47zceaw7.aspx

I have checked the driver code and it definitely does not return a status of 0x13.

I suggest you have a look at the above links and once you are clear about the different data types, go through the variables in your code and make sure they are all correct. If you are still having problems, I will try it out here.

The following link gives the C/C++ data types that are used in the 1216 programmer's guide:

http://msdn.microsoft.com/en-us/library/s3f49ktz.aspx

I hope this helps!

Robin

LPH
Newbie
Posts: 0
Joined: Wed May 19, 2010 2:08 pm
Location: Stockholm

Re: Digital output on PL 1216

Post by LPH »

Hi Robin,

found the error! Thanks for the links, now I know more about difference in data types. However the error was in declarations below, realized that do_value and doNo must be ByVal - totally missed that.

//Patrik
Robin wrote:Hi

I should have said that you also need to change

Code: Select all

Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Short
to

Code: Select all

Declare Function pl1000SetDo Lib "pl1000.dll" (ByVal handle As Short, ByRef do_value As Short, ByRef doNo As Short) As Integer
Let me know how you get on

Robin
EDIT: also, the errorcode is 13 translated from hex (since I print it with MsgBox), i.e. PICO_INVALID_PARAMETER
Last edited by LPH on Wed Jun 02, 2010 8:08 am, edited 1 time in total.

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Digital output on PL 1216

Post by Robin »

Hi Patrik

I'm pleased you found the error. I really should have spotted that!

Robin

Post Reply