Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

U3 C# Watchdog


  • Please log in to reply
10 replies to this topic

#1 davidwatson

davidwatson
  • Members
  • 9 posts

Posted 13 December 2010 - 10:49 AM

I have been trying to configure the watchdog so that it sets a digital line high on a time-out but does not reset the LabJack. I have tried the following but I never see the signal. Has anyone implemented the watchdog in C#? Thanks using System; using System.Collections.Generic; using System.Text; using LabJack.LabJackUD; namespace WatchDog { class Program { private U3 m_U3; static void Main(string[] args) { Program a = new Program(); a.PreformActions(); } public void ShowErrorMessage(LabJackUDException e) { Console.Out.WriteLine("Error: " + e.ToString()); if (e.LJUDError > U3.LJUDERROR.MIN_GROUP_ERROR) { Console.ReadLine(); // Pause for the user Environment.Exit(-1); } } public void PreformActions() { //Connection through USB to U3 m_U3 = new U3(LJUD.CONNECTION.USB, "0", true); //Reset pin assignments to factory default condition. LJUD.ePut(m_U3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0 to FIO3 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000001111. LJUD.ePut(m_U3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16); bool requestedExit = false; while (!requestedExit) { Console.Out.WriteLine("Enter \'E\' to enbale WatchDog, \'D\' to disable it or \'Q\' to Quit"); String requested = Console.ReadLine(); if (requested.Equals("E", StringComparison.OrdinalIgnoreCase)) Enable(); else if (requested.Equals("D", StringComparison.OrdinalIgnoreCase)) Disable(); else if (requested.Equals("Q", StringComparison.OrdinalIgnoreCase)) requestedExit = true; else Console.Out.WriteLine("Unsupported input"); } } private void Enable() { try { m_U3.u3Config(); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 10, 0, 0, 0); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_RESET_DEVICE, 0, 0, 0); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_UDPATE_DIOA, 1, 0, 0); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_CHANNEL, 10, 0, 0); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_STATE, 1, 0, 0); LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_ENABLE, 10, 0, 0); LJUD.GoOne(m_U3.ljhandle); } catch (LabJackUDException e) { ShowErrorMessage(e); } } private void Disable() { LJUD.ePut(m_U3.ljhandle, LJUD.IO.SWDT_CONFIG, LJUD.CHANNEL.SWDT_DISABLE, 0, 0); } } }

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 December 2010 - 12:59 PM

I have been trying to configure the watchdog so that it sets a digital line high on a time-out but does not reset the LabJack. I have tried the following but I never see the signal. Has anyone implemented the watchdog in C#?
Thanks

using System;
using System.Collections.Generic;
using System.Text;
using LabJack.LabJackUD;

namespace WatchDog
{
class Program
{
private U3 m_U3;

static void Main(string[] args)
{
Program a = new Program();
a.PreformActions();
}

public void ShowErrorMessage(LabJackUDException e)
{
Console.Out.WriteLine("Error: " + e.ToString());
if (e.LJUDError > U3.LJUDERROR.MIN_GROUP_ERROR)
{
Console.ReadLine(); // Pause for the user
Environment.Exit(-1);
}
}

public void PreformActions()
{
//Connection through USB to U3
m_U3 = new U3(LJUD.CONNECTION.USB, "0", true);

//Reset pin assignments to factory default condition.
LJUD.ePut(m_U3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);

//Configure FIO0 to FIO3 as analog, all else as digital. That means we
//will start from channel 0 and update all 16 flexible bits. We will
//pass a value of b0000000000001111.
LJUD.ePut(m_U3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16);

bool requestedExit = false;
while (!requestedExit)
{
Console.Out.WriteLine("Enter \'E\' to enbale WatchDog, \'D\' to disable it or \'Q\' to Quit");

String requested = Console.ReadLine();

if (requested.Equals("E", StringComparison.OrdinalIgnoreCase))
Enable();
else if (requested.Equals("D", StringComparison.OrdinalIgnoreCase))
Disable();
else if (requested.Equals("Q", StringComparison.OrdinalIgnoreCase))
requestedExit = true;
else
Console.Out.WriteLine("Unsupported input");
}
}

private void Enable()
{
try
{

m_U3.u3Config();

LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 10, 0, 0, 0);
LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_RESET_DEVICE, 0, 0, 0);
LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_UDPATE_DIOA, 1, 0, 0);
LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_CHANNEL, 10, 0, 0);
LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_STATE, 1, 0, 0);
LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_ENABLE, 10, 0, 0);
LJUD.GoOne(m_U3.ljhandle);
}
catch (LabJackUDException e)
{
ShowErrorMessage(e);
}
}

private void Disable()
{
LJUD.ePut(m_U3.ljhandle, LJUD.IO.SWDT_CONFIG, LJUD.CHANNEL.SWDT_DISABLE, 0, 0);
}
}
}


Your code looks good except for one part, the following code:

LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_ENABLE, 10, 0, 0);


it should use the LJUD.IO.SWDT_CONFIG I/O Type instead, like in the

LJUD.ePut(u3.ljhandle, LJUD.IO.SWDT_CONFIG, LJUD.CHANNEL.SWDT_DISABLE, 0, 0);

line of code. Thus:

LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.SWDT_CONFIG, LJUD.CHANNEL.SWDT_ENABLE, 10, 0, 0);

will work. I tested it by enabling the reset and found the U3 to reset if there was no communication after 10 seconds.

#3 davidwatson

davidwatson
  • Members
  • 9 posts

Posted 10 January 2011 - 06:28 AM

Hi, Thanks for spotting the issue with the code I have now come back to this project after some distractions and will be able to complete it now. Regards, David

#4 davidwatson

davidwatson
  • Members
  • 9 posts

Posted 11 January 2011 - 05:04 AM

Hi, I have found that the U3 will reset with your change but I can't get an IO line to go high on a watchdog timeout. I have tried this with and without resetting the U3 on time out but I never see the EI02 go high. The new code is below. Thanks for your help private void EnableWatchDog() { try { //Set EI02 to output low LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 10, 0, 0, 0); //Specify if the device should be reset on timeout. if (this.rbResetU3Disabled.Checked) LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_RESET_DEVICE, 0, 0, 0); else LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_RESET_DEVICE, 1, 0, 0); //Specify that the state of the digital line should be updated on timeout. LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_UDPATE_DIOA, 1, 0, 0); //Specify that EIO2 is the desired digital line. LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_CHANNEL, 10, 0, 0); //Specify that the digital line should be set high. LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SWDT_DIOA_STATE, 1, 0, 0); int timeout = System.Convert.ToInt32(this.tbWatchDogTimeOut.Text); //Don't set timeout below 10 seconds if (timeout <= 10) timeout = 10; LJUD.AddRequest(m_U3.ljhandle, LJUD.IO.SWDT_CONFIG, LJUD.CHANNEL.SWDT_ENABLE, timeout, 0, 0); LJUD.GoOne(m_U3.ljhandle); Log.LogMessageToFile(LogLevel.Trace, m_Config.ID, "Set WatchDog Timeout to " + timeout); } catch (LabJackUDException e) { Log.LogMessageToFile(LogLevel.Error, m_Config.ID, e.ToString()); } }

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 January 2011 - 09:40 AM

I have firmware V1.32 and UD driver V3.24. I tried testing in LJControlPanel and it did not work for me either, so we will have to look closer. I used "Config Defaults" to set EIO2 to power-up as output-low and to enable the watchdog at power-up with 10 second timeout and on timeout to set EIO2 high. I noticed that the EIO2 kept changing to EIO6 in the window after I wrote the changes, so I suspect a firmware problem.

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 January 2011 - 02:42 PM

OK, got to the bottom of this. The depreciated watchdog command is being called by the driver and not interpreted properly by the U3. The problem is that the depreciated command uses bit 4 of the settings byte to enable the DIO response where the other command uses bit 3 for one DIO and bit 4 for a second DIO. The result is that the second DIO was being enable and the first was being filled in. So, not only was EIO2 not changing, but FIO0 may have been changing.

A new beta firmware is available that moves the controlling bit accordingly. You can get Beta 1.36 here: http://labjack.com/s...irmware/u3/beta

#7 davidwatson

davidwatson
  • Members
  • 9 posts

Posted 13 January 2011 - 08:01 AM

Thanks for the quick response and before trying the beta firmware I updated the UD Driver to match yours and now I can't run LJControlPanel or the LJSelfUpgrade. LJStreamUD and LJLogUD both rum okay. I have attached the error messages

Attached Thumbnails

  • LJControlPanel.png
  • LJSelfUpgrade.png


#8 davidwatson

davidwatson
  • Members
  • 9 posts

Posted 13 January 2011 - 08:21 AM

Hi I found a newer version of the UD driver (3.25) and that has fixed the app issues so I can now try the Beta FW which I can confirm has also fixed the watchdog issue :-) Can you let me know when will the Beta FW testing be completed? Thanks again for your help Regards David

#9 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 January 2011 - 04:04 PM

Beta 1.36 will probably be the released version in a few days, assuming that no problems are found.

#10 ocean62

ocean62
  • Members
  • 1 posts

Posted 27 March 2014 - 07:40 AM

Hello you said

//Configure FIO0 to FIO3 as analog, all else as digital. That means we
//will start from channel 0 and update all 16 flexible bits. We will
//pass a value of b0000000000001111.
LJUD.ePut(m_U3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16);

 

i'm using labjack U3 and i want as analogue FIO0 to FIO7 and others digital.

How can i say that and can u explain me what the numbers 0,15,16 stands for so i can adjust it my self?



#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 March 2014 - 09:30 AM

The value b0000000000001111 is a bitmask, so each bit of the number corresponds with one of the FIO lines, or EIO, depending on the bit.  So, 0b0000000000000001 means that all lines are set to digital, except the very first one, which is FIO0-> FIO0 will be analog. As another example, 0b1111111100000000 will set EIO0-7 to analog, and it will leave FIO0-7 as digital. 

 

To convert the bitmask 0b1111111100000000 into a normal number, just use 'scientific mode' of the Microsoft calculator in Windows, set the calculator input to "Bin" and enter "1111111100000000", then set the calculator to "Dec".  The result is 65280, so the function call would look like this:

LJUD.ePut(m_U3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 65280, 16);

 

http://labjack.com/s...3-eget-and-eput




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users