Shop OBEX P1 Docs P2 Docs Learn Events
Stupid Question <FullDuplexSerial> — Parallax Forums

Stupid Question <FullDuplexSerial>

grasshoppergrasshopper Posts: 438
edited 2008-09-16 18:13 in Propeller 1
This is a stupid question but i cant seem to figure it out


Main
  StartBit := "0"  
  SorC := "-"  
  Sor3 := "+"

ser.str(string(startbit))
  




It wont send the data "0" out the serial port. I guess i need to send various conditions of my program i.e startbit and Sorc etc...

Help is appreciated

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-15 22:36
    The reason it doesn't work is that string() requires an inline string constant, meaning the string literally has to be inside the parenthesis.

    Without knowing more background on what you are trying to do, it's hard to point you in the right direction. The answer may be as simple as ser.tx(StartBit).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 9/15/2008 11:51:44 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-15 22:43
    If a variable X is a WORD or LONG, you can do X := "0" then you can do ser.str(@X) and it will transmit the character "0". This works because the character "0" is stored in the lowest address of the WORD or LONG and the next byte will be a zero. If X is a LONG, you can even do X := "0" + ("1" << 8) or X := "A" + ("B" << 8) + ("C" << 16) and this will display as "01" or "ABC".
  • grasshoppergrasshopper Posts: 438
    edited 2008-09-16 05:37
    Sorry Paul for not being more specific.

    I will have my variables as a byte. I not only want to use the "+" and "-" but also a "0" and"1". these variables will be toggled in my program and then "glued" together in one long string for a user to note the current condition of the device I am designing.

    i.e a returned string would look something like this on the computer side

    [noparse][[/noparse]Condition = 1--0]
    
    



    The pseudo propeller code would look like this
    
    Var
      byte StartBit, SorC ,SorC, SorE
    
    OBJ 
      ser  = "Fullduplexserial"
    
    Pub Main
    
      SorB := "0"  
      SorC := "-"  
      SorD := "+"
      SorE := "+"
    
    Pub Running
    
      ser.str(String("[noparse][[/noparse]Condition = "))
      ser.str(SorB)
      ser.str(SorC)
      ser.str(SorD)
      ser.str(SorE) 
      ser.str)string("]")
    
    
    




    Mike I will try some thing like you demonstrated.
  • grasshoppergrasshopper Posts: 438
    edited 2008-09-16 05:45
    Mike Green said...
    If a variable X is a WORD or LONG, you can do X := "0" then you can do ser.str(@X) and it will transmit the character "0". This works because the character "0" is stored in the lowest address of the WORD or LONG and the next byte will be a zero. If X is a LONG, you can even do X := "0" + ("1" << 8) or X := "A" + ("B" << 8) + ("C" << 16) and this will display as "01" or "ABC".

    After reading this over and over I ask you this...

    A character is how many bits? I am imagining 8 bits, not sure but 1111 = 15 so this is directly related to hex or F or 1/2 a byte since "A" = $41

    A Long can hold how many characters? perhaps 32 bit? thus = 1111 1111 1111 1111 1111 1111 1111 1111 or 4 characters?

    and while i am asking may as well ask what the hell a <<8 is doing? Bit shifting left? Why left? Why not right?

    Thanks for any help ...
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-16 05:51
    You can just use the single character output routines: ser.tx(SorB)
    What you wrote will also work if you change everything to WORDs (with VAR WORD SorB, SorC, SorD, SorE)
    and put "@" in front of the variable names like: ser.str(@SorB)
    Again, this is because a single character stored in a WORD looks the same as a byte with the character
    followed by a zero byte (which makes it a string to Spin).
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-09-16 08:25
    hello grasshopper,

    as you send single bytes i would prefer the command for sending a single byte

    so your code posted above would be changed to


    Var
      byte StartBit, SorC ,SorC, SorE
    
    OBJ 
      ser  = "Fullduplexserial"
    
    Pub Main
    
      SorB := "0"  
      SorC := "-"  
      SorD := "+"
      SorE := "+"
    
    Pub Running
    
      ser.str(String("[noparse][[/noparse]Condition = "))
      ser.tx(SorB)
      ser.tx(SorC)
      ser.tx(SorD)
      ser.tx(SorE) 
      ser.str(string("]"))
    
    
    



    best regards

    Stefan
  • grasshoppergrasshopper Posts: 438
    edited 2008-09-16 15:01
    StefanL38 said...
    hello grasshopper,

    as you send single bytes i would prefer the command for sending a single byte

    so your code posted above would be changed to


    Var
      byte StartBit, SorC ,SorC, SorE
    
    OBJ 
      ser  = "Fullduplexserial"
    
    Pub Main
    
      SorB := "0"  
      SorC := "-"  
      SorD := "+"
      SorE := "+"
    
    Pub Running
    
      ser.str(String("[noparse][[/noparse]Condition = "))
      ser.tx(SorB)
      ser.tx(SorC)
      ser.tx(SorD)
      ser.tx(SorE) 
      ser.str(string("]"))
    
    
    



    best regards

    Stefan


    This does not work... Hum

    I even tried making the variables a long as well
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-16 15:31
    Saying "This does not work" is not very useful. You're more likely to get useful information if you describe what happened.

    That said, why do you have "Pub Running"? That creates a separate method (subroutine) which is never called.
    Try putting "Running" after the 'SorE := "+"' line or simply removing the "Pub Running".
  • grasshoppergrasshopper Posts: 438
    edited 2008-09-16 15:45
    Sorry Mike your right I was quick to complain without a clear discription

    Here is the code that works but not efficient.

    Var
       long SorB, SorC, SorD, SorE
    
    Pub Main
    
      SorB := "0"  
      SorC := "-"  
      SorD := "+"
      SorE := "+"
    
    Pub Running 
    
          ser.str(String("[noparse][[/noparse]Condition = "))
                                                                  
         IF (SorB == "0")
               ser.str(string("0")) 
         IF (SorB == "1")
               ser.str(string("1"))
                                    
         IF (SorC == "-")
               ser.str(string("-")) 
         IF (SorC == "+")
               ser.str(string("+"))
                                                                                                                                              
         IF (SorD == "+")
               ser.str(string("+")) 
         IF (SorD =="-")
               ser.str(string("-"))
                                                             
         IF (SorE == "C")
               ser.str(string("C")) 
         IF (SorE == "S")
               ser.str(string("S"))
     
      ser.str(string("[noparse][[/noparse]Condition = "))    
                                 
    
    



    I have tried all of the examples listed but no luck, The one i posted works but it is not a great way to go about it. The variables will change during run time
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-16 15:49
    What you've posted can't possibly work (because of the "Pub Running").

    How about posting what you really used? Try attaching the file to your message so there's no possibility of the forum software "eating" some of it.
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-09-16 18:13
    hello grashopper,

    the following code IS running on my propeller

    So if it does not run on yours it's NOT a coding-problem
    Then the problem must be somewhere else

    
    'Use F11 to store program into the EEPROM.
    'If you open the COM-Port with a terminalsoftware this may cause
    'a reset of the propellerchip and then
    'the content of RAM will be overwritten by the content of the EEPROM
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    Var
      byte StartBit, SorB, SorC ,SorD, SorE
    
    
    OBJ
      'give the serialdriver object wich is defined in the file "FullDuplexSerial.SPIN"
      'the name "Ser" 
    
      Ser : "FullDuplexSerial"  
    
    
    Pub Main
    
      SorB := "0"  
      SorC := "-"  
      SorD := "+"
      SorE := "+"
    
      Ser.start(31, 30, 0, 9600)                    ' start serialdriver in a new cog with parameters Rx-Pin is Pin 31 Tx-Pin is Pin 30, mode 0, 9600 baud
      
      repeat 
        Running
        WaitCnt(clkfreq + cnt)
    
    Pub Running
    
      ser.str(String("[noparse][[/noparse]Condition = "))
      ser.tx(SorB)
      ser.tx(SorC)
      ser.tx(SorD)
      ser.tx(SorE) 
      ser.str(string("]"))
      ser.tx(13)
    
    
    



    best regards

    Stefan
Sign In or Register to comment.