Shop OBEX P1 Docs P2 Docs Learn Events
propeller serial comms problems — Parallax Forums

propeller serial comms problems

realolmanrealolman Posts: 65
edited 2010-01-02 21:00 in Propeller 1
I have in the propeller an array called "parameters", which I am trying to populate, and communicate with, using a visual basic express program.

It·mostly works, but it often does not... it is unreliable.·

from the VB program I am sending a "#"· just to let the propeller know something is coming, followed by a number and a chr(13) and another number and another chr(13).·

Then the propeller is sending back to the computer what it just received, so I know it got it.· It adds a "P" and an "=" so the VB program can strip it down to the values of interest.· Sometimes the values·are one digit, sometimes two, three, or four

this is the code in the propeller:
··
If ser.rxcheck <> -1     'checks to see if serial input. 
                                    'if nothing there, returns -1 send any character 
                                     'to make true 


WhichVariable := ser.rxDec           'receive a number and a carriage return chr(13) ( which element of the array "Parameter")

InputVariable := ser.rxDec             'receive a number and a carriage return chr(13)  (what to put in the element of the "Parameter" array)
 

                           'Tx parameter back to computer to ensure 
                            'it has been received by propeller 

ser.str(string("P" ))            ' distinguishing character 
ser.dec(WhichVariable) 
ser.str(string("="))              ' shows where value begins 
ser.dec(InputVariable)         'value of parameter 
ser.tx(13) 
ser.tx(10) 



Parameter[noparse][[/noparse]WhichVariable]:=InputVariable          'load the array element with the value received


Is there a way I can make this more reliable?

thanks

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2010-01-02 15:10
    The following may be helpful, which I have snipped from Rayman's Windows-to-Prop serial driver for the excellent PSM:

    [noparse][[/noparse]PUB CommandLoop| i ' start command receive&process cycle
    'Now, start command receive&process cycle
    repeat
    'wait for command code prefix
    repeat
    i:=GetB
    until i==CommandPrefix 'wait for the command code prefix, $C5

    'get command group code
    case GetB
    "G": 'General commands group
    ProcessGeneralCommand
    "T": 'Text commands group
    ProcessTextCommand]
    This works well for me. I don't have sufficient insight to describe properly whether there is an effective difference between Rayman's method compared to yours; but I think that this 'wait for command code' is more deterministic.
    T o n y
  • TonyWaiteTonyWaite Posts: 219
    edited 2010-01-02 15:14
    [noparse][[/noparse]/PUB CommandLoop| i ' start command receive&process cycle
    'Now, start command receive&process cycle
    repeat
    'wait for command code prefix
    repeat
    i:=GetB
    until i==CommandPrefix 'wait for the command code prefix, $C5

    'get command group code
    case GetB
    "G": 'General commands group
    ProcessGeneralCommand
    "T": 'Text commands group
    ProcessTextCommand]

    Re-posted the snip from Rayman's code in an effort to show its indentation properly.
    T o n y
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-01-02 15:42
    Hi realolman , this link http://forums.parallax.com/showthread.php?p=785572 has a spin file called VBtest.spin that contains a method to detect your header and two methods that transmit and receive an array of byte values. The post also contains a link to another post with the terminal app I used for test purposes , the latter post was originated by yourself , I was wondering if you had tried VBtest I found it to work well but if it has flaws it would be interested to know in an attempt to improve.

    Jeff T.

    ·
  • realolmanrealolman Posts: 65
    edited 2010-01-02 21:00
    I want to thank you all for your replies. Unsoundcode , you can see that I haven't made a whole lot of progress.· I may not be good, but I am slow.smilewinkgrin.gif

    Unfortunately I am not understanding what you want me to do.· Do you want me to abandon what I have and·start over with·something else?.

    I appreciate everyone's help, but I think that even though you have found code that works for you, I don't think I am willing to abandon mine and try to figure out what is going on with yours, and make the necessary changes to both my VB code and my spin code.·· I think I would become·completely lost If I tried to start over with something else.

    I was hoping perhaps you would help me figure out why what I have doesn't seem to work reliably.

    When the··
    If ser.rxcheck <> -1
    

    · line encounters a received transmission it executes the code below it.· ( The indentations seem to suffer in cutting and pasting )

    How can I make sure that the transmission I sent to the propeller is completely received by the propeller, before it assigns what it received to a variable in the propeller?· How can I know it's not assigning an unfinished transmission to the variable?
    WhichVariable := ser.rxDec 
    

    The numbers I will send to the propeller in this application could be any integer between 0 to 1200.

    Thank you in advance



    Post Edited (realolman) : 1/2/2010 9:05:20 PM GMT
Sign In or Register to comment.