Jump to content

combobox taking only last value


Recommended Posts

Hi,

I want to display 3 strings in combox and it depends on read value from read visa.

My program is working good in highlighed mode i.e. combox is displaying all the three values in it.

but in case of normal run it is only displaying first string alltime i.e.10

Why it is like that please ...some help me. I guess the problem is with stroing into combobox. how can i store all the read values in to array then to combobox all.

post-20037-0-22987700-1301840757_thumb.p

Link to comment

Is it specific to the combo box? What do you see when you put a probe on the string array wire? Also have you tried temporarily changing the wait 0mS to wait longer? Since it works with highlight execution I would suspect that in normal run the device has not responded yet where you are checking the number of bytes at serial port. If the device has not responded yet it will return zero.

If waiting longer fixes it then that is not the best fix. It just tells you where the problem is. The best thing would be to use some kind of handshaking. Does your device send a termination character? Does it send a fixed length reply? If not then it gets a little bit more tricky. One solution in that case would be to loop until bytes at serial port is not zero. Be careful with that because that loop will not exit if your device does not respond. You would have to implement a timeout using a small state machine.

Link to comment

Is it specific to the combo box? What do you see when you put a probe on the string array wire? Also have you tried temporarily changing the wait 0mS to wait longer? Since it works with highlight execution I would suspect that in normal run the device has not responded yet where you are checking the number of bytes at serial port. If the device has not responded yet it will return zero.

If waiting longer fixes it then that is not the best fix. It just tells you where the problem is. The best thing would be to use some kind of handshaking. Does your device send a termination character? Does it send a fixed length reply? If not then it gets a little bit more tricky. One solution in that case would be to loop until bytes at serial port is not zero. Be careful with that because that loop will not exit if your device does not respond. You would have to implement a timeout using a small state machine.

After increasing the time between write and read also not working. Really, i don't know why. It is executing exactly in highlight execution mode. once If change that to normal mode, then it is only displaying one string in it. you can see my attched vi for futhur errors. never mind about other cases, still i am doing them.

Actuvally this not the way i want. I want to write all the possible addresses from 0 to 64(hex) and i will display available address in dropdown list according to the read data. I have to take for loop indexing and writing them in order. So, i did not got any reply in that case. So, i am only writing three adresses which i know that they are available in my serial device. Still i have lot of problems and did not get a way from one week. its working only in highlight mode. why? i have attched highlight mode, normal mode and my file. Can help where is the mistake.

Please help me out of this error hell.

post-20037-0-66785800-1301844694_thumb.p

post-20037-0-46538800-1301844721_thumb.p

GUI.vi

Link to comment

Now I can see that you are explicitly disabling the termination character so I guess that answers my question and you know your device does not send one.

You changed the wait to only 5mS. Highlight execution would cause a much longer delay. Try changing it to 100 or even 1,000 as a test to isolate the problem. Maybe you already tried that but it is not clear.

I can see that the combo box has empty values after the first one. Is that what you see when putting a probe on the input to the Strings[] property node?

I also notice that you are using the same pattern of write, wait, read in many places. You should make that into a subvi.

post-17905-0-21319800-1301846366_thumb.p

I also changed it so that the array of strings is built in a shift register.

post-17905-0-58595700-1301850443_thumb.p

But after looking more closely I am kind of confused. I thought that you were creating the combo box entries from the results of the read. It looks like you want to create entries if the read returns something other than zero and the entry is the for loop iteration in hex. I did not notice that the N terminal had a 50 wired to it. I can not figure out how you only have three entries in your combo box instead of 50. Can you try putting an array size function on the input to the property node and see what that returns?

[EDIT] Ok now it makes sense. The code you posted is not the same as the image you posted above. In the code image above you have a three element string array constant auto indexing the loop. No wonder I didn't notice the 50 wired to the N terminal. It wasn't there before.

