you could try using the same code for all, that would guarantee that all are built the same way
Sorry, my description was not sufficient. I forgot to tell you that I only wrote "set" for a better understanding. The commands are in german (it should be: soll=1,4000;soll=2,3900;soll=3,3700).
I checked the result of my input with "visa read string" and it also changed on the machines display. The OK is part of the machines answer. The answer looks like this:
It should look like this:
soll=1,4000OK:soll=2,3900;soll=3,3700OK; (channel 1=40°C, channel 2=39°C, channel 3=37°C )
If I have only two commands, it still won't understand the second. The second channel alone works. Since I copy-pasted the number to string inputs and changed only the channel number, there should be no syntax error.
I will upload my VI later, since uploading data doesn't work at my current location.
all the commands are terminated by a ";". How can i feed in only the sinlge commands? I have a set of 20 different commands, that can be used to control the machine or get a certain response.
thanks, that's much more elegant than my Version.
VISA Write the first command, VISA Read the echoed command and response to the first command, write the second command, read the echo and response to the second command, write the third command, read the echo and response to the third command. Does the response from the device (the "OK") have any terminating character, like a linefeed or carriage return character after it? Something that marks that the reply is complete?
Edit: If the received text you posted is correct, then it looks like the device is echoing back the command without the semicolon, then appending its reply and a semicolon terminating character. If that's right, then the semicolon would be what you'd configure as your termination character before your VISA Read. If you want to check that your command was received correctly and acknowledged, which would be a good idea, you can check that the start of the received text matches your sent command (other than the semicolon), and that what follows is "OK".
Thank you very much again for your help and ideas! I tried to implement some of them and changed a lot of things in my VI. Now I have some follow up questions:
1) I tried to implement the termination character, but i couldn't figure out how to make it work. Since I have no manual for the machine i don't know its exact configuration. How do I set up a termination character in my VI? Is there any example VI? I also found out that the machine has an echo mode, which in on by default.
2) I tought I could set up multiple VISA write/read operations in series. My idea was to write channel 1 and read channel 1, write channel 2 and read channel 2 and so on. But write/read in series in a long line did never work.
I put my sub-VIs in parallel an the program worked fine. Is putting things in parallel bad programming? The only problem I have is that the read changes for a second everytime I write an new temperature. I want to monitor the temperature of all channels continuously, but when i input a new value the read answer will change for a second. How can i make changes and have a constant read-value for the temperature? The VI is attached as "V3 - Temp".
By the way: I solved my problem with the multiple inputs. Since concatenate strings didn't work i now use the autoindexing of an array in a loop. This works fine. I seems the machine needs small breaks between the inputs.
3) My first objective was to control the machine. This now works fine in my VI-V3. I can change the temperature and turn the heating on and off. The only problem is the monitoring i mentioned in 2).
My second objective is to change the program, so it can automatically create a temperature curve. This should work like this: Hold channel 1,2,3 at the tmperature i set before. When i push the startbutton i want every channel to decrease 1 degree every 5 minutes until it reaches 22 degrees. Then its should hold the temperature for like 15 minutes and increase it 1°C every 5 minutes till it reaches the starting temperature and hold it.
With my limited skills i could only come up with an array that contains a table of the temperatures and a 5 minute loop. It works in gerneral but the stop-button doesn't really work and the programm keeps going. Additionallly i would like to monitor the temperature of my channle 6 (external temperature probe) without interuption. You can find the VI below as V4- Temp. Is there a more elegant way?
1) You can enable the (receive) TermChar at the VISAInitSerialPort function. Read its help!
2) In general that should work as the COM driver is handling both read and write buffer for the port. You only need to make sure the received messages are "unique" so you always know to which command they belong…
3) Create a state machine! You would need states like "wait for xx seconds", "set new parameters, "ramp up/down"…
(You should NOT have an event structure without a loop around, it may block your whole UI! Additionally events should get executed very fast.)
1. If you can view the received string in a string indicator with backslash codes displayed, then you can tell for sure whether the device is putting a termination character after its messages. Without the backslash codes displayed you might not be able to see it if it's not printable (e.g. tab, carriage return, linefeed, space). Can you turn on backslash codes and share the received strings with us?
2. You can do it the way you are now, sending all of your commands in a row without reading any of the responses until after they've all been received, but it's worth identifying why you can't get it to work the other way, where you read each response as soon as it comes in. The 100 ms delay you have to add between transmissions could be because the device can't handle receiving your next command while it's sending its reply to the previous one, but if you waited for each reply you could probably get rid of it.
Also, parsing the responses based only on character position isn't very robust; one erroneously inserted or dropped character in the response string will corrupt all of the responses that follow without giving you any indication. A more robust approach, such as using Scan From String to match the known format of the response will generate an error if it doesn't match.
When your Temploop Value Change event fires (which it can only do once, since it's not in a loop like it should be), then its "soll=" commands will potentially be sent intermixed with your other "is=" commands, and any responses they generate will be mixed in with your other responses and will corrupt your response parsing. You need to use some kind of access control (e.g. a semaphore, or a state machine architecture) to prevent the two sets of commands from interfering with each other, and you need to read the responses to your "soll=" commands before handing the port back to the "is=" commands.