Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

sub does not work?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Jul 03, 2014 10:59 am    Post subject: sub does not work? Reply with quote

Why does the sub not work?
All I have done is to put the two lines of code into a sub so not to have to repeat them multiple times the variables are global!

Regards Paul

Code:

                     Wsize = Len(txbuffer)
                     ' Bsize = Len(txbuffer)
                      'Call Buffer_send                      ' (Bsize global)
                       Call Activate_wiz812
                     Tempw = Tcpwrite(i , Txbuf(1) , Wsize) ' i global


   End Select


End Sub



Sub Buffer_send

        Local Tempj As Word

                    Call Activate_wiz812
                      Tempj = Tcpwrite(i , Txbuf(1) , Bsize)       ' write data  (I global)



End Sub
 


(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5916
Location: Holland

blank.gif
PostPosted: Thu Jul 03, 2014 11:44 am    Post subject: Reply with quote

when you move code to a sub it should work just fine as long as you have enough $hwstack since it will create an additional stack level.
you really should post something we can check. for example the version that works, and the version you modified and doesnt.

_________________
Mark
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Jul 03, 2014 12:30 pm    Post subject: Reply with quote

Hello Mark
Trouble is posting a version that works is its too big, now 14 inter-related subs I can only put the whole lot up as a zip but I just posted the small bit of code to show that simply putting it into the sub it did not work , it compiles ok just does not work , as you say just moving it to a sub should work Note the stacks are fine I added 100 to each to test if they were the problem.
Just for interest sake and it shows how to do redirection in the browser, here is the whole sub with multiples of those 2 lines you can see where I commented the calls. Also I tried making Wsize global I am not going to try to find this it wastes too much time it works ok with multiples of the 3lines of code, just thought maybe I was doing something wrong.

Regards Paul

Code:

'*******************************************************************************
' send data from SD Card
'error codes
'66 file not found
'*******************************************************************************
Sub Sd_html
   Local Fl As Long
  ' Local Wsize As Word
   Local Tempw As Word
   Local Lb As Byte
   Local Lc As Byte
   Local Lz As Byte
   Local Lf As Word                                         'we keep track of the number of bytes in the buffer
   Local Ltxt As String * 30

   Lf = 0

   Txbuffer = ""                                            'clear buffer



   '=====================
   '=Redirection of pages    this will be needed for later
 '     Http / 1.1 301 Moved Permanently
'      Location : Http : / / Www.example.org/

   Select Case Redirect

    Case 0                                                  'no redirection

      Txbuffer = "HTTP/1.0 200 OK{013}{010}"                'put the OK response in the buffer
 '==as we have a file type variable need to re write this
           Select Case Ext

               Case "ico" : Txbuffer = Txbuffer + "Content-Type: image/x-icon{013}{010}"
               Case "gif" : Txbuffer = Txbuffer + "Content-Type: image/gif{013}{010}"
               Case "jpg" : Txbuffer = Txbuffer + "Content-Type: image/jpeg{013}{010}"
               Case "js" : Txbuffer = Txbuffer + "Content-Type: application/x-javascript{013}{010}"
               Case "css" : Txbuffer = Txbuffer + "text/css{013}{010}"
               Case Else : Txbuffer = Txbuffer + "Content-Type: text/html{013}{010}"

           End Select
   '==========
          '#if Cdebug
             Print "send " ; Shtml ; " on Sock= " ; I
           '#endif
           Call Activate_sdcard()
      Fl = Filelen(shtml)                                   'find the length of the file


          '  #if Cdebug
              Print "size :" ; Fl
           ' #endif
       If Fl > 0 Then

           ' This header indicates the number of bytes in the response.
           'This information is needed only if the browser is using a persistent (keep-alive) HTTP connection.
             Tempw = Instr(buffer , "keep-alive")
              If Tempw > 0 Then
                   Txbuffer = Txbuffer + "Content-Length: " + Str(fl) + "{013}{010}"
              End If


                 Txbuffer = Txbuffer + "{013}{010}"         ' add additional CR and LF
                 Lf = Len(txbuffer)
                 Call Activate_wiz812

                 Tempw = Tcpwrite(i , Txbuf(1) , Lf )       'send response

                Txbuffer = ""                               'clear buffer

               Call Activate_sdcard
              Open Shtml For Binary As #4
            Do

                If Filetype = 4 Then                        'this is a cgi file
                          ' Print "filetype=4"

                         Call Activate_sdcard
                         Lf = 0
                   Do
                          Get #4 , Lb , , 1                 'get one byte
                          Decr Fl                           'we have read one byte

                      If Lb = 126 Then                      'then its ~

                        Get #4 , Tmpb(1) , , 2              'get the next two bytes as this is the hex value

                          Replacemnt = ""

                        Call Hex_replace(tmp2)              'tmp2 contains the hex value as a string

                        Lc = Len(replacemnt)                'find out how many bytes we insert

                            If Lc > 0 Then                  'there are bytes in string
                              For Lz = 1 To Lc

                                  Incr Lf                   'move to next free byte in buffer

                                  Txbuf(lf) = Rpl2(lz)      'insert byte from string replacemnt

                              Next
                            End If



                           Decr Fl                          'we have read 2 bytes
                           Decr Fl

                         Else

                           Incr Lf                          'add 1 to the buffer size pointer

                          Txbuf(lf) = Lb                    'put byte into buffer

                      End If

                        If Lf > 800 Then                    'buffer is full  with 200 bytes  of space for inserted bytes

                           Exit Do

                        End If

                   Loop Until Fl = 0

                          Wsize = Lf                        'number of bytes in the tx buffer
                     Lf = 0
                  Else                                      'send the file
                         ' Print "Not CGI >" ; Filetype
                              Call Activate_sdcard
                         If Fl > 1000 Then                  'send 1000 Bytes
                               Get #4 , Txbuf(1) , , 1000
                               Fl = Fl - 1000 : Wsize = 1000
                           Else
                              Get #4 , Txbuf(1) , , Fl      'send the rest
                                 Wsize = Fl : Fl = 0
                         End If


                End If

                   'Print "Wsize>" ; Wsize
                    'Print "Fl>" ; Fl
                   ' Call Buffer_send                        ' (wsize)
                      Call Activate_wiz812
                      Tempw = Tcpwrite(i , Txbuf(1) , Wsize)       ' write data
                    If Tempw <> Wsize Then
                       #if Cdebug
                          Print Tempw ; " - " ; Wsize ; " written : error"       'when error
                       #endif
                       Exit Do
                    End If
            Loop Until Fl = 0
         Close #4

          Else                                              'file does not exist
              Print "file does not exist"
          Txbuffer = ""


                   Shtml = "error404.htm"                   'make a variable so this can be set
             Fl = Filelen(shtml)                            'custom error file

               If Fl > 0 Then                               'there is a custom error file

                  Tempw = Tcpwrite(i , "HTTP/1.0 404 Not Found{013}{010}{013}{010}" )       'send response

                   Do
                         Call Activate_sdcard
                         Open Shtml For Binary As #4

                         If Fl > 1000 Then                  'send 1000 Bytes
                               Get #4 , Txbuf(1) , , 1000
                               Fl = Fl - 1000 : Wsize = 1000
                           Else
                              Get #4 , Txbuf(1) , , Fl      'send the rest
                                 Wsize = Fl : Fl = 0
                         End If
                      'Call Buffer_send                      ' (wsize)
                      Call Activate_wiz812
                      Tempw = Tcpwrite(i , Txbuf(1) , Wsize)       ' write data


                   Loop Until Fl = 0
                   Close #4
                   Else
                      '==send page from flash
                  ' Print "Send file not found page"
                    'Call Activate_wiz812
                    Txbuffer = ""
                    Restore Notfound_page                   'restore the data pointer
                     Do

                       Read Ltxt                            'read data
                       If Ltxt = "endblock" Then            'end of data
                               Exit Do
                       End If
                      Txbuffer = Txbuffer + Ltxt
                     Loop

                      Wsize = Len(txbuffer)

                      'Print "Buffer is >" ; Wsize ; "<Bytes"
                      'Print Txbuffer
                    ' Call Buffer_send                       ' (wsize)
                     Call Activate_wiz812
                     Tempw = Tcpwrite(i , Txbuf(1) , Wsize)


               End If









       End If
     Case 1                                                 'we will be redirecting to a url

          Txbuffer = "HTTP/1.0 200 OK{013}{010}"            'put the OK response in the buffer



              Txbuffer = Txbuffer + "Refresh: 0; Url=Http://192.168.0.192/"
              Txbuffer = Txbuffer + Shtml
              Txbuffer = Txbuffer + "{013}{010}{013}{010}"
              Txbuffer = Txbuffer + " Content -type : Text / Html{013}{010}"
              Print "REDIRECT"
              Print Txbuffer

                      Wsize = Len(txbuffer)
                     ' Bsize = Len(txbuffer)
                      'Call Buffer_send                      ' (Bsize global)
                       Call Activate_wiz812
                     Tempw = Tcpwrite(i , Txbuf(1) , Wsize) ' i global


   End Select


End Sub



Sub Buffer_send

        Local Tempj As Word

                    Call Activate_wiz812
                      Tempj = Tcpwrite(i , Txbuf(1) , Bsize)       ' write data  (I global)



End Sub
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5916
Location: Holland

blank.gif
PostPosted: Thu Jul 03, 2014 12:45 pm    Post subject: Reply with quote

of course i mean you need to zip it.
just as with support, i do not have time to look at big programs. so i usually ask for 2 versions : one that is ok, and one that is modified. Or the code can have some remarks that must be unremarked or remarked to show the problem. i then check both codes with windiff or so and also the output. but posting fragments of code is not helping since i can not compile. i do not have time to add in the missing vars. and even when i have, i could use different types which lead to possible different results.
now you said you just moved the lines. but that is not true for the code you show. (at least when you mean buffer_send)
- you added a new var and also use a new name now for the return result. maybe your code depends on the first used var name?
if you really only move code then it means you select, cut and replace with a call.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum