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

How to recover from a crash


  • Please log in to reply
13 replies to this topic

#1 Mathieu C.

Mathieu C.
  • Members
  • 20 posts

Posted 04 February 2009 - 02:00 PM

Hi,

I use a LabJack U3-LV in my application to stream some data. Since my application is in developpement, it
sometimes crash in the middle of a manipulation.

For some reason, I get the following problem: if I open the U3 port, then read the calibration information and
crash, I am unable to read the calibration again (when I relaunch my application) until I unplug the and replug the U3.

This is an issue for me as the U3 connection might not be easy to access on my system.

I am using the Mac OSX driver. I can reproduce with this test application (See end of post). Run it once and it crashes. Run it again and it
just hangs forever. Is there a way to force a reset to the U3? Or is there a time out to which the read method can return?

Thanks,

Mathieu

#include <stdlib.h>
#include "u3.h"

int main(int argc, char **argv)
{
//Opening first found U3 over USB
HANDLE hDevice = LJUSB_OpenDevice(1, 0, U3_PRODUCT_ID);
int success = (hDevice != NULL);
printf("Open USB: %d\n", success);

//Getting calibration information from U3
if (success)
{
uint8 cU3SendBuffer[26], cU3RecBuffer[38];
int sentRec = 0;
int i = 0;

/* sending ConfigU3 command to get hardware version and see if HV */
cU3SendBuffer[1] = (uint8)(0xF8); //command byte
cU3SendBuffer[2] = (uint8)(0x0A); //number of data words
cU3SendBuffer[3] = (uint8)(0x08); //extended command number

//setting WriteMask0 and all other bytes to 0 since we only want to read the response
for(i = 6; i < 26; i++)
cU3SendBuffer[i] = 0;

extendedChecksum(cU3SendBuffer, 26);

sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, cU3SendBuffer, 26);

printf("\nWILL READ...\n");
sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, cU3RecBuffer, 38);

printf("\nSUCCEEDED\n");

// Force crash
int* ptr = 0;
*ptr = 123;

}

return 0;
}

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 04 February 2009 - 07:16 PM

There is no timeout for the read in the current driver, though in the next release I will add one. To stop the read you can disconnect your device as you know already, or perform the LJUSB_AbortPipe call on pipe U3_PIPE_EP1_IN/U3_PIPE_EP2_IN in a different thread. Through our driver the only way to reset our device is through low-level commands. You may be able to re-enumerate the U3, which would reset the device, through the USB host. This would be an operating system operation, so if you want try this you will need to search online to see if this is possible on the Mac and how to do it.

#3 Mathieu C.

Mathieu C.
  • Members
  • 20 posts

Posted 05 February 2009 - 10:51 AM

There is no timeout for the read in the current driver, though in the next release I will add one. To stop the read you can disconnect your device as you know already, or perform the LJUSB_AbortPipe call on pipe U3_PIPE_EP1_IN/U3_PIPE_EP2_IN in a different thread.

Through our driver the only way to reset our device is through low-level commands. You may be able to re-enumerate the U3, which would reset the device, through the USB host. This would be an operating system operation, so if you want try this you will need to search online to see if this is possible on the Mac and how to do it.


Thanks,
would you know by any chance when the next release is planned?

Mathieu

#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 February 2009 - 03:09 PM

Maybe in 1 to 2 months we'll have the updated driver that has been tested. Currently a new product we are working on is pushing back new releases.

#5 Sean

Sean
  • Members
  • 6 posts

Posted 12 April 2012 - 01:19 PM

To revisit this old issue... The current exodriver now has a timeout. So when our process crashes, and we relaunch it, and try to connect to the LabJack we now get a timeout from LJUSB_DoTransfer. That's fine, but what to do to be able to re-connect to the device (other than unplugging it)? LJUSB_AbortPipe was mentioned, but it's unimplemented. I don't mind using a libusb API directly, but am not sure what to do. Thanks, Sean

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 April 2012 - 02:16 PM

When starting your program after a crash, try throwing in a dummy write/read after opening your device and see if that helps. By dummy write/read, I mean just send a ConfigU3 command like in the first post and read back its response. The read will timeout, but following command/responses should work.

A LJUSB_AbortPipe type command is not needed as it was meant to abort a stalled read. The timeout takes care of this now, and you have the option to set a specific timeout time. If you do want to try toying around with the libusb API it is documented here:

http://libusb.source...-1.0/index.html

I did notice that the Exodriver on Linux, which has the same source code for Mac OS X, does not have this issue after a crash. It seems to be either a libusb and Mac OS X, or Mac OS X operating system USB layer issue. I'll check into this further and see if there is something we can do in the Exodriver to prevent this issue. I will point out though that if your program crashes in the middle of a command/response, you will need the dummy write/reads to resolve the issue in software, or a power cycle.

#7 Sean

Sean
  • Members
  • 6 posts

Posted 05 September 2013 - 11:22 AM

I'm revisiting this again... :)

 

The dummy read works, but now I have another problem.

 

To recap: I start streaming and all is well, then my process crashes, then I relaunch it, then I try to connect to the device, it times out, so I do a ConfigU3 again ("dummy read"), and I get back all the expected values.  Then I do my usual sequence: ReadCal, StreamStop, Feedback, StreamConfig, StreamStart.  I've checked all the returned values and everything is as expected.  Streaming starts, but the samples seem to be all garbage (or maybe there is a pattern that I have yet to discern).

 

One thing I noticed: when everything's working properly, after starting streaming, the first streaming sample I receive has a 'PacketCounter' field value of 0, which makes sense as it's the first sample.  However, when things aren't working, and I get the garbage samples, the first one has a 'PacketCounter' field value of 1 instead of 0.  So I wonder if everything is 'shifted' somehow…

 

Should the first 'PacketCounter' always be 0 after starting streaming?

 

Thanks, Sean



#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 September 2013 - 12:19 PM

Try upgrading your U3 firmware to the latest and see if that helps:

 

http://labjack.com/support/firmware/u3

 

Looking through the firmware history, a while ago there was a fix for an issue that was corrupting Stream data channels. I'm not sure if this is the issue you are seeing.

 

As for the PacketCounter, it should always start at 0 after starting a new stream.



#9 Sean

Sean
  • Members
  • 6 posts

Posted 06 September 2013 - 09:15 AM

I can reproduce this with the newest firmware (1.46) and also with 1.32 and 1.04, and with two different devices.

 

Thanks for confirming that PacketCounter should always start at 0.  As it doesn't, does it seem I've found a firmware bug?  I would be great if you could try to reproduce this on your end, how can I help?  I've added logs everywhere I call LJUSB_* functions so you can see exactly what I'm sending receiving:

 

When things work fine (first line is sent, second line is received):

 

 

• ConfigU3: 0b f8 0a 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
• ConfigU3: dd f8 10 08 c9 03 00 fd ff 2e 01 1b 00 1e 01 77 5f 13 13 03 00 01 40 0f 00 00 00 00 00 00 00 01 00 00 02 00 00 12 
 
• ReadMem: 24 f8 01 2a 00 00 00 00 
• ReadMem: 39 f8 11 2a 03 02 00 00 52 6f 67 75 65 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 
• ReadCal: 2a f8 01 2d 03 00 00 03 
• ReadCal: 29 f8 11 2d ec 05 00 00 a7 dd 14 00 00 00 00 00 3e d4 14 00 00 00 00 00 fd d1 14 00 00 00 00 00 67 d1 14 00 00 00 00 00 
 
• ReadCal: 2b f8 01 2d 04 00 00 04 
• ReadCal: b8 f8 11 2d 6a 17 00 00 cd 06 d7 87 f5 ff ff ff 6d 2d 55 8d f5 ff ff ff b1 ef 5a 91 f5 ff ff ff 07 aa 28 91 f5 ff ff ff 
 
• StreamStop: b0 b0 
• StreamStop: e5 b1 34 00 
 
• ConfigU3: 0b f8 0a 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
• ConfigU3: dd f8 10 08 c9 03 00 fd ff 2e 01 1b 00 1e 01 77 5f 13 13 03 00 01 40 0f 00 00 00 00 00 00 00 01 00 00 02 00 00 12 
 
• StreamStop: b0 b0 
• StreamStop: e5 b1 34 00 
 
• ConfigIO: 0e f8 03 0b 07 00 04 00 00 00 03 00 
• ConfigIO: 56 f8 03 0b 4f 00 00 00 40 00 0f 00 
 
• Feedback: 0d f8 02 00 12 00 00 0d 05 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• Feedback: 0e f8 02 00 13 00 00 0d 06 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• Feedback: 0f f8 02 00 14 00 00 0d 07 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• StreamConfig: b6 f8 06 11 a4 02 03 19 00 09 80 3e 00 1f 01 1f c1 c1 
• StreamConfig: 0b f8 01 11 00 00 00 00 
 
• StreamStart: a8 a8 
• StreamStart: a9 a9 00 00 
 
•• STREAM: 29 f9 1d c0 38 19 00 00 00 00 *00* 00 50 80 70 80 50 ff 70 80 70 80 50 ff 50 80 50 80 50 ff 50 80 60 80 50 ff 50 80 70 80 50 ff 60 80 70 80 50 ff 60 80 60 80 50 ff 60 80 60 80 50 ff 40 80 00 00 99 f9 1d c0 a9 18 00 00 00 00 01 00 60 80 50 ff 50 80 60 80 50 ff 30 80 60 80 50 ff 50 80 60 80 50 ff 50 80 60 80 50 ff 60 80 60 80 50 ff 50 80 50 80 50 ff 40 80 60 80 50 ff 50 80 60 80 00 00 c9 f9 1d c0 d9 18 00 00 00 00 02 00 50 ff 40 80 50 80 50 ff 50 80 50 80 50 ff 50 80 50 80 50 ff 40 80 50 80 50 ff 50 80 40 80 50 ff 60 80 70 80 50 ff 60 80 50 80 50 ff 40 80 60 80 50 ff 00 00 ab f9 1d c0 bb 18 00 00 00 00 03 00 50 80 60 80 50 ff 70 80 70 80 50 ff 40 80 50 80 50 ff 40 80 50 80 50 ff 50 80 50 80 50 ff 60 80 60 80 50 ff 50 80 50 80 50 ff 50 80 70 80 50 ff 50 80 00 00 dc f9 1d c0 ec 18 00 00 00 00 04 00 60 80 50 ff 50 80 60 80 50 ff 50 80 50 80 50 ff 60 80 60 80 50 ff 50 80 50 80 50 ff 60 80 70 80 50 ff 60 80 50 80 50 ff 60 80 40 80 50 ff 60 80 60 80 00 00 
 
Notice the *00*, that's PacketCounter = 0.
 
When things don't work:
 
• ConfigU3: 0b f8 0a 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 
didn't get reply, so tried again (the "dummy read" we've been talking about):
 
• ConfigU3: 0b f8 0a 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
• ConfigU3: dd f8 10 08 c9 03 00 fd ff 2e 01 1b 00 1e 01 77 5f 13 13 03 00 01 40 0f 00 00 00 00 00 00 00 01 00 00 02 00 00 12 
 
• ReadMem: 24 f8 01 2a 00 00 00 00 
• ReadMem: 39 f8 11 2a 03 02 00 00 52 6f 67 75 65 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 
• ReadCal: 2a f8 01 2d 03 00 00 03 
• ReadCal: 29 f8 11 2d ec 05 00 00 a7 dd 14 00 00 00 00 00 3e d4 14 00 00 00 00 00 fd d1 14 00 00 00 00 00 67 d1 14 00 00 00 00 00 
 
• ReadCal: 2b f8 01 2d 04 00 00 04 
• ReadCal: b8 f8 11 2d 6a 17 00 00 cd 06 d7 87 f5 ff ff ff 6d 2d 55 8d f5 ff ff ff b1 ef 5a 91 f5 ff ff ff 07 aa 28 91 f5 ff ff ff 
 
• StreamStop: b0 b0 
• StreamStop: b1 b1 00 00 
 
• ConfigU3: 0b f8 0a 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
• ConfigU3: dd f8 10 08 c9 03 00 fd ff 2e 01 1b 00 1e 01 77 5f 13 13 03 00 01 40 0f 00 00 00 00 00 00 00 01 00 00 02 00 00 12 
 
• StreamStop: b0 b0 
• StreamStop: e5 b1 34 00 
 
• ConfigIO: 0e f8 03 0b 07 00 04 00 00 00 03 00 
• ConfigIO: 56 f8 03 0b 4f 00 00 00 40 00 0f 00 
 
• Feedback: 0d f8 02 00 12 00 00 0d 05 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• Feedback: 0e f8 02 00 13 00 00 0d 06 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• Feedback: 0f f8 02 00 14 00 00 0d 07 00 
• Feedback: fa f8 02 00 00 00 00 00 00 00 
 
• StreamConfig: b6 f8 06 11 a4 02 03 19 00 09 80 3e 00 1f 01 1f c1 c1 
• StreamConfig: 0b f8 01 11 00 00 00 00 
 
• StreamStart: a8 a8 
• StreamStart: a9 a9 00 00 
 
•• STREAM: 0a f9 1d c0 19 19 00 00 00 00 *01* 00 70 80 50 ff 50 80 60 80 50 ff 50 80 60 80 50 ff 60 80 60 80 50 ff 50 80 60 80 50 ff 60 80 60 80 50 ff 50 80 70 80 50 ff 50 80 50 80 50 ff 50 80 70 80 00 00 ea f9 1d c0 f9 19 00 00 00 00 02 00 50 ff 50 80 60 80 50 ff 80 80 70 80 50 ff 60 80 70 80 50 ff 70 80 60 80 50 ff 60 80 60 80 50 ff 70 80 60 80 50 ff 50 80 50 80 50 ff 50 80 70 80 50 ff 00 00 3c f9 1d c0 4b 19 00 00 00 00 03 00 50 80 80 80 50 ff 50 80 70 80 50 ff 80 80 70 80 50 ff 50 80 60 80 50 ff 50 80 60 80 50 ff 50 80 60 80 50 ff 60 80 60 80 50 ff 50 80 50 80 50 ff 60 80 00 00 2d f9 1d c0 3c 19 00 00 00 00 04 00 70 80 50 ff 50 80 60 80 50 ff 60 80 70 80 50 ff 40 80 50 80 50 ff 70 80 50 80 50 ff 60 80 60 80 50 ff 50 80 70 80 50 ff 50 80 60 80 50 ff 60 80 70 80 00 00 bd f9 1d c0 cc 19 00 00 00 00 05 00 50 ff 50 80 50 80 50 ff 60 80 70 80 50 ff 80 80 60 80 50 ff 60 80 70 80 50 ff 50 80 50 80 50 ff 70 80 50 80 50 ff 60 80 60 80 50 ff 50 80 70 80 50 ff 00 00 
 

 

Notice the *01*, that's PacketCounter = 1.


#10 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 06 September 2013 - 03:53 PM

Doing some tests on both a Mac OS X and Linux machine, it looks like this occurs when a StreamData packet is partially read and then the stream is restarted. A crash is not necessary to reproduce the problem, and your crash is most likely interrupting a StreamData read.

 

If you run into the problem of the packet counter starting at 1 after a crash, in your program you can account for this by calling StreamStop to stop the current stream and then StreamStart to start a new stream. This should start your new stream with a correct PacketCounter starting at 0. I'll check if this is something that can be fixed in firmware.



#11 Sean

Sean
  • Members
  • 6 posts

Posted 09 September 2013 - 03:34 PM

Great, thanks for looking into this so promptly.  I think what I'll do is always do a dummy LJUSB_Stream() after starting streaming mode, then stop streaming mode, then start it again.  A quick test here suggests that 'fixes' the problem.  Does that seem reasonable?



#12 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 September 2013 - 03:02 PM

Sounds reasonable. Alternatively, you can also detect the error if the first PacketCounter is not 0 after StreamStart and restart when needed.



#13 Sean

Sean
  • Members
  • 6 posts

Posted 10 January 2014 - 12:01 PM

As it's been a few months, I just wanted to ping this issue… Any news on a firmware fix for this?



#14 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 10 January 2014 - 12:44 PM

Sorry for not updating on the firmware side. The current suggested solution is through software like we mentioned a couple of posts ago. Firmware wise we have this on our list of things to look into but have no timeline on when that will be as we are focusing on T7 development at the moment.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users