Shop OBEX P1 Docs P2 Docs Learn Events
Sub with parameters problem — Parallax Forums

Sub with parameters problem

RsadeikaRsadeika Posts: 3,824
edited 2007-07-16 18:53 in General Discussion
For the life of me, I cannot find the problem with the snippet below. I am trying to create a new Sub, TX1_Byte, which will take in one to four parameters. It seems to work ok with one parameter, but it will not work with two or more parameters. I just can't see the problem. Maybe there is a better way to accomplish this?


Thanks

Ray

****************
temp1 var Byte (4)

TX1_Byte sub 1,4

TX1_Byte:

'Fills the array with PARAM values
·· temp1(0) = __PARAM1
·· temp1(1) = __PARAM2
·· temp1(2) = __PARAM3
·· temp1(3) = __PARAM4

·· temp2 = __PARAMCNT··· 'Get the PARAMCNT

·· do while temp2 > 0···· 'Is the PARAMCNT greater than 0
···· serout tx1, T57600, temp1(0)
···· dec temp2······· 'Reduce the PARAMCNT value by 1
···· inc temp1(0)··· 'Will it increment the array to the next element?
·· loop
return

Comments

  • BeanBean Posts: 8,129
    edited 2007-07-15 18:19
    You are using zero for the index in serout. "inc temp1(0)" isn't going to change what element temp1(0) is.
    I think you want:

    temp1(0) = temp1(1)
    temp1(1) = temp1(2)
    temp1(2) = temp1(3)

    This will shift the elements down so temp1(0) is the next value.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • SamTheManSamTheMan Posts: 43
    edited 2007-07-15 19:10
    This should do it for you



    ****************
    x var byte
    temp1 var Byte (4)

    TX1_Byte sub 1,4

    TX1_Byte:

    'Fills the array with PARAM values
    ·· temp1(0) = __PARAM1
    ·· temp1(1) = __PARAM2
    ·· temp1(2) = __PARAM3
    ·· temp1(3) = __PARAM4

    ·· temp2 = __PARAMCNT··· 'Get the PARAMCNT

    ·· do while temp2 > 0···· 'Is the PARAMCNT greater than 0
    ···· serout tx1, T57600, temp1(x)
    ···· dec temp2······· 'Reduce the PARAMCNT value by 1
    ···· inc·x·· 'Will it increment the array to the next element?
    ·· loop
    return

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RsadeikaRsadeika Posts: 3,824
    edited 2007-07-15 21:24
    Thanks SamTheMan, preliminary tests show results to be as expected, hopefully this will work for every thing that I have in mind.

    While on the SUB and serin/serout topic, has anybody created a sub for serin/serout. What I am thinking is something like Ser_In/Ser_Out sub with·three parameters. That way you could use it like this:

    · Ser_Out TX1, T57600, 'A'···· 'TX1 could be re.0

    · Ser_Out TX2, N19200, 128··· 'TX2 could be re.2

    Using this method, you could access the different pins from your code line, and the code generated would only being using one instance of serin/serout, I think. With only 4096 bytes of code space, I would like·to minimize as much as possible.

    Thanks

    Ray
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-16 18:34
    This is a nice idea, but...

    My understanding is that the pin designator of the SEROUT command (or any other SX/B command) can not be a variable.

    - Sparks
  • RsadeikaRsadeika Posts: 3,824
    edited 2007-07-16 18:53
    Sparks, that is why I posted the question. I thought maybe somebody smarter than me may have solved it. A couple of versions ago, I think we were using VAR to designate a pin, but it may be something with the command itself, oh well. We need more tools.

    Ray
Sign In or Register to comment.