LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial write not working in state machine

Hi Folks.

 

I have a state machine program that has been working fine. I recently added a tab control to do some config writes and reads. However the serial write part (load device, unload, up and down buttons) is not working now. I feel it may be to do with the tab control but I cannot figure out what is causing it. Any ideas??

 

Thanks,

 

Mark.

0 Kudos
Message 1 of 6
(3,463 Views)

Do you plan on going back and re-writing the code from scratch at any point? Because you should. This code looks like it's really gotten out of hand with add-on after add-on. You shouldn't have a million shift registers, instead you should have a single shift register (or maybe just a few) that is a cluster of everything you need. You should also handle your error with a merge at some point so that you don't have a dozen error cluster shift registers.

 

You shouldn't use the tab control to control the code. You should really use it just to control what the user can and cannot see/touch on the front panel to limit them that way. By controlling which code can run by linking it to a case structure, you're very easily going to run in to problems like you're seeing now. I remember making an application like this when I was first starting and I thought I was a genius for segmenting my code like that so all the other unused code didn't slow down my application when it wasn't needed. Then my application kept freezing...

 

Your Setup tab has all of the outputs from the case set to Default when not wired... This is probably the source of your issue. You're losing those shift register values because of this. I grimace while I type this, but you might fix your problem by wiring through the wires to all those terminals. This will still look really messy, but might do the trick with minimal effort.

You can also assign the Linked Input Terminal using the right-click menu when clicking on an output terminal. This will help you with your specific problem, but is really messy if you do it a lot.

 

P.S. Take a look at the Simple State Machine template that ships with LabVIEW. This will give you an idea of what the state machine should look like.

P.S.S. Use subVIs.

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 2 of 6
(3,449 Views)

Unfortunately that did not solve the problem. I also put an indicator on the wire beside the visa write and its blank. Is the wiring from the read config as string to the serial config vi the problem. It has one of those red dots which usually means trouble??

0 Kudos
Message 3 of 6
(3,434 Views)

You have 11 VISA Write functions in your code, so I'm not sure where you're referring to.

 

The red coercion dot is okay in this instance because you're reading the resource name from file as a string and coercing it to be the VISA resource name (a fancy string).

 

To figure out your problem, go through and probe every single wire that pertains to your serial comms. I bet you'll run in to a spot where the reference gets lost or some data to write gets lost. Just trace out your code from case to case in your structure til you find it.

 

Make sure you double click your wires to find where they're actually connected (this will highlight the whole wire)... I just double clicked your serial resource name wire and it goes to a different shift register than I would have guessed by looking at the routing. You should really contemplate rewriting all of this to make it much neater.

 

Edit: I traced out that same shift register wire and it doesn't seem to make its way back to that shift register as far as I can tell (It's hard to tell). You need to go through and check all of your wires to make sure you're not losing your references from iteration to iteration of your main loop. This can be much much much much much much more simple if you re-write the code to be more encapsulated with a cluster of data. Pleeeaaase look at the Simple State Machine example/template that ships with LabVIEW.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 4 of 6
(3,420 Views)

It turns out that the timeout case was not wired and so was setting back to default. Thanks for the tips, particularly replacing all the shift registers with clusters. Makes things way more neater now.

 

Mark.

0 Kudos
Message 5 of 6
(3,369 Views)

Glad you figured it out! If you need more help, let us know.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 6
(3,346 Views)