Hello Pico in Xojo

Post your .Net discussions here
Post Reply
dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Hello Pico in Xojo

Post by dfergenson »

I'm trying to get in contact with my PicoScope 5244A in an in-house application that I'm writing in Xojo and I'm stumbling on the first step in the process. Fundamentally, I can't figure out why ps5000aOpenUnit keeps returning my scope status as 3 in Xojo while it returns 282 (as desired) in the VB.Net example code.

I started with the VB.Net example code and, after moving a few files into the appropriate directories, I was able to get it to compile and run. Practically the first executed line is:

status = ps5000aOpenUnit(handle, vbNullString, DeviceResolution.PS5000A_DR_12BIT)

As expected, it returns 282 since the scope is bus powered and, after VB checks for this, this line is executed:

status = ps5000aChangePowerSource(handle, status)

Now Status = 0. All is right with the world...

And then I code nearly identical code in Xojo and the first line returns 3. It does this consistently, whether or not VB.net is running, even if I unplug/replug the scope...

There's really practically nothing to my program so my simple and concrete question is:
What are the different reasons that ps5000aOpenUnit could return the value 3? I know that it's accessing the .DLL correctly because I see the Pico logo show up and a progress bar scan.

If I know what can be going wrong, then I can troubleshoot it.

Of course, if anyone has Xojo example code already running for a PicoScope (I saw that there were examples for DrDAQ), that would be greatly appreciated. Once I get mine up and running, I'll try to distribute it here, though it wouldn't accept the xojo_binary_project extension and blocked me when I changed it to .txt.

Here's what I have:

Dim Handle as short
Dim ScopeOutput as UInteger

Declare Function ps5000aOpenUnit Lib "ps5000a.dll" (ByRef Handle as Short , ByVal Serial as CString, ByVal Resolution as Integer) as UInteger

ScopeOutput = ps5000aOpenUnit(Handle, "", 1)

App.ScopeHandle = Handle

Window1.lblScopeMessage.Text = cstr(ScopeOutput)

dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Re: Hello Pico in Xojo

Post by dfergenson »

One point of information that I noticed:

Pico's working VB.net code and my non working Xojo code both call ps5000a.dll but when the VB program calls it, the progress bar is blue and segmented and runs through to the end. When the Xojo program calls it, it's green and continuous and the Pico window disappears when the bar is only about 1/3 of the way across.

dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Re: Hello Pico in Xojo

Post by dfergenson »

One more point of information. I was concerned that perhaps the different programs were calling different .DLLs so I sabotaged the filenames of the different examples of ps5000a.dll. Sabotaging the same instance caused both programs to become inoperable.

So the calls from each program are definitely being interpreted by the same .DLL.

The blue segmented vs. green continuous progress bars on the splash screen indicates that perhaps the calls are being handled differently internally to the .DLL, though.

AndrewA
PICO STAFF
PICO STAFF
Posts: 401
Joined: Tue Oct 21, 2014 3:07 pm

Re: Hello Pico in Xojo

Post by AndrewA »

I made copy of the DrDAQ code and installed Xojo.
I did find and replace on the code 'DrDAQ' replaced by 'ps5000a'
You also need to delete all the other code linked to other buttons.

I managed to get the ps5000aOpenUnit function to work by changing the code of Pushbutton to code below-

Code: Select all

Declare Function ps5000aOpenUnit Lib "ps5000a.dll" (ByRef handle As Integer, serial As Ptr, resolution  As Int64) As Int32
Declare Function ps5000aCloseUnit Lib "ps5000a.dll" (ByVal handle As Integer) As Int32
Declare Function ps5000aGetUnitInfo Lib "ps5000a.dll" (handle As Integer,  S As Ptr, stringLength As Integer, ByRef requiredSize As Integer, info As Int64) As Int64
 
 Dim handle As Integer
 Dim status As Int32
 Dim requiredSize As Integer
 Dim resolution as Int64
 Dim info as Int64
 Dim serial As New MemoryBlock(255)
 Dim S As New MemoryBlock(255)
 Dim SLegnth As Integer 
 
 serial="CQ178/005"
 
 status = ps5000aOpenUnit(handle, serial, 1)
 
 If status <> 0 Then
   MsgBox ("Unit not opened")
   Text1.Text = Str(status, "###")
 Else
   Text1.Text = "ps5000a is opened"
 End If
 
 SLegnth = ps5000aGetUnitInfo(handle, S, 255, requiredSize, 3)
 TextInfo1.Text = S.StringValue(0,requiredSize)
 
 SLegnth = ps5000aGetUnitInfo(handle, S, 255, requiredSize, 4)
 TextInfo2.Text = S.StringValue(0,requiredSize)
 
 SLegnth = ps5000aGetUnitInfo(handle, S, 255, requiredSize, 0)
 TextInfo3.Text = S.StringValue(0,requiredSize)
  
 Call ps5000aCloseUnit(handle)
I had to set the serial number string to serial number of my unit, as don't know how to set the serial string to NULL.

One thing you could do is create a table of data types using the DrDAQ code.
Showing the new C/C++ data types vs the Xojo data types
You could then use this with our programmers guides. Maybe post it on the forum here-
topic14387.html

If you are not using the current SDK windows installer, I would delete all Pico dll files from your system and download and install it- https://www.picotech.com/download/
Then you won't need to copy dll's into your project folder.

If you get status code 282 (0x011A) you need to connect the scopes 5v external supply.
Regards Andrew
Technical Specialist

dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Re: Hello Pico in Xojo