Just a side note and I hope it doesn't sound preachy. Personally I always keep the block diagram as neat as possible and don't worry much about the FP. I live in the BD. When my mind is busy thinking about how to solve a problem I sometimes use that time to clean up wires and arrange nodes. I only do this with parts of the code that have something to do with the problem to keep my thoughts focused.

Link to comment

Now I can see that you are explicitly disabling the termination character so I guess that answers my question and you know your device does not send one.

You changed the wait to only 5mS. Highlight execution would cause a much longer delay. Try changing it to 100 or even 1,000 as a test to isolate the problem. Maybe you already tried that but it is not clear.

I can see that the combo box has empty values after the first one. Is that what you see when putting a probe on the input to the Strings[] property node?

I also notice that you are using the same pattern of write, wait, read in many places. You should make that into a subvi.

post-17905-0-21319800-1301846366_thumb.p

I also changed it so that the array of strings is built in a shift register.

post-17905-0-58595700-1301850443_thumb.p

But after looking more closely I am kind of confused. I thought that you were creating the combo box entries from the results of the read. It looks like you want to create entries if the read returns something other than zero and the entry is the for loop iteration in hex. I did not notice that the N terminal had a 50 wired to it. I can not figure out how you only have three entries in your combo box instead of 50. Can you try putting an array size function on the input to the property node and see what that returns?

[EDIT] Ok now it makes sense. The code you posted is not the same as the image you posted above. In the code image above you have a three element string array constant auto indexing the loop. No wonder I didn't notice the 50 wired to the N terminal. It wasn't there before.

Just a side note and I hope it doesn't sound preachy. Personally I always keep the block diagram as neat as possible and don't worry much about the FP. I live in the BD. When my mind is busy thinking about how to solve a problem I sometimes use that time to clean up wires and arrange nodes. I only do this with parts of the code that have something to do with the problem to keep my thoughts focused.

I am from india and i am so happy now, Your are my god of today. After changing the delay into 150ms it is working good. no more problems. I haven't studied your description clearly.

I have one problem that, now i changed my forloop to 100 iterations. i am getting all the replies in combobox but the combobox is displaying all the output of 100 iterations even though there is no output. If no read data means it is displaying empty in that place. if it reads any data from read visa then it is also displaying that address on combobox. Therefore the combobox is displaying all the values in it even no output(empty place). how can sort out all the string and display one after another. You can see in the following image.

As you said in above with array and shift register to combobox for eliminating these empty spaces is not working i.e. the combo box is hanged if i run the vi and I checked for the addresses in it. then it is freezesd and not all droping down. how to remove this problem.

post-20037-0-82238500-1301854635_thumb.p

Link to comment

Did you wire the shift register through in the other case, the zero case? That case should be empty other than wiring the shift register through.

As for the UI freezing this can be expected. The UI will freeze until everything in the event structure is done. You can try right clicking on the event, select edit events handled by this case and unselect Lock front panel at the bottom. That is not the right way to do this and you should read the help to understand what the implications are. It is recommended that you put all of the processing in another loop outside of your event loop. It means rewriting your application to use a producer/consumer architecture. There are many good articles about this.

Have you used the LabVIEW project? With one vi like you have it doesn't make a lot of sense to use it. But if you were to rewrite this to use a producer/consumer design with subvis and typedefs it really helps.

Link to comment

Did you wire the shift register through in the other case, the zero case? That case should be empty other than wiring the shift register through.

As for the UI freezing this can be expected. The UI will freeze until everything in the event structure is done. You can try right clicking on the event, select edit events handled by this case and unselect Lock front panel at the bottom. That is not the right way to do this and you should read the help to understand what the implications are. It is recommended that you put all of the processing in another loop outside of your event loop. It means rewriting your application to use a producer/consumer architecture. There are many good articles about this.

Have you used the LabVIEW project? With one vi like you have it doesn't make a lot of sense to use it. But if you were to rewrite this to use a producer/consumer design with subvis and typedefs it really helps.

