LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with a RS232 LabView program

As usual cbuthers comments are spot on. The only addition I have is that I often find it useful to use a third party serial communication software to check the message structure. It also gives you a sanity check on whether it is your LabView software/serial cable or hardware which isn't working.

 

I'd recommend Putty, you will have to manually add the line feed and carriage return characters (<LF><CR>), see the link below. 

 

https://z49x2vmq.github.io/2017/11/12/putty-cr-lf-en/ 

Message 21 of 44
(915 Views)

Good morning everyone.

 

@Henrik: Your example works as well. Very nice to see the real time change in a graph. This could come handy later. Attached you will find the screenshot.

continous read out.PNG

 

@cbutcher:

Thanks a lot for the files. I think (hope) I can start playing around now. First I want to see if I am able to read out two different values (Plant Temp and maybe Set Temp) in one VI with your code. I think if I manage to do this I am a huge step further.

Unfortunately, I don't have much time today. And 0 over the weekend. But I promise I will be back next week and work on this script. So you won't get rid of me that easy 🙂

 

@Niatross:

I will have a look into this later. It's a valid point I guess.

 

Thanks again to all of your suggestions here. This is a tremendous help and I couldn't have done any of it without you guys. Much appreciated.

0 Kudos
Message 22 of 44
(896 Views)

@Torracc wrote:

Good morning everyone.

...

@cbutcher:

Thanks a lot for the files. I think (hope) I can start playing around now. First I want to see if I am able to read out two different values (Plant Temp and maybe Set Temp) in one VI with your code. I think if I manage to do this I am a huge step further.


So I'd suggest (and you can feel free to disagree) that you'd be best off trying to first setup simple VIs (in the style of the Read Plant Temperature.vi I sent) that do a single command from your list in the first post.

 

After that, you can test them in the manner of the example VI, to check they work in a reasonable fashion.

 

Then, you probably want some sort of "Main" VI to combine them and trigger them based on button presses etc. I'd suggest reading about Event Structures and using one in a While loop to handle button presses and call subVIs (the simple ones you create in the first step) based on which button is clicked, then updating indicators or reading controls as appropriate.

 

You can also use Value Change events on numeric controls (e.g. "Setpoint" control or something) to call a VI like "Set Setpoint Temperature.vi" (I just made this name up, but whatever you call your Writing subVIs)). Or you can stick with boolean events, and read the numeric control values inside those cases of the Event Structure.

 

Good luck and feel free to post more questions here as you find them.


GCentral
Message 23 of 44
(889 Views)

SO it took me some tries but I figured how to read out 2 things in one VI. Not sure if you would do it like that. I tried to make them parallel (I guess that was intuition?) but then it only showed just one of them (either set or plant) and never both. I guess I kind of "stole" a path with the wiring in parallel and so I only got one value. I also needed to save two sub VIs, because when I changed the parameter in the set point read out to "S", it automatically changed the parameter "T" in the plant temp read out to "S" as well. I guess there is a better way than saving multiple sub VIs just for one different parameter. However, it kind of works.

Of course it is silly to read out the set point temperature. But I figured there are only two commands for a simple read out in the manual and that is set point and plant temperature. There is this option to read out the full status of the chiller with "R" but I guess this needs some fixing as it is multiple lines and not just one string to number.

 

2 read outs.PNG

0 Kudos
Message 24 of 44
(883 Views)

@Torracc wrote:

I also needed to save two sub VIs, because when I changed the parameter in the set point read out to "S", it automatically changed the parameter "T" in the plant temp read out to "S" as well. I guess there is a better way than saving multiple sub VIs just for one different parameter. However, it kind of works.


Hmm. Actually, that's exactly what I'd probably do.

My reasoning would be something like the following:

  • As the developer of a LabVIEW driver for this chiller, I (you) need to deal with strings and string formatting and conversion between strings and numbers and so on. I need to read the manual and find out which character controls which read and write operations.
  • As the user of a LabVIEW driver for this chiller, I (you) don't want to ever look at the manual, or deal with string formatting and conversion. I want to deal with things in the more "natural" representation - numbers in degrees C, booleans (not flags packed in hex values, or on/off as strings or numbers (I didn't check the manual to see which)).
  • This means for me as a user, I would like to see a VI that does "Read Plant Temp" or "Read Set Temp" and gives me a numeric value in degrees C. I don't want to know anything about how it works.
  • As the developer, the two VIs might be very similar (different only by one character, in this case?). So I'd put all of the code in some separate, private VI(s) (Send VISA Command, Convert Response String to Number, whatever) and then call those, to avoid repeating the same low-level code, but to expose a simpler API to the user (also me).
  • I'd create a library file (lvlib) and use Access Scopes to hide some VIs (by making them private) and make other VIs public