Post by dfergenson »

Andrew,

Thanks for your thorough reply.

The bottom line is that I’m still not able to get HelloPico in Xojo running. I did as you suggested and modified the DRDaq example and was able to get it to run (just like my own bare bones example) but I still got a status of 3 and a handle of 0. But I think that I may have found the crux of the problem.

I should have mentioned this earlier but when I first installed the SDK, I had to do a few things before I could get the VB.net example to run. First, VisualStudio asked for a few files such as resources.resx to be moved into the My Project subdirectory so I did that. Then, when it did run, it threw a BadImageFormat Exception which I’ve pasted at the bottom. I installed the PicoScope application and the VB code would then execute fine. I can cause the same exception to occur reliably by sabotaging the PicoScope application’s ps5000a.dll and rebooting, forcing the SDK’s version to be used. Installing the latest Beta did not solve the problem. Both Xojo and VB.net behave the same way regarding the .DLL version issue.

By the way, a Cstring type in Xojo is null terminated by default and a null string is just “” with the Cstring data type. I made a chart as you asked and posted it to the forum. I’ve also pasted a copy below.

So, some concrete questions:
Was your progress bar blue and segmented or green and continuous?
Do you know why mine might have been green and continuous for Xojo but blue and segmented for VB.net?
Can you tell me the precise size of the .DLL that you are calling on your computer down to the byte? (This will help me determine which of the three that installed on my PC yours matches). The one that both of my applications were calling was in the PicoScope program file path itself and was 4,083,472 bytes, dated 26 January, 2016.
Is the code for the .DLL supplied as a subset of the C or C# examples or is it in a distinct code base?

Code: Select all

System.BadImageFormatException was unhandled
  HResult=-2147024885
  Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
  Source=PS5000a
  StackTrace:
       at PS5000a.PS5000aVBCon.ps5000aOpenUnit(Int16& handle, String& serial, DeviceResolution resolution)
       at PS5000a.PS5000aVBCon.Main() in C:\PicoSDK\PS5000A\VB .Net\PS5000aVBCon.vb:line 329
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
Attachments
Equivalent File Types for Xojo vs. C/C++ and VB.Net
Equivalent File Types for Xojo vs. C/C++ and VB.Net

AndrewA
PICO STAFF
PICO STAFF
Posts: 401
Joined: Tue Oct 21, 2014 3:07 pm

Re: Hello Pico in Xojo

Post by AndrewA »

Hi,

Our driver code is closed source.
The colour of the driver splash screen is related to the programming language calling the driver.
With Xojo the progress bar is green, with C and VB its blue.

I tried following code to set a NULL string-

Code: Select all

  status = ps5000aOpenUnit(handle, "", 1)
but found I had to use the key word 'Nil'

Code: Select all

  status = ps5000aOpenUnit(handle, Nil, 1)
I not sure if Xojo is calling the 32-bit or 64-bit dll's-

5000a.dll (32 bit)
1.1.5.15
4077328 bytes
5000a.dll (64 bit)
1.1.5.15
4331280 bytes

These are from the stable releases of the SDK. https://www.picotech.com/downloads
I have both 32 and 64 SDK's installed on my PC.

I have attached my example project, for you to try.
ps5000aExample.zip
Xojo ps5000aExample
(12.45 KiB) Downloaded 434 times
Regards Andrew
Technical Specialist

dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Re: Hello Pico in Xojo

Post by dfergenson »

AndrewA,

Thanks for doing that.

I was able to download and execute the example program.

It opens the Scope on one of my machines but not another (whereas before it hadn't opened on either).

I think that I can take it from here.

Thanks again for all the help.

dfergenson
User
User
Posts: 2
Joined: Fri Mar 04, 2016 8:58 am

Re: Hello Pico in Xojo

Post by dfergenson »

I'm still able to execute the Xojo code on my Windows10 machine and have a working path forward.

I've managed to parameterize the problem a bit more so here's some information in the hopes that it will be useful.

I've checked the file sizes and versions vs. those that AndrewA posted and even though I just deleted the old versions and redownloaded the SDK again, mine don't match. My 32 and 64 bit SDK .DLL versions are both 1.1.4.39.

But the PicoScope6.exe download installed .DLL version 1.1.5.26. That's the only version that I was able to make work. Perhaps that's the issue?

When I launch either AndrewA's code or my own with the SDK .DLLs enabled, I get the following error message in Xojo:

Common\Loaders\Loader.cpp: 173
Failure Condition: 0
Failed to load library ps5000a.dll
%1 is not a valid Win32 application

I get the same error for both the 32 Bit and 64 Bit versions.

Thanks again for getting me to a running program and I hope that this helps chase down whatever residual issues may remain.

Hitesh

Re: Hello Pico in Xojo

Post by Hitesh »

Hi dfergenson,

It's possible that the Xojo environment is picking up a 64-bit dll from somewhere when attempting to run in 32-bit mode.

You will need to ensure that you are using the PicoIpp.dll from the PicoScope 6 installation directory if you are using the ps5000a.dll from that directory. Alternatively, please e-mail support@picotech.com and we can provide more recent 32-bit and 64-bit drivers - we are waiting for a new SDK build to be uploaded.

With regards to the BadImageFormatException, please check to see if the VB .NET code is building for 'Any CPU'. If that is the case, it might be picking up a 32-bit dll even though it is trying to run a 64-bit application. In that case, it is better to configure your IDE to build separately for 32-bit/64-bit target platforms.

Regards,

Post Reply