Yeah,people suggested that model but i don't know how to convert this program into that way. So, I am just continuing with this. Don't know what is going to happen in future. I am very new to labview and afraid of this changing. Again, if some thing happens, i should have to put all the stuff in forums and simply waste the time for people replies. Don't know what to do. You have any good material for that model. i will try.

Link to comment

The program is simple enough. If I can find some time I would be happy to set it up into a producer/consumer design pattern. But I have a couple of questions.

Forget about the architecture for now. If I were to help you with this I need to know if you are familiar with the following concepts.

  • clusters, bundle and unbundle by name (I see you are unbundling the error wire by name)
  • queues
  • typedefs
  • custom controls
  • user events (different from the events you are using)
  • subvis
  • action engine/functional global
  • state machine

Until I can get some time to help get you started you should study those things above that you do not understand.

You have an event for Timing/Phase shift value change. You create a command to send to your controller from that and read a response. You then write that back to the Timing/Phase shift control that triggered the event. You do the same for some other controls. Is it your intent that the controller modifies what the user enters into those controls?

Link to comment

The program is simple enough. If I can find some time I would be happy to set it up into a producer/consumer design pattern. But I have a couple of questions.

Forget about the architecture for now. If I were to help you with this I need to know if you are familiar with the following concepts.

  • clusters, bundle and unbundle by name (I see you are unbundling the error wire by name)
  • queues
  • typedefs
  • custom controls
  • user events (different from the events you are using)
  • subvis
  • action engine/functional global
  • state machine

Until I can get some time to help get you started you should study those things above that you do not understand.

You have an event for Timing/Phase shift value change. You create a command to send to your controller from that and read a response. You then write that back to the Timing/Phase shift control that triggered the event. You do the same for some other controls. Is it your intent that the controller modifies what the user enters into those controls?

yes, the controller will change the values what we are written to it. But, this is going to be extent more that means i want use one formula when i am writing from control and that i can make it later. I know only queues and state machines and will learn quickly about others also. Now i am seeing the producer and consumer design. My project process is like below

1) address search as in my firstcase and display the available addresses (one refresh button is required to update the addresses anytime)

2) select one address write it with list of commands as in my monitor case and display it to respective textbox

3) simple user terminal for seeing user interested value by just writing his wish command in it.

4) other all cases belongs to control commands which write user entered value to device (here posiblly need send button to send value to device after press)

I am studying here http://forums.ni.com...ure/m-p/1184565. Is that what you suggested?

If you make it to some starting stage i will try then to fill the remaining holes.

Thank you so much for your helping hand.

Edited by sjukheter
Link to comment

yes, the controller will change the values what we are written to it. But, this is going to be extent more that means i want use one formula when i am writing from control and that i can make it later. I know only queues and state machines and will learn quickly about others also. Now i am seeing the producer and consumer design. My project process is like below

1) address search as in my firstcase and display the available addresses (one refresh button is required to update the addresses anytime)

2) select one address write it with list of commands as in my monitor case and display it to respective textbox

3) simple user terminal for seeing user interested value by just writing his wish command in it.

4) other all cases belongs to control commands which write user entered value to device (here posiblly need send button to send value to device after press)

I am studying here http://forums.ni.com...ure/m-p/1184565. Is that what you suggested?

If you make it to some starting stage i will try then to fill the remaining holes.

Thank you so much for your helping hand.

Can you just make it to some extent then i will do myself after. I don;t where to start. More, what is the difference between my event cases and

you said something "user events". Please help me.

Link to comment

Can you just make it to some extent then i will do myself after. I don;t where to start. More, what is the difference between my event cases and

you said something "user events". Please help me.

User events are events you generate in your code. In a standard producer/consumer design you can send messages from the producer to the consumer. But there is no way to send messages from the consumer back to the producer. This can be necessary if there is an error in the consumer and you want to notify the producer. A user event is much like a queue. The difference is that with a queue you can send from multiple loops to only a single loop whereas a user event can be sent to multiple loops. That detail doesn't matter right now. For sending messages from the consumer loop back to the producer you could also just use another queue but many examples use a user event.

You use LV8.5 right? I will create an example with some of your code in it to get you started. Why would I do this? I like the practice! It can be hard to come up with an idea just for practice. And if it helps someone all the better.

Link to comment

User events are events you generate in your code. In a standard producer/consumer design you can send messages from the producer to the consumer. But there is no way to send messages from the consumer back to the producer. This can be necessary if there is an error in the consumer and you want to notify the producer. A user event is much like a queue. The difference is that with a queue you can send from multiple loops to only a single loop whereas a user event can be sent to multiple loops. That detail doesn't matter right now. For sending messages from the consumer loop back to the producer you could also just use another queue but many examples use a user event.

You use LV8.5 right? I will create an example with some of your code in it to get you started. Why would I do this? I like the practice! It can be hard to come up with an idea just for practice. And if it helps someone all the better.

thank you so much i am using LB8.5 and eagerly waiting for starting code.

Link to comment

thank you so much i am using LB8.5 and eagerly waiting for starting code.

This will get you started. It does not have a user event to keep it simple. I integrated some of your code but you will have to add the missing functions. If you study this code and understand how it works you should have no trouble doing the rest. The Comm.vi is a simple action engine.

Also study gcode's project template. You will probably want to do some better error handling especially when dealing with comm ports and the fact that your device may or may not even be on. The error module in that project will work very well for you.

I have no way of testing this but maybe something will happen to your device. I hope that something does not involve smoke! :P

Controller.zip

Link to comment

This will get you started. It does not have a user event to keep it simple. I integrated some of your code but you will have to add the missing functions. If you study this code and understand how it works you should have no trouble doing the rest. The Comm.vi is a simple action engine.

Also study gcode's project template. You will probably want to do some better error handling especially when dealing with comm ports and the fact that your device may or may not even be on. The error module in that project will work very well for you.

I have no way of testing this but maybe something will happen to your device. I hope that something does not involve smoke! :P

I have one doubt on this model that what is the main difference between before program and this model. Where this program is good compared to previous. Now, i am just learning how this is working. I want to know where the difference is?

Link to comment

I have one doubt on this model that what is the main difference between before program and this model. Where this program is good compared to previous. Now, i am just learning how this is working. I want to know where the difference is?

Do you mean the difference between your program and the one I posted or the difference between what gcocde posted and the one I posted?

The difference between yours and mine is that in mine the communications are all done outside of the user event structure. You mentioned that your front panel would freeze. That will happen if the VISA read is taking a long time in your event structure.

The difference between mine and the one that gcode posted is that his uses events for error signaling.

I know the producer/consumer architecture seems more complex than it needs to be but there are significant advantages which is why others have been suggesting this to you. But it really is not that complex once you get to know it.

This link has some good information for you.

Link to comment

Also study gcode's project template. You will probably want to do some better error handling especially when dealing with comm ports and the fact that your device may or may not even be on. The error module in that project will work very well for you.

Well, this is just an example template I use for teaching taken from NI Intermediate 1.

Thought it may help in this case to describe exactly what you were talking about (using user event to communicate and error from consumer to producer).

Cheers

-JG

Link to comment

Well, this is just an example template I use for teaching taken from NI Intermediate 1.

Thought it may help in this case to describe exactly what you were talking about (using user event to communicate and error from consumer to producer).

Cheers

-JG

Steve, I just once look your code and affried to handle that. I am just learning it now. Have you used any state machine in your code. Furthurmore, if i have any doubts then i will post here.

What is enumerated typedef constant. I don't have any idea about these terms. can you explaine me.

Thank you.

Edited by sjukheter
Link to comment

Steve, I just once look your code and affried to handle that. I am just learning it now. Have you used any state machine in your code. Furthurmore, if i have any doubts then i will post here.

What is enumerated typedef constant. I don't have any idea about these terms. can you explaine me.

Thank you.

I did not use a state machine anywhere.

An "enumerated typedef constant" . First an enum is a collection of integers that have strings associated with their values. You can find the enum control under Ring & Enum. You right click and select edit items.

post-17905-0-27430500-1302016804_thumb.p

You can wire that to a case structure and switch on the name instead of remembering the number.

post-17905-0-59343200-1302017097_thumb.p

You can right click the case structure and add a case for every value. Now you will have a case for each element of the enum. One reason you would want to use a number instead of just a string (an enum is a number) is that a number takes much less memory. But more importantly you can also ensure that only values in the list can be used. Somebody could not try to add a "Grape" case because it does not exist in the enum.

If you right click on the enum terminal and create a constant you have an enum constant. Now for the typedef part.

You can create your own custom controls in LabVIEW. That is what the .ctl files in the project are. You can make a custom control from the enum by right clicking on the control, selecting advanced, then customize. When you save the ctl file you have three options: "Control", "Type Def" and "Strict Type Def". If you save it as a control then you can easily place the enum on the front panel again by just dragging it there. Now you don't have to add all those items if you want to use this in twenty places in different subvis. The other option would be to copy and paste the enum.

But what happens if you have a vi that has ten of your enum constants and you decide you want to add grape? You have to right click on each constant and edit the items. Not only that but you have to make sure that the numbers match the strings in each instance. Remember that the datatype is not a string but a number. The string is associated with the number. That means you can do any numeric operations on the enum. In the example above banana+orange=pear because banana is associated with the value 1, orange is associated with 2 and pear is associated with 3. If you do not keep all the constants consistent and have one instance where the value 1 is associated with banana and in another the value 1 is associated with pear you will have problems.

That is where the typedef comes in. When you save your custom enumerated control as a typedef, then anywhere it is used, either as a control, indicator or constant, they will all be updated when you edit the control. A strict typedef is the same thing as a typedef but it makes sure that all properties get updated when you edit the strict typedef. The project I attached uses strict typedef clusters for your front panel. If you want to change the color just open the .ctl file and edit it. You can also add to the clusters and the cluster constants in your code will be updated. That means that unbundle by name will not break. The error terminal is a built in typedef cluster.

The comm.vi is an action engine that uses an enumerated typedef (Comm Command.ctl) for the command. It has the values "initialize", "Write and Read" and "Close". If you wanted to add another command such as "Reset" you would add that by opening the .ctl file, right click and edit items, insert the new command and save the file. The action engine will be broken. If you click on the run arrow you will see that this is because the case structure does not have a case for the new value and there is not a default case. You can right click on the case structure and select "add case for every value"

Link to comment

Hi,

I have a problem with my combobox. it is always saving the strings in drop down list and displaying it before even the program not run one time. When I run my code it will populate some addresses and when my total vi and open again also displaying previous addresses. how should clear these address when the program is closed.

Thank you.

Link to comment

i did not make it to erase dropdown data at the starting of program and how to add the empty array to existing property node. Drop down data is coming from for loop and displaying in it in same time that before that operation how can i exactly empty the combobox.

Link to comment

If you create a Strings[] property node from your combo box just right click on the input and create constant. Sorry but I forgot to mention that clearing the strings does not clear what is displayed so you also have to write an empty string to the Value property. To keep the write from happening at the same time as some other code you have to enforce dataflow with the error wire.

post-17905-0-61955400-1302359448_thumb.p

Link to comment

In my program, If my serial device is disconnected unfortunately, i am displaying a message to user and program is shutdown. Now, i would like to do in a way, that if my serial device disconnects then my program shoud display the message and then it will not shutdown but it has to wait for the serial device again. if it connetcs in same port the program should run as well or if it connects in other com port then the program should automatically change existing comport to that port. Is possible in labview? Can you help me?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.