Change EIO (relay) value in sequence but it changed back on its own


Recommended Posts

Hi everyone,

 

I am a new user of DAQFactory and LabJack, I have my test set up and I have tested all the channels I need to acquire data with as well as the EIO2 and EIO3 relay control.

For EIO2 and EIO3, I have tested them use simple sequence one liner: LJM_eWriteName(any,"EIO2",1) or LJM_eWriteName(any,"EIO2", 0) and use button component on the dashboard.

 

However for my real test, everything needs to be automated so I started to write code to flip the EIO relays. Below is what I found (issue)

while(1)
   if(LJM_eReadName(any,"EIO3")==0)
      LJM_eWriteName(any,"EIO3",1)      
   endif
   if(LJM_eReadName(any,"EIO3")==1)     
      break
   endif
   delay(0.01)
endwhile   

?LJM_eReadName(any,"EIO3")     
delay(3)
?LJM_eReadName(any,"EIO3")

For above code, the logic is simple, if EIO3 is 0, we make sure to set it to 1 before break out of the loop, and I use two prints to check the result, surprisingly, the first print showed 1, which was good, but the second one (after 3 seconds), it gave me 0.

 

So I commented out all above code and wrote below code to check if it's automatically turning back to 0 due to LabJack hardware or something (I think not, as I used to use multimeter to check the relay physically, if it's 1, it stayed as closed circuit)

LJM_eWriteName(any,"EIO3",1)
?LJM_eReadName(any,"EIO3")     
delay(3)
?LJM_eReadName(any,"EIO3")

This time, both prints gave me 1, so it must be something with the while of if statement, but I can't figure it out, can somebody help me? Thanks a bunch.

Link to comment
Share on other sites

First, it is much cleaner to use Channels for doing digital control.  It is also more efficient because DAQFactory can optimize things for you. 

Second, if the readback is switching on you then something is switching the output somewhere else.  This could be another script, or something internal to the LabJack itself like Lua.  The fact that you feel you have to verify that an output is being set makes me think that you do have other logic somewhere that is changing it.  Otherwise you should just be able to do EIO3 = 1 and it will either turn on or throw an error.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.