451
Technical support / Re:Editing/Changing HMI, a large number
« on: July 04, 2010, 03:08:13 PM »
cdenk,
On the rotary encoder, it had 32 steps per rev. 2 digit numbers took a little over 6 spins. The encoder is not a perfect match for the T100MD+ as these PLCs don't support the decode mode required to get all 32 steps. Ladder logic was not fast enough to track the transitions when the encoder was moved rapidly. I used interrupt routines to interface to the encoder.
On the HMI keypad input I took an approach where the parameter to be edited was converted to a string, edited as a string and converted only back to a number for storage/use.
As an example for a time of day field:
The approach seems convoluted, but its works well with TBASIC and I used the same editing function for all of my input fields.
This is the input handler shared by all of the numeric fields:
' Edits X$
'
' X$ is updated, X is set to 1 to indicate that input is complete
'
DM[3900] = INPUT[3] ' Get data from input #33-48
IF TESTBIT(DM[3900],10)
' <Del> key has been pressed
'
X$ = "0"+MID$(X$,1,LEN(X$)-1)
X = 0 ' More Input to come
RETURN
ENDIF
IF TESTBIT(DM[3900],11)
' <Enter> key has been pressed. Input is complete
'
X = 1 ' Done with input
RETURN
ENDIF
' OK it must be a Number key that was pressed
' Figure out which one it was...
'
FOR Z = 0 to 10
IF TESTBIT(DM[3900],Z)
X$ = MID$(X$,2,LEN(X$)-1)+STR$(Z)
X = 0 ' More Input to come
RETURN
ENDIF
NEXT
Good luck,
Gary D
On the rotary encoder, it had 32 steps per rev. 2 digit numbers took a little over 6 spins. The encoder is not a perfect match for the T100MD+ as these PLCs don't support the decode mode required to get all 32 steps. Ladder logic was not fast enough to track the transitions when the encoder was moved rapidly. I used interrupt routines to interface to the encoder.
On the HMI keypad input I took an approach where the parameter to be edited was converted to a string, edited as a string and converted only back to a number for storage/use.
As an example for a time of day field:
- This field was stored in DM[_x] as a scaled integer. 8:31 was stored as 831 ( multiply the hours by 100 and then add in the minutes).
- To edit this field, I convert the scaled integer back into a text string using the STR$(DM[_x],4) function. The resulting sting was " 831". Note the leading space, the length of the string must always be constant at 4 for my time fields.
- The custom function that updates the LCD display inserts a ":" as it write to the display. The ":" never appears in the string.
- If the user enters a digit, 0..9, the old string is shifted to the left and the new digit is appended onto the right end of the string. If the string started as "0831" and the user presses the "9" key the string will become "8319".
- The delete key causes the number to be shifted to the right. If the string is now "8319", pressing the delete key gets you "0831"
- Pressing the ENTER key, gets the field validated and converted back into a integer for storage in DM[_x].
The approach seems convoluted, but its works well with TBASIC and I used the same editing function for all of my input fields.
This is the input handler shared by all of the numeric fields:
' Edits X$
'
' X$ is updated, X is set to 1 to indicate that input is complete
'
DM[3900] = INPUT[3] ' Get data from input #33-48
IF TESTBIT(DM[3900],10)
' <Del> key has been pressed
'
X$ = "0"+MID$(X$,1,LEN(X$)-1)
X = 0 ' More Input to come
RETURN
ENDIF
IF TESTBIT(DM[3900],11)
' <Enter> key has been pressed. Input is complete
'
X = 1 ' Done with input
RETURN
ENDIF
' OK it must be a Number key that was pressed
' Figure out which one it was...
'
FOR Z = 0 to 10
IF TESTBIT(DM[3900],Z)
X$ = MID$(X$,2,LEN(X$)-1)+STR$(Z)
X = 0 ' More Input to come
RETURN
ENDIF
NEXT
Good luck,
Gary D