Complex Triggering

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

Complex Triggering

Post by dfergenson »

I'm developing drivers for the PS5000A.dll in VisualStudio 2019 to drive a PS5444D and I've run into some confusing results when attempting to interface with the complex triggering functions. I started off working in VB.net but eventually switched to C# to see if I could get my head around the functions better. I modified the example C# code on Github. Specifically, I was working in the block collection example.

I've excerpted some driver code below. The bottom line is that when I initially cleared the triggers, I got error code 300. Then when I initially the channel properties (for Channel A only) I got error code 382. The rest of the channel initialization returned PICO_OK but then, when I went to collect the data, it seemed to be auto triggering. I got similar results in VB.net.

So, my concrete questions are:
1. What is error code 300 and why might I have been seeing it? It wasn't in the C# example. In the C example, it says PICO_INVALID_CONDITION_INFO but I'm only clearing all conditions so that was surprising.
2. What is error code 382 and why might I have been seeing it? It wasn't in the C# example. In the C example, it says PICO_AUX_NOT_SUPPORTED but I wasn't attempting to use the aux as a trigger and that should have been supported on my model.
3. Why might I be randomly triggering? Did I miss something obvious?
4. Is there complex triggering code in any language ready to go in VisualStudio? I fought with the C example for a few hours but couldn't get it to compile. This probably says more about me than it does about the code but any ready made VS example code for the V2 complex triggering functions would be greatly appreciated.

Thanks in advance. Code is below.

-Davio

I added this to PS5000aImports.cs:

Code: Select all

		
	public enum PS5000A_CONDITIONS_INFO : uint
        {
		PS5000A_CLEAR,
		PS5000A_ADD
        }

[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public struct tPS5000ATriggerChannelPropertiesV2
		{
			public short thresholdUpper;
			public ushort hysteresisUpper;
			public short thresholdLower;
			public ushort hysteresisLower;
			public Channel Channel;

			public tPS5000ATriggerChannelPropertiesV2(
				short thresholdUpper,
				ushort hysteresisUpper,
				short thresholdLower,
				ushort hysteresisLower,
				Channel channel)
			{
				this.thresholdUpper = thresholdUpper;
				this.hysteresisUpper = hysteresisUpper;
				this.thresholdLower = thresholdLower;
				this.hysteresisLower = hysteresisLower;
				this.Channel = channel;
			}
		}


[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public struct tPS5000ADirection
		{
			public Channel channel;
			public ThresholdDirection direction;
			public ThresholdMode mode;

			public tPS5000ADirection(
				Channel channel,
				ThresholdDirection direction,
				ThresholdMode mode)
			{
				this.channel = channel;
				this.direction = direction;
				this.mode = mode;
			}
		} 

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aSetTriggerChannelPropertiesV2")]
		public static extern uint SetTriggerChannelPropertiesV2(
			short handle,
			tPS5000ATriggerChannelPropertiesV2[] channelProperties,
			short nChannelProperties,
			short auxOutputEnable);

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aSetTriggerChannelConditionsV2")]
		public static extern uint SetTriggerChannelConditionsV2(
			short handle,
			tPS5000ACondition[] conditions,
			short nConditions,
			PS5000A_CONDITIONS_INFO info);

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aSetTriggerChannelDirectionsV2")]
		public static extern uint SetTriggerChannelDirectionsV2(
			short handle,
			tPS5000ADirection[] directions,
			short nDirections);
Then I added this to private void buttonStart_Click in ps5000aBlockForms.cs. It's pretty self-explanatory:

Code: Select all

Imports.tPS5000ATriggerChannelPropertiesV2[] properties = new Imports.tPS5000ATriggerChannelPropertiesV2[1];

Imports.ThresholdDirection.Rising, delay, auto);

properties[0].thresholdLower = 25000;
properties[0].thresholdUpper = 25000;
properties[0].hysteresisLower = 100;
properties[0].hysteresisUpper = 100;
properties[0].Channel = Imports.Channel.ChannelA;

Imports.tPS5000ACondition[] conditions = new Imports.tPS5000ACondition[1];
conditions[0].source = Imports.Channel.ChannelA;
conditions[0].condition = Imports.TriggerState.True;

Imports.tPS5000ADirection[] directions = new Imports.tPS5000ADirection[1];
directions[0].channel = Imports.Channel.ChannelA;
directions[0].direction = Imports.ThresholdDirection.Above;
directions[0].mode = Imports.ThresholdMode.Level;

status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_CLEAR); //Returns 300.

status = Imports.SetTriggerChannelPropertiesV2(_handle, properties, 1, 1); //Returns 382

status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_ADD); //Returns 0

status = Imports.SetTriggerChannelDirectionsV2(_handle, directions, 1); //Returns 0

status = Imports.SetAutoTriggerMicroSeconds(_handle, 0); //Returns 0


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

Re: Complex Triggering

Post by dfergenson »

I created a fork in my Github account. All of my changes are within the PS5000A folder:

https://github.com/dfergenson/picosdk-c-sharp-examples

Thanks.

-Davio

Post Reply