Jump to content

Question

Posted (edited)

I'm working with the usb-dio32hs using the universal library for windows.  I've connected my sensor to PD01 and GND and set my trigger using the following code which is c# and I've set my pattern to be the listenString.

DConfigPort(DigitalPortType.AuxPort, DigitalPortDirection.DigitalIn);

this.daqBoard.BoardConfig.SetPatternTrigPort(1);

short low = Convert.ToInt16(listenString, 2);

SetTrigger(TriggerType.TrigPatternEQ, low, short.MaxValue);

message = new ushort[this.contentSize];
MccService.WinBufFreeEx(this.memHandle);
memHandle = MccService.WinBufAllocEx(this.contentSize);
ret = DInScan(DigitalPortType.AuxPort, contentSize, ref rate, memHandle, ScanOptions.ExtTrigger);

The pattern never seems to get detected because it never seems to progress past the DInScan method call.  I've confirmed that the pattern has been generated correctly.  What am I doing wrong.

 

Update to this post, so I changed 

ret = DInScan(DigitalPortType.AuxPort, contentSize, ref rate, memHandle, ScanOptions.ExtTrigger);

to 

 

ret = DInScan(DigitalPortType.AuxPort, contentSize, ref rate, memHandle, ScanOptions.Default);

so it would accept anything and not look at a pattern but turns out that the problem is not that its not seeing the pattern, its not reading any data at all.  When I dump the buffer to an array.  All I see are zeroes.  Its a different problem than what I thought it was.

Edited by Mtd001

Recommended Posts

  • 0
Posted

The UL Help implies that the SetPatternTrigPort function must be used, but it works without it. I've attached the code file from my 32-bit console test app.

I wired the first eight lines from AuxPort0 to AuxPort1 and used AuxPort1 to apply test patterns.

My test app configures the trigger to look for FF on the first eight lines of AuxPort0.  DInScan is called with the scan options for an external trigger and background operation. Background operation causes the DInScan function to return immediately, and the program drops into a while loop. The while loop calls GetStatus and checks for curCount to be greater than 0 to exit the loop. The loop increments a count variable that counts the number of times it calls Sleep(100). When it reaches 40 or about 4 seconds, a DOut function is used to write FF to AuxPort1. This triggers the scan causing the loop to exit. 

I hope this helps..

Program.cs

  • 0
Posted

JRys,  thanks for your help.  I did further digging and the problem seems to be that the usb-dio32hs is not reading the data.  The puzzling thing is that it had been working but  now it doesn’t.  Previously the array used to be filled with 2 and zero corresponding to high and low but now all I’m getting is zeroes.  The only thing I did was some code clean up.  Not completely sure what changes I made but I included the relevant code in my first post
 

as far as wiring I connected the positive lead to pd01 and ground to gnd.  Any debugging tips ?  

  • 0
Posted

Connecting PD01 to the ground is okay if it is an input. 

Remove any and all attached wires. Unplug it, reboot the computer, and plug it back in. Run InstaCal and make sure it is showing up under Universal Serial Bus. Use the Test->Digital function for a quick test on the ports. You could use DAQami to test the individual IO lines.

 

  • 0
Posted

Unplugged and rebooted everything.  Ran test using instacal.  Everything is fine.  One thing to note is that I’m able to do DOutScan just fine.  Having DInscan issues.  Still getting zeroes.  I even applied a constant high on the input in the hope of getting an array of highs.  No luck just seeing zeroes.

  • 0
Posted

Jumper wires from P0D0 - 7 over to P1D0-7 and use our DAQami software to test it. Outputs in DAQami use an Output display type. Inputs use the Scaler display type. Drag the channels onto the display and press the green play button. Inputs will be shown as status lamps, and outputs are switches. Toggle the switches to see the status change.

  • 0
Posted

Not sure what I’m looking at.  Since I’m having issues with input then I should be looking at Scalar ?.  What am I looking for ?

  • 0
Posted

With the code that you just sent me.  How are you wiring your usb-dio32hs ?  I was not able to get a trigger to happen using your code and my dio32hs ?

  • 0
Posted

I have jumper wires connecting AuxPort0 to AuxPort1. However, if you change the SetTrigger threshold values 0x0001 (pattern and mask), then you need only one wire connecting P0D0 to P1D0.

  • 0
Posted

So you are connecting P0D0 - P1D0 all the way to P0D7 - P1D7.  Stupid question but if I’m connecting my signal to P0D0 why would it be necessary to connect to P1 which is AuxPort1 right?  If my pattern is 16 bits won’t my pattern and mask need to be 16 bits as well

  • 0
Posted

I’m playing around with SetTrigger.  If I set TypeTrigger.PatternEQ, 0x6dbd, 0xffff nothing gets triggered, if I do TypeTrigger.pattern above or TypeTrigger.PatternBelow nothing gets triggered but it does get triggered with TypeTrigger.PatternNE.  Not sure I understand

  • 0
Posted

I found a couple of mistakes. There were several changes, so please review the attached code. Notice that the pattern is equal to the mask. It works best this way. When I set the mask to 0xFFFF so that all sixteen lines are evaluated, it fails to detect the pattern.   If you figure out the mask, please let me know.

 

Program.cs

  • 0
Posted

So the documentation is wrong about setting the mask ?  By the way, I should mention that the code I put in my first post actually worked at one point.  I had wired my input to p0d0 and ground but not sure why things stopped working.  I’ll play around with mask a bit more

  • 0
Posted

Ran your code and I can’t get the trigger to happen for mask=pattern and mask = 0xffff.  Just an fyi.  My input goes to p0d0 and gnd.  Anything else you can try ?  I reached out because I was stuck.  Hoping you can reach out to resources that I don’t have access to and get a solution for me.  So aggravated that it use to work and stopped working.  Please help

  • 0
Posted

Another thing that puzzles me is that for SetTrigger.  The only TriggerType that causes a trigger to occur is triggerpatternNE and triggerpatternbelow doesn’t matter what the pattern or mask is.

  • 0
Posted

You're not going to believe this. Pattern and Mask are backward. I switched the low and high thresholds and it worked. Make the low threshold the mask and the high threshold the pattern. Let me know how it goes, thanks.

  • 0
Posted

my code

        private void Init()
        {
            MccDaq.DaqDeviceManager.IgnoreInstaCal();
            
            this.BoardNum = this.GetBoardNumber();
            this.daqBoard = new MccBoard(this.BoardNum);
            
            this.ret = this.daqBoard.DConfigBit(DigitalPortType.AuxPort0, 0,DigitalPortDirection.DigitalIn);
            this.ret = this.daqBoard.BoardConfig.SetPatternTrigPort(1);
        }

 

        private void Listen(ContentData model)
        {
            this.rate = model.Rate;
            this.size = model.Size;
            this.BoardNum = 0;
            this.messageList = new List<ushort[]>();
            this.SetTrigger();
            MccService.WinBufFreeEx(this.memHandle);
            this.memHandle = MccService.WinBufAllocEx(200);
            ret = this.daqBoard.DInScan(DigitalPortType.AuxPort0, 200, ref this.rate, memHandle, ScanOptions.ExtTrigger|ScanOptions.Background);
            short dataValue;
            short status;
            int currentCount = 0;
            int currentIndex = 0;
            int eventCount;

            do
            {
                ret = this.daqBoard.GetStatus(out status, out currentCount, out currentIndex, FunctionType.DiFunction);

            } while (currentCount < 200);


            var message = new ushort[200];

            ret = MccService.WinBufToArray(memHandle, message, 0, 200);

 

}

 

        public void SetTrigger()
        {
            ret = this.daqBoard.BoardConfig.SetPatternTrigPort(1);
            ret = this.daqBoard.DConfigBit(DigitalPortType.AuxPort0, 0, DigitalPortDirection.DigitalIn);
            short low = Convert.ToInt16(Communication.listenString, 2);
            ret = this.daqBoard.SetTrigger(TriggerType.TrigPatternEQ, 0xffff, 0x6dbd);
        }
 

what am I missing.  Also I'm wiring input to P0D0 and GND.

 

 

  • 0
Posted

Put a 10 millisecond thread.sleep in the do..while. 

I tried 0x6DBD, and it worked. 

Check the firmware version with InstaCal. It is on the Install->Configuration panel and it should be 1.0 or greater. 

  • 0
Posted

image.png.a24565b133731582f750d0a7f4504d77.png

 

The following is your code that I modified to invert the mask and pattern.  Additionally 

my current wiring is connected to P0d0 and GND.  Still doesn't work for me.

 

using System;
using MccDaq; //added to project references


namespace DigitalOutput
{


    class Program
    {
        public const string DEVICE = "DIO32HS"; //identify the board using string name
        public const int SAMPLES = 100;
        public const ushort PATTERN = 0x6dbd;

        public static MccDaq.MccBoard Discover(string dev)
        {

            //this ignores devices listed in InstaCal utility
            MccDaq.DaqDeviceManager.IgnoreInstaCal();

            //get inventory of MCC USB devices
            MccDaq.DaqDeviceDescriptor[] inventory = MccDaq.DaqDeviceManager.GetDaqDeviceInventory(MccDaq.DaqDeviceInterface.Usb);

            int numDevDiscovered = inventory.Length;

            if (numDevDiscovered > 0)
            {   //loop through inventory looking for device
                for (int boardNum = 0; boardNum < numDevDiscovered; boardNum++)
                {

                    try
                    {

                        if (inventory[boardNum].DevString.Contains(dev))
                        {
                            MccDaq.MccBoard daqBoard = MccDaq.DaqDeviceManager.CreateDaqDevice(boardNum, inventory[boardNum]);
                            return daqBoard;
                        }

                    }
                    catch (ULException ule)
                    {
                        Console.WriteLine("Error occured: " + ule.Message);
                    }
                }
            }
            return null;

        }

        static void Main(string[] args)
        {

            MccDaq.ErrorInfo RetVal;


            MccBoard daq = Discover(DEVICE);


            if (daq == null)
            {
                Console.WriteLine("Board not detected!\n");
                WaitForKey();
            }
            else
            {

                try
                {


                    RetVal = daq.DConfigBit(DigitalPortType.AuxPort0, 0, DigitalPortDirection.DigitalIn);

                    RetVal = daq.BoardConfig.SetPatternTrigPort(1);
                    if (RetVal.Value != 0)
                        Console.WriteLine("SetPatternTrigPort error {0}", RetVal.Value);

                    RetVal = daq.SetTrigger(TriggerType.TrigPatternEQ, 0xFFFF,PATTERN);
                    if (RetVal.Value != 0)
                        Console.WriteLine("SetTrigger error {0}", RetVal.Value);

                    int rate = 1000;
                    IntPtr buffer = MccService.WinBufAllocEx(SAMPLES);

                    RetVal = daq.DInScan(DigitalPortType.AuxPort0, SAMPLES, ref rate, buffer, ScanOptions.ExtTrigger | ScanOptions.Background);

                    if (RetVal.Value != 0)
                        Console.WriteLine("DInScan error {0}", RetVal.Value);

                    short status = 0;
                    int curCount = 0;
                    int curIndex = 0;
                    RetVal = daq.GetStatus(out status, out curCount, out curIndex, FunctionType.DiFunction);

                    while (curCount < 10)
                    {

                        RetVal = daq.GetStatus(out status, out curCount, out curIndex, FunctionType.DiFunction);

                        System.Threading.Thread.Sleep(20);

                        if (Console.KeyAvailable) break;
                    }


                    ushort[] UserBuffer = new ushort[SAMPLES];
                    MccService.WinBufToArray(buffer, UserBuffer, 0, SAMPLES);
                    for (int i = 0; i < 10; i++)
                        Console.WriteLine("Buffer[{0}] = {1}H", i, (PATTERN & UserBuffer[0]).ToString("X"));

                    Console.ReadKey();
                    WaitForKey();

                    //stop background operation
                    daq.StopBackground(FunctionType.DiFunction);

                    //free up memory
                    MccService.WinBufFreeEx(buffer);

                    MccDaq.DaqDeviceManager.ReleaseDaqDevice(daq);
                }

                catch (ULException ule)
                {
                    Console.WriteLine("Error occured: " + ule.Message);
                }

            }
        }
        /*////////////////////////////////////////////////////////////////////////////////////*/

        public static void WaitForKey()
        {
            Console.WriteLine("\nPress any key to continue...");
            do
            {
                System.Threading.Thread.Sleep(20);

            } while (!Console.KeyAvailable);
            ConsoleKeyInfo cki = Console.ReadKey();

        }
    }
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...