Does that make any sense?

 

Essentially, this is now beyond "how can I make this work" and into "how should I make this look/feel/work"?

You're now talking about the design of your driver, and making it "nice" for a "user" (even though probably the user is also the same person as the developer, i.e. you).


GCentral
Message 25 of 44
(877 Views)

@cbutcher wrote:

 

Does that make any sense?

 100%

0 Kudos
Message 26 of 44
(876 Views)

Okay so with Henriks VI I was able to identify some parts of the read out of the chiller. When I use "R" as a command I will get a weird output.

R.PNG

I THINK that I was able to identify the parts to the actual "values" of the chiller. So both the 070X are the Plant and Set Temperatures. I was able to cross check with the output of the "T" and "S" commands and they fit. So I figured the other ones need to be for the Control Flags, the Alarm Flags and the Pressure.

The values for Control Flags and Alarm Flags are always constant (A5 and 00), which makes sense I guess. The value for the pressure varies, which also makes sense.

 

Now how to convert these lines into real strings? That is the questions. For the Temperatures we convert hex string into numbers. So I figured that we would now need to convert hex string into "real" string. But I couldn't find anything simple for that when I googled it. So I guess that there is not a pre-set function for that?! Because then I would be able to read out the other parameters of the chiller as well (the pressure would be interesting, not sure what control and alarm flag really is).

 

edit: With just changing the offset to a high number (19 or 20) and changing the 100 to 1 I was able to read out the pressure! So with the offset I can just "cut" parts of the string, right? Maybe not the smoothest way of handling problems but it works 🙂

0 Kudos
Message 27 of 44
(863 Views)

@Torracc wrote:

Now how to convert these lines into real strings?


No, you convert them into actual values.  Personally, I am a fan of the Scan From String function.  You can define your entire response and pull out the values you care about.  See Format Specifier Syntax for more information on building the format string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 28 of 44
(854 Views)

@crossrulz wrote:

@Torracc wrote:

Now how to convert these lines into real strings?


No, you convert them into actual values.  Personally, I am a fan of the Scan From String function.  You can define your entire response and pull out the values you care about.  See Format Specifier Syntax for more information on building the format string.


That is great advice. This safes so much space and I get all the needed information with just one function. I implemented that into my code. I was wondering about the two Flags though. In the manual they say

"Control Flags Status in Bit encoded Byte (2 chars)" and "Alarm Flags Status in Bit encoded Byte (2 chars)"

So does that mean that there is more information saved in the "10100101" and "00000000"? Because that would actually be the next part. To figure out if there are alarms.

I can read out the temperatures and the pressure now. That already makes 1/4 of my problem. So the 3 points missing would be:

- set the temperature (so don't just read it out)

- check for alarms (just for Alarm Flags like low flow or low level alarm)

- turn on/off the chiller (I think that's the "W" parameter)

0 Kudos
Message 29 of 44
(814 Views)

For the flags you can use Number to Boolean Array and optionally Array to Cluster (guide) to create an array or cluster of values.

The cluster is nice because you could create 8 boolean indicators and set their labels to the appropriate element of the alarms.

They'll be in order of the flags described in the manual (or perhaps reverse order, in which case you could list the booleans indicators in opposite order, or you could use Reverse 1D Array).

 

To set the plant temperature, the manual specifies a command of the format: ^JP xxxx^M where xxxx is degrees C * 100 as an ASCII representation of hexadecimal characters 0-F.

So to set the value to 25 degrees C, you'd want to give the value as the hex value for 2500, which is 09C4.

 

You can do this in LabVIEW like follows:

Example_VI_BD.png

 

Here the format string specifies a hexadecimal string with 4 characters and 0 padding (with %4x you only get 9C4, which might not be sufficient).


GCentral
Message 30 of 44
(810 Views)