Author Topic: READING A COUNTER  (Read 7967 times)

philipjoseph

  • Jr. Member
  • Posts: 57
    • View Profile
READING A COUNTER
« on: January 08, 2003, 08:43:40 AM »
I'm trying to read the value of a counter. The Master is a T100MD and the slave is a T40. I set the counter to 400.
1. Are the T40's counters only decremental counters?
2. I want to read the value of the counter every minute and save the value in a variable or DM, and after a read, send a comand to reset the value of the counter (400 ).

I use a dCusF with a 1min contact.

B$ = NETCMD$(3,"@02RU0C")         ' Read SPEED-COUNTER (#13) preset value
 IF LEN(B$) = 0  RETURN: ENDIF     ' Not getting response
DM[102] = HEXVAL(MID$(B$,6,2))

C$= NETCMD$(3,"@02WU0C0000")            ' CLEAR SPEED COUNTER PRESET VALUE

where is the problem if that is posible.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Philip.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re: READING A COUNTER
« Reply #1 on: January 09, 2003, 10:35:01 AM »
1. The T40H's counter can be up/down counter or used as a standard down-counter. See the TRiLOGI [UpCtr] and [DnCtr] command.

2. You can write a new Present Value to any counter.

3. The "RU0C" command returns a 4 digit decimal value for counter #13.  MID$ function should extract 4 characters from the B$, not 2 characters.

4. You should use the VAL( ) function to convert the data since it is decimal value and not hexadecimal value in this case.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

philipjoseph

  • Jr. Member
  • Posts: 57
    • View Profile
Re: READING A COUNTER
« Reply #2 on: January 10, 2003, 08:08:11 AM »
I change the funtion:

I$= NETCMD$(3,"@02RU0C")      'Read SPEED-COUNTER (#13) preset value
IF LEN(I$)= 0 RETURN: ENDIF      'Not getting response
DM[102]= VAL(MID$(I$,1,3))      'Keep the value temporarily

I$= NETCMD$(3,"@02RU0D")      'Read SPEED-COUNTER (#14) preset value
IF LEN(I$)= 0 RETURN: ENDIF      'Not getting response
DM[103]= VAL(MID$(I$,1,3))      'Keep the value temporarily

I$= NETCMD$(3,"@02RU0E")      'Read SPEED-COUNTER (#15) preset value
IF LEN(I$)= 0 RETURN: ENDIF      'Not getting response
DM[104]= VAL(MID$(I$,1,3))      'Keep the value temporarily

I$= NETCMD$(3,"@02WU0C0000")      'Clear the SPEED-COUNTER #13 preset value.
I$= NETCMD$(3,"@02WU0D0000")      'Clear the SPEED-COUNTER #14 preset value.
I$= NETCMD$(3,"@02WU0E0000")      'Clear the SPEED-COUNTER #15 preset value.

SETLCD 1,1,"SPEED:   "
SETLCD 2,1,"NO CLP:  "
SETLCD 3,1,"COUNT:   "
SETLCD 1,10,"    "
SETLCD 2,10,"    "
SETLCD 3,10,"    "
SETLCD 1,10,STR$(DM[102])
SETLCD 2,10,STR$(DM[103])
SETLCD 3,10,STR$(DM[104])

However, the display and the DM's don't change. The value is always 0. Where is the problem?

Philip.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Philip.

Ken

  • Newbie
  • Posts: 16
    • View Profile
Re: READING A COUNTER
« Reply #3 on: January 10, 2003, 11:14:17 AM »
One problem that I see is that you are telling your LCD to do two things in the same place.  Example:  setlcd 1,10,"   " and then 3 lines down you say setlcd 1,1,str$DM(103).  If these are in the same custom function then the only thing that will display is the last command
The other thing that I see as a problem is that you are using I$ as your register for 3 different DM's.  By doing that you make it very hard to find your problem because you are unable to tell which command line is developing the value of I$.
Your use of RETURN would produce a termination and no update to display of connection was lost to slave.  Is that what you are trying to do?  I may be wrong....  
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re: READING A COUNTER
« Reply #4 on: January 10, 2003, 05:34:38 PM »
Ken is right. The first thing you do to debug any communication problem is to find out if you have received any response string at all from the slave.  What is the content of the I$ received from NETCMD$? You could either display it on the LCD or use On-line monitoring to look at the content of I$.

Knowing the value of I$ can then help you to figure out what you did wrong in the following statements. You should check the communication one step at a time and analyse the return string. Sprinkle some PAUSE statements after each communication is an effective way of stopping the program and analyze the data.

If you use I$ for every comm you it become difficult to find out which NETCMD$ that you have executed is giving you problem.

You should extract 4 characters from the returned string, not 2 characters or 3 characters.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

philipjoseph

  • Jr. Member
  • Posts: 57
    • View Profile
Re: READING A COUNTER
« Reply #5 on: January 11, 2003, 03:13:23 AM »
Ok, I changed the funtion to:

I$= NETCMD$(3,"@02RU0C")      'Read SPEED-COUNTER (#13) preset value
DM[102]= VAL(MID$(I$,1,4))      'Keep the value temporarily

J$= NETCMD$(3,"@02RU0D")      'Read SPEED-COUNTER (#14) preset value
DM[103]= VAL(MID$(J$,1,4))      'Keep the value temporarily

K$= NETCMD$(3,"@02RU0E")      'Read SPEED-COUNTER (#15) preset value
DM[104]= VAL(MID$(K$,1,4))      'Keep the value temporarily

just to read the value, without the return, every counter with a diferent variable (I$,J$,K$) and also I am extracting 4 caracters from the variable.

When I monitor online the value of every variable(I$,J$,K$), the values change every minute. These are some value that i copied.
I$=@02RU027747* J$=@02RU00694A* K$=@02RU027545*
I$=@02RU030741* J$=@02RU007547* K$=@02RU030442*
I$=@02RU01914C* J$=@02RU000346* K$=@02RU018844*

however, the value of the DM's (102,103,104) didn't change. They always show 0.

Philip
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Philip.

philipjoseph

  • Jr. Member
  • Posts: 57
    • View Profile
Re: READING A COUNTER
« Reply #6 on: January 11, 2003, 04:34:42 AM »
I think, i found the problem.
DM[102]= VAL(MID$(I$,1,4))
I change the VAL(MID$(I$,6,4))
since it was reading from the first caracter insted the sixth caracter. Is that right?

Philip
« Last Edit: December 31, 1969, 04:00:01 PM by -1 »
Philip.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re: READING A COUNTER
« Reply #7 on: January 11, 2003, 08:24:03 AM »
That's right.  The data of interest starts from the sixth characters and you want 4 characters from there, so MIDS$(I$, 6,4) is correct.  :)
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS