Multi-digit word variable to string


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Thank you, Henrik.
    I love when the answer is shorter than the question!

    To be clear then, it appears that DEC is not a command of itself, but a parameter of some other display functions; it is only valid in an output string to an LCD or other output device (ie serial port) or construct (array-obviously).

    I hope it is not too much trouble for any who follow this thread to correct my interpretation as well as to clarify one more point? Can an entry point be specified, as ARRAYWRITE MSG[14], [DEC RawT] so that the variable may be positioned in a larger array? I saw little on this when searching

    It is possible to specify an entrypoint, so that (for example) the string "Temperature = XXX degrees" can be dynamically updated with Arraywrite ARRAYNAME[entrypoint] = [DEC variable]
    Last edited by Amoque; - 25th March 2012 at 19:44.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hi,
    That's correct. DEC is not a command by itself, it's what the manual calls a modifier among others (BIN, HEX etc).

    I've never tried it but I'm pretty sure you can start anywhere in the array in the way you show.

    /Henrik.

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hello all,

    this is an old post. I'm not sure if my question fits right to here.

    I have a temperature values and i would like to send them to a display from 4D Systems.

    At the moment i was using the serial SPE commands as 4D Systems calls it, and they have exactly the command to send those variables.

    Then i tried their "new" Visi Genie enviroment, which allows you to create "forms" and add any image, button etc.

    I have fniished the easy task inside the Visi Genie and i'm in front of a problem that i need to transform the variable to string.

    As from 4D Systems:

    Visie-Genie writes to pre-defined objects so in this case it is a pre-defined string object so all we have to do is convert what we need to send to a string, calculate a checksum and send. This is where Genie differs from Serial as in the Serial mode you are sending a serial command to the display which is translated to a command to do a supported function on the display.
    It is the first time i had to do a task with Checksum and found it interesting way by XORing all the bytes. In a very small code i tryied it worked, as i sent based on 4D Systems the command to change the constrast and it worked.

    Code:
    command var byte
    constrast var byte
    CS var byte
    
    ' -----------------------------------------------------------------------------|
    ' [ LCD Initialization ] |
    '------------------------------------------------------------------------------|
    ' FIRST TIME BOOTUP: We give plenty of time for tbe LCD '
    lcdinit:
    pause 2000
    command = $04
    contrast = $06
    gosub checksum
    hserout [command,contrast,CS]
    hserin [wait(6)]
    pause 100
    
    
    high green
    return
    
    '------------------------------------------------------------------------------|
    ' CHECKSUM |
    '------------------------------------------------------------------------------|
    checksum:
    cs = 0
    cs = cs ^command
    cs = cs ^ contrast
    return
    Now i'm trying to see the way to convert var to string. I have read the manual written in 2013

    "A numeric value preceded by a pound sign ( # ) will send the ASCII representation of its decimal value, up to 65535. For example, if W0 = 123, then #W0 (or #123) will send "1", "2", "3"."
    Is that the right way? May i have your help please?

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Or use DEC modifier like DEC k. If k=5, DEC k will send out the "5".

    With DEC you can also specify how many digits you will send. E.g. DEC3 will send 3 digit of the variable with the appropriate leading zeros in this case to fit the number of digits requested.

    If k=15 then DEC3 k will send "0", "1", "5"

    Ioannis
    Last edited by Ioannis; - 28th September 2020 at 09:57.

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Thanks so much Ioanni,

    will try it out.

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Dear all,

    i have some problem regarding the conversion of a variable to string.

    I have the following code.


    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                         VAR for IR to LCD          '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    IRCS         var byte       ' this is the checksum for the IR required in external display command
    TEMP         var word       ' this is the word variable for TEMP 
    temperature  var word       ' for result and output to lcd 
    TEMPIR       var word       ' set a variable tempir 
    Remainder    var word       ' Get the remainder = tempir//50
    
    '------------------------------------------------------------------------------*
    '                    Measure IR object temp sent to uLCD                          *
    '------------------------------------------------------------------------------*
    object:
    
    reg    = $07             ' based on the datasheet $07 is the object's temp
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    addr   = %10110101       ' $B5  Binary value: %10110101
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
    
    
    tempir = (temp.highbyte << 8) + temp.lowbyte
    
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    pause 100
    gosub display
    return
    
    '------------------------------------------------------------------------------*
    '                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS 
    Hserin2  timeout,error,[wait(6)]
     
    
    gosub checksum2    
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature
    IRCS = IRCS ^ remainder
    return

    One i do the CS calculation, and returning from checksum2 the following is not working as expectred.

    Code:
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    even if i try the following.

    Code:
    hserout [$01,$0F,$00,dec2 temperature,dec remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    Is there a way to convert the variable to string ourside from a preset command like the HSEROUT?

    for example is there a way to make something like this in PBP?

    temperature = #temperature.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If your variable is ranging from 0 to 65536 (the maximum that word can hold) obviously the HSEROUT command cannot handle that. With HSEROUT you can use only ascii values.

    So, as you have already find out, the dec2 temperature does work. Maybe your value is beyond 2 decimals so you have to use dec5 to be sure and cover all temperature values?

    Ioannis

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    i have had three or four people say i'm not a good teacher,
    i'm not surprised since i never have been or ever aspired to be one

    so what do think of my new signature ?

    Warning I'm not a teacher , one on one Tuition with flowery prose like a gushing embroilment is not my style
    Last edited by richard; - 21st December 2021 at 09:11. Reason: if i can get it to take
    Warning I'm not a teacher

  9. #9
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    i may need to apologize for my behaviour as well. I do not expect that from you.

    Do what you know better to do, in this particular field. Everyone has its bad and good days. We are all in the same boat.

    You never know one day, i may be some how useful for you.....

    Take care and try to smile.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts