Loading ...
Sorry, an error occurred while loading the content.

Failed object creation

Expand Messages
  • Jeff Medkeff
    Hi all, We ve had a few conversations about strange behavior in which scripting code, trying to create an object, fails to do so, but a second try succeeds. I
    Message 1 of 1 , Dec 8, 2000
    View Source
    • 0 Attachment
      Hi all,

      We've had a few conversations about strange behavior in which scripting
      code, trying to create an object, fails to do so, but a second try
      succeeds. I have a possible explanation for this for the programmers out
      there to pass judgement on and I propose a possible solution (or, perhaps
      "workaround" would be a better way of putting it).

      It appears that scriptlets have a property called ReadyState and something
      called OnReadyStateChange can be used to determine when a scriptlet
      component is loaded and ready for use. The implication in the documentation
      I read was that when using a scriptlet, the script programmer should poll
      (or use an event, if OnReadyStateChange is an event, as it sounds) to make
      sure the scriptlet is ready before using it. A scriptlet can be treated
      very much like an object, so....

      This got me to thinking, and I wrote a bit of VBScript code which is (on
      one particular computer only!), 100% guaranteed to fail to create the Maxim
      camera object. The failing code looks like this:

      Set cam = CreateObject("MaxIm.CCDCamera")
      cam.LinkEnabled = True
      cam.CoolerOn = True

      However, I find that this code works 100% of the time on the same computer
      (the "util" object comes from ACP) (Lets call this "case A"):

      Set cam = CreateObject("MaxIm.CCDCamera")
      util.waitformilliseconds 500
      cam.LinkEnabled = True
      cam.CoolerOn = True

      This also works (call this "case B"):

      Set cam = CreateObject("MaxIm.CCDCamera")
      cam.LinkEnabled = True
      util.waitformilliseconds 500
      cam.CoolerOn = True

      This does not work ("case C"):

      Set cam = CreateObject("MaxIm.CCDCamera")
      cam.LinkEnabled = True
      cam.CoolerOn = True
      util.waitformilliseconds 500

      This suggests to me that when an object is being created, procedural flow
      control is given back to the script prior to completion of the command. If
      so it would be possible to call cam properties and methods *before* the
      object actually exists. Case A is what suggests this to me - a half second
      delay after creating the cam object allows us to hit the cam object with
      impunity.

      Case B suggests to me that it may possibly be that (a) the scripting host
      is somehow queueing the cam.linkenabled line, or more likely (b) that the
      cam.linkenabled line causes parallel port activity which takes time to
      develop, but, during that time, procedural flow control is given back to
      the script causing the cooleron line to fail because, of course, the
      parallel port isn't yet ready at a much lower level of the system. I.e., I
      am suggesting that Win32's multitasking may be the problem, here.

      Case C provides some semblance of control on the above two hypotheses.

      If either of these two hypotheses are correct, they could also explain why
      some programs' objects are affected by the problem than others. In this
      particular case, Maxim would be more vulnerable than programs that are
      coded in more sloppy ways, in my opinion (but I won't go into that).

      I'll let the programmers comment on whether I may be right or not. But in
      the meantime I thought I would suggest that we evaluate our object
      creation. We might try:

      Set cam = CreateObject("MaxIm.CCDCamera")
      Do While Not IsObject(cam)
      util.waitformilliseconds 50 ' 1/20 second
      Loop
      cam.LinkEnabled = True
      Do While Not cam.LinkEnabled 'may not be needed
      util.waitformilliseconds 50 '
      Loop '
      cam.CoolerOn = True

      Or we might just insert arbitrary (preferably empirically tested for a
      given system) delays after object creation. (You may want to be careful
      about using the above code as given - I'm tossing it out off the top of my
      head, and the top of my head is not necessarily a reliable place to be.)
      Whatever the *cause* of the problem - and I'm not at all certain I've
      explained the correct cause here - if the idea of testing for the objects
      *works* then at least we have a workaround for the problem.

      Offered for your edification....


      --
      Jeff Medkeff
      Hereford, Arizona
    Your message has been successfully submitted and would be delivered to recipients shortly.