« Close

Datasheets and User Guides

App Notes

Software & Driver

 

8.4 - Handling Disconnect / Reconnect

The most useful thing to catch in OnAlert is the pseudo-error codes LJE_DISCONNECT and LJE_RECONNECT. LJE_DISCONNECT is probably more useful as an alarm type alert to tell you that you accidentally unplugged the LabJack, and should maybe make the screen red or something similar. LJE_RECONNECT, however, provides a way for you to ensure that the LabJack is reset to a known state on power-up. Yes, the LabJack has the ability to set power-on defaults, but you may want different defaults depending on what document you are running. The best way to do this is to create a sequence will all the commands to set your default LabJack settings. You'll want to call this from a sequence marked AutoStart so the LabJack gets configured when you load the document. You'll then also want to add code like this to the OnAlert sequence / system event to call that configuration code when a reconnect occurs:


if (left(strAlert,13) == "D0050:00:2001") // 2001 is LJE_RECONNECT
   ConfigureLJ()
endif

This of course assumes that your configuration sequence is called ConfigureLJ. We can use Left() instead of Find() because Disconnect and Reconnect errors never come from Channel Timing loops.

Now, if you have multiple LabJacks, you'll also need to look at which LabJack got reconnected. In the example above, we assumed a D# / ID of 0, meaning first found. To further parse it:


if (left(strAlert,6) == "D0050:") // we have a labjack error
   private ID = strtodouble(mid(strAlert,6,2)) // retrieve ID
   if (mid(strAlert,9,4) == "2001") // reconnect
      ConfigureLJ(ID)
   endif
endif

This assumes that ConfigureLJ is setup to take the desired ID as the parameter. You might instead want to use a separate sequence for each ID.

This code just uses basic string manipulation functions to pull out the appropriate information:

left(s, n) returns the first n characters from the string s.

mid(s, i, n) returns n characters from character number i in the string s. Like everything else in DAQFactory, i is zero indexed, so the first character of the string is i = 0.

strtodouble(s) converts the given string s into a number.