Moisture Analyzer Percentage in Studio 5k

AD@brady

Member
Join Date
Feb 2021
Location
Currently Planet Earth
Posts
33
Hello PLC experts,

I have a question for those of you familiar with studio 5k.
A moisture analyzer was added to the PLC as a REAL data type tag with data type but the value I'm seeing is not what the M.A display shows.

The MA Displays 99.74%.
The REAL value on the PLC shows 1.0.

So, my understanding is that the number is being rounded to 100% and the plc is showing the actual number and not the percentage.

My questions are:
Is there any way for the number to not be rounded?
Is there a way for number to be shown as a percentage?

If the answer is yeas for either one of this please let me know the how to.

Thanks,

AD
 
How is the MA value being input to the PLC? Is it analog (e.g. 4-20mA or 0-10V, etc.)? Is it a digital protocol (e.g. Modbus, Ethernet/IP, Hart, etc.)?


Where, and in how many places, is it being scaled?


The problem could be clamping and not rounding.
 
@DrBitBoy,

It is being input to the plc through an RS232 serial to Ethernet/Ip connection.
Being converted from TEXT(ASCII) To FLOAT in a protocol converter and then sent to the PLC via Ethernet.
 
Last edited:
@DrBitBoy,

It is being input to the plc through an RS232 serial connection.
Being converted from TEXT(ASCII) To FLOAT in a protocol converter and then sent to the PLC via Ethernet.

[Update: whoops, got this confused with another thread]

Ah, thanks.

  • Can you get a dump of the RS232 stream (via e.g. Hyperterminal or Putty)?
  • What Ethernet protocol is being used?
    • Can you get a dump (via e.g. Wireshark or tcpdump) of the Ethernet packets to see the bits in them, and identify the FLOAT value being transmitted?
  • What do you get if you multiply the 1.0-valued FLOAT by 10000. or 1e6 or 1e7?
 
Last edited:
I am able to connect via a program like HyperTerminal which dumps into an excel sheet.
Im connected to a L81E Controller so I think its Ethernet/IP protocol.
When I multiply the value by 10000 I get 10000.
 
I am able to connect via a program like HyperTerminal which dumps into an excel sheet.
Im connected to a L81E Controller so I think its Ethernet/IP protocol.
When I multiply the value by 10000 I get 10000.


Can you put the excel sheet into a .ZIP and post it here?


or just take a screen shot?
 
Huh.


The only real data are that the string "99.61" coming into the protocol converted is not being properly converted to a REAL in the PLC.


Why it is 1 instead of near 100 makes me wonder

  • if the converter is using the correct string and/or treats the value is an integer on its side of the E/IP comms,
  • and/or,
  • if either the converter or the PLC is somehow clamping the value to a maximum of 1.

It would seem unlikely that the converter 1) rounds 99.61 to 100, and 2) then sees the % unit and converts 100% to 1, which is correct in one sense.


I wonder if a tcpdump/wireshark hex dump of E/IP packets would allow seeing whether the converter is sending 99.61 or 1.0 or (or 1 as an integer) to the PLC. That would enable isolating where the problem is occurring.


I doubt it is sending 99.61 in a 4-byte REAL, but who knows.
 
I never used Wireshark before.

I have a maintenance computer through which the Protocol Convert Program(Crimson 3.1)
runs and the PLC is actually accessed trough a remote desktop.

Can you please tell me where I would install Wireshark in this case?
 
If the conversion takes place in a Crimson 3.1 device, you should have a file running on that hardware with the extension "cd31". If you can post that file, we can probably help.
 
Code:
//Moisture Analyzer

//declare local variable 
cstring input;        
cstring response;
  
int port = 1;
 
 // read Port 1's buffer: no start character, <CR> end character
// , 500ms timeout, no length restriction
 input = PortInput(port, 0, 13, 500, 0);
 
// check for non-empty input
if(input != "") {
            
             // populate tag with data
             response = input;
             }    
MoistureAnalyzerIn = TextToInt(input, 10);
MoistureAnalyzerReal = TextToFloat(input);
  1. It looks like TextToFloat could be parsing an empty cstring (i.e. input).
    1. I think the cstring response should be the 1st argument to TextToFloat.
  2. Where does the code decide to read only that line 22 ("End Result 99.61 %DC<CR>") that OP cares about?
    1. Because all the other lines also probably end in "<CR>" (ASCII code 13 i.e. 3rd argument to TextToFloat).
  3. Where does the code extract and pass only the ASCII decimal digits and decimal point (e.g. "99.61") to TextToFloat from that line 22?
    1. What does the TextToFloat function return if e.g. the cstring "End Result ...<CR>" is its 1st argument?
Do you know if there is a linefeed (<LF>; ASCII code 10) after each carriage return (<CR>) in the RS-232 stream? Because if there is, the that linefeed will likely be the first character in [cstring input] returned by PortInput each time it is called after the first.
 
Last edited:
Code:
[COLOR=blue]// Moisture Analyzer[/COLOR]

[COLOR=blue]// Declare local variables[/COLOR]
cstring input;        
cstring response;
cstring End_Result = "End Result";
int pct_pos;

int port = 1;
 
[COLOR=blue]// read Port 1's buffer: no start character, <CR> end
// character, 500ms timeout, no length restriction[/COLOR]
input = PortInput(port, 0, 13, 500, 0);

[COLOR=blue]// check for non-empty input[/COLOR]
if(input != "") {          
   [COLOR=blue]// populate tag with data[/COLOR]
   response = input;
}
             
[COLOR=blue]//Strip leading linefeed (ASCII code 10 = 0xA), if present[/COLOR]
if (Find(response,10,0)==0) {
  response = Mid(response,1,Len(response)-1);
}

if (Len(response) > Len(End_Result)) {
 
  [COLOR=blue]// If response is longer than "End Result" ...[/COLOR]
  
  if (End_Result == Mid(response,0,Len(End_Result)) {
  
    [COLOR=blue]// ... and response starts with "End Result",
    // then strip leading "End Result"[/COLOR]
    response = Mid(response,Len(End_Result),Len(response)-Len(End_Result));
    
    [COLOR=blue]// Find position offset percent character "%" ASCII code 37 = 0x25[/COLOR]
    pct_posn = Find(response,37,0);
    [COLOR=blue]// N.B. pct_pos will be -1 if % is not in response ...[/COLOR]
    
    if (pct_posn > 0) {

      [COLOR=Blue]// If % was found after the first character,
      // Then extract characters up to just before %[/COLOR]
      response = Mid(Response,0,pct_posn);

      [COLOR=blue]// And parse remaining response as both radix (base) 10 integer ...[/COLOR]
      MoistureAnalyzerIn = TextToInt(response, 10);
      
      [COLOR=blue]// ... and as decimal float[/COLOR]
      MoistureAnalyzerReal = TextToFloat(response);
    }
  }
}
 
Last edited:
There is at least one typo in that code: "Response" should be "response" in the last Mid(...) function call.

Also, It's not the most efficient e.g. Len(End_Result) is potentially used a few times so
Code:
Ler = Len(End_Result);
early on, and then Ler replacing later instances of that function call, would be a cheap optimization.
 
@drbitboy - Thank You!

YES!
That Worked.

Thank You so much!

I am not familiar with C language at all.
I know that this is Crimson' own scripting but would you say is closer to C+ or C# or some other type of code?
Also, do you know any good online training where I could sharpen my skills on this language? Any thing you have done that you would recommend?

Again,

Thank You!

MoistureAnlazyerFeedback.PNG
 

Similar Topics

Hi, I have a situation that I'm trying to resolve. I have a MT HR-83 moisture analyzer communicating via RS-232. I want to get info...
Replies
1
Views
5,770
Good Evening , I'm looking for a moisture sensor to read muffin dough going across a conveyor . We have recipes , that should add the correct...
Replies
8
Views
3,012
Happy New Year All! Does anybody know of a decent sensor for monitoring humidity or water in compressed air lines? I'm sort of looking at the...
Replies
3
Views
1,917
hello all, we have little side project cooperating with local University. They are reading resistence between two screws screwed into wood (cca...
Replies
9
Views
2,438
Hi All, I have an application where I need to constantly measure the moisture level of abrasive material in a pan mixer. The sensor needs to be...
Replies
0
Views
1,505
Back
Top Bottom