Hserin / out Woes..


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Hserin / out Woes..

    Hi All..

    Am using this code as a simple password check on a serial link :-

    Code:
    hserout [":- "]
                hserin 65535,bed, [pass (0)]: hserout [pass (0)]
                hserin 65535,bed, [pass (1)]: hserout [pass (1)]
                hserin 65535,bed, [pass (2)]: hserout [pass (2)]
                hserin 65535,bed, [pass (3)]: hserout [pass (3)]
                hserin 65535,bed, [pass (4)]: hserout [pass (4)]
                hserin 65535,bed, [pass (5)]: hserout [pass (5)]
                hserin 65535,bed, [pass (6)]: hserout [pass (6)]
                hserin 65535,bed, [pass (7)]: hserout [pass (7)]
                hserin 65535,bed, [pass (8)]: hserout [pass (8),10,13]
                
                IF ("2" = pass(0))and ("9" = pass(1))and ("9" = pass(2))and ("7" = pass(3))and ("9" = pass(4))and ("2" = pass(5))and ("4" = pass(6))and ("5" = pass(7))and ("8" = pass(8)) THEN correct
    There are nine decimal digits which have to be correct.... but some times it fails on the last digit, but not always ?? If I cut the pass word to 4 digits it fails also on the last digit ????

    My question is... is there a more elegant way of doing the above? I still want to see each char as typed...wich rules out a string of words.

    But more I need it to be reliable..I am using a 4 Meg Xtal my defines are :-

    Code:
        DEFINE OSC 4	'Set oscillator in MHz
        'OSCCON = $60     '4 Megs
        
        DEFINE HSER_RCSTA 90H   'Set receive status and control
        DEFINE HSER_TXSTA 24H   'Set transmit status and control
        DEFINE HSER_BAUD 9615   'Baud Rate
        
        
        ADCON1 = 7 ' Turns Analogs off
        CMCON0 = 7 'Disable both comparators
        ANSEL = 0  ' Set all analog pins to digital
    thank you for looking....

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

    Default Re: Hserin / out Woes..

    Hi,
    I'm not sure if the DEFINE HSER_BAUD accepts non standard baudrates, I suspect it does since it kind of works. What's with the 9615 anyway?
    I don't know what would make it fail on the last character - sometimes. Are you typing in, and sending, the characters one by one, ie there's 100ms or whatever between each character?

    Anyway, here's an alternative aproach I just wrote. I have not tested it, not even compiled it so take it for what it is.

    Code:
    Key VAR BYTE
    CorrectKey VAR BYTE[9]
    KeyIndex VAR BYTE
    PassFail VAR BIT
    
    Pass CON 1
    Fail CON 0
    
    CorrectKey[0] = "2"
    CorrectKey[1] = "9"
    CorrectKey[2] = "9"
    CorrectKey[3] = "7"
    CorrectKey[4] = "9"
    CorrectKey[5] = "2"
    CorrectKey[6] = "4"
    CorrectKey[7] = "5"
    CorrectKey[8] = "8"
    
    
    Main:
    hserout [":- "]
    
    PassFail = Pass
    For KeyIndex = 0 to 8
    	HSERIN 65535, bed, Key
    	HSEROUT Key
    	IF Key <> CorrectKey[KeyIndex] THEN
    		PassFail = Fail
    	ENDIF
    NEXT
    
    IF PassFail = Pass THEN
    	HSEROUT[10, 13, "Correct key entered",10, 13]
    ELSE
    	HSEROUT[10, 13, "Wrong key entered", 10, 13]
    ENDIF
    /Henrik.

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: Hserin / out Woes..

    Here is another approach that allows you to wait for all of the characters to be entered before testing the password.
    It also makes use of arraywrite to enter the Master Password.

    Code:
     DEFINE OSC 4	'Set oscillator in MHz
        'OSCCON = $60     '4 Megs
        
        DEFINE HSER_RCSTA 90H   'Set receive status and control
        DEFINE HSER_TXSTA 24H   'Set transmit status and control
        DEFINE HSER_BAUD 9615   'Baud Rate
    
    MasterPass var byte[9]
    pass var byte[9]
    PassTest var bit
        
    i var byte
        
    '    ADCON1 = 7 ' Turns Analogs off
    '    CMCON0 = 7 'Disable both comparators
    '    ANSEL = 0  ' Set all analog pins to digital
        
        arraywrite MasterPass,["299792458"]
    
    main:    
        'Test for 299792458
        PassTest = 1
        for i = 0 to 8
            pass[i] = 0
        next i
        
        hserout [":- "] 
        for i = 0 to 8
            hserin 65535, bed, [pass(i)]
            hserout [pass(i)]
        next i
        
        'Check Password with Master
        for i = 0 to 8
            if pass(i) <> MasterPass(i) then PassTest = 0 
        next i
    
        if PassTest = 1 then correct
        
        hserout [13,10,"NO WAY!!",13,10]
        
        
        goto main
    
    
     
    correct:
    
        hserout [13,10,"Correct!",13,10]
        
        goto main
    
                
    bed:
        hserout ["Timeout",13,10]
        
                
     bye:
            goto main
    Regards,
    TABSoft

  4. #4
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    Thanks for the replies.....

    Will try then out later.... have been working away!

    BR
    Andy

  5. #5
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    hi All...

    Have played with my code a little more....

    Have come to conclusion that the serial port is seeing 0xFf before I type any password... I found by putting a 232 sniffer on the ports !!!


    Ie the password is 9 chars but the first on occasionally is 0xFF ????

    any Ideas ? anyone ?

    Tomorrow O will go back to Serin / Serout see how that gets on !

    Thank you for help !

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,149

    Default Re: Hserin / out Woes..

    For reliable communications, I always clear the receive buffer before transmitting a request to any perif. That way if you have some noise on the comm lines, it won't be interpreted as bad data.
    Dave Purola,
    N8NTA
    EN82fn

  7. #7
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    Quote Originally Posted by Dave View Post
    For reliable communications, I always clear the receive buffer before transmitting a request to any perif. That way if you have some noise on the comm lines, it won't be interpreted as bad data.
    Hi Dave

    Sounds good.... But how do I do that ?

    I see no pointers in the manual V2.60

    THank you for help

  8. #8
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    MY Defines are now :-

    DEFINE HSER_RCSTA 90H 'Set receive status and control
    DEFINE HSER_TXSTA 24H 'Set transmit status and control
    DEFINE HSER_BAUD 9615 'Baud Rate
    DEFINE HSER_CLROERR 1 ' Clear Buffer

  9. #9
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: Hserin / out Woes..

    Andy,

    You can always just use a "HSERIN" bogus statement to throw away anything in the buffer before you execute your regular "HSERIN" statements.
    Since the EUSART has a 2 byte buffer you may need to do two of the bogus "HSERIN" statements with timeouts just to make sure you don't get stuck waiting.
    Regards,
    TABSoft

  10. #10
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    Hi

    Thanks for reply ...

    Will try tomorrow and post what happens ...

    Thank you for advice

    Andy

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,234

    Default Re: Hserin / out Woes..

    Hi,
    You can always just use a "HSERIN" bogus statement to throw away anything in the buffer before you execute your regular "HSERIN" statements.
    Just keep in mind that if there is no garbage data in the RX buffer then the bogus statement will throw away the real data when it comes so if you go down that route make sure you specify a very low timeout value for the initial bogus statement.

    Here's another way to flush the buffer:
    Code:
    RCIF VAR PIR1.3    ' Alias to the RX Interrupt flag for USART 1 on an 18F25k22
    Dummy VAR BYTE
    WHILE RCIF
       Dummy = RCREG1
    WEND
    /Henrik.

  12. #12
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    222

    Default Re: Hserin / out Woes..

    Quote Originally Posted by Tabsoft View Post
    Andy,

    You can always just use a "HSERIN" bogus statement to throw away anything in the buffer before you execute your regular "HSERIN" statements.
    Since the EUSART has a 2 byte buffer you may need to do two of the bogus "HSERIN" statements with timeouts just to make sure you don't get stuck waiting.
    Hi

    I just put your suggestion in place and it seems to be working for me .... I just used 50 as a time out figure... thank you!

    I will try the other suggestions also thank you as always Henrik

    For now I need sleep !!!!!

    Br
    Andy

Similar Threads

  1. SPI woes
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th September 2013, 14:04
  2. Capture woes...
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2011, 08:36
  3. LCDOut Woes
    By LetTheSmokeOut in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th June 2008, 01:45
  4. ICD Woes
    By spad13m in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th February 2008, 05:56
  5. Still HSEROUT woes
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 11th July 2006, 21:13

Posting Permissions

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