Hi I,Hi C. Yes the only difference between proc's and functions is the return.
Byref is only necessary when the variable isn't global.
If said string is declared on the top of all code you can access the string without passing its reference.
All strings in Oshonsoft can be accessed by index. BUT!! I don't want to confuse you as strIX and str may be easier for you to manipulate.
Hi D,Hello; "ByRef" can only be used with "Proc".
With "Function" you can only work with global variables or with memory addresses (pointers) that represent the variables involved.
WOW... I was sure I could do both. I haven't used Oshosoft for quite some time.Hello; "ByRef" can only be used with "Proc".
With "Function" you can only work with global variables or with memory addresses (pointers) that represent the variables involved.
Hi,WOW... I was sure I could do both. I haven't used Oshosoft for quite some time.
But I would have used global variable anyway..
Reading the help file he does say ALL facts about procedures are the same for functions
I would have preferred to just have "Function" and the programmer choose whether data is returned or not, like in C.
The problem with "ByRef" is that it works first by "value" and when exiting the procedure it copies the image over the original. This is not very efficient, if you work with microcontrollers with just enough memory it will cause problems.
For me it is more comfortable to work with "Function" so I wrote a library to work with memory addresses with the "String" type, or with normal arrays used as string.
'18F4431 32MHz XTL PCB8 BASE_SLAVE match 2 strings E 170123 short 2
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz x4 =32
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
'OSH config
Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20
Define SEROUT_DELAYUS = 1000
'**********************************************************************
'* *
'* Register configuration *
'* *
'**********************************************************************
'------------- TARGET SETUP ------------------
'Const PR2set = 125 'use this for the live board: gets 5ms per interrupt
Const PR2set = 2 'use this for fast timing to speed up simulator
Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
'**********************************************************************
'* *
'* IO Port configuration *
'* *
'**********************************************************************
'IN or OUT
Const TRISAinit = %11011000 '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %11000100 '7=1-RX, 6=1-slave4431_cs, 2=MOSI'RX<<<<<<<<<<<<<<<<<<<<<
Const TRISDinit = %00100000 '6=led, 7=led, 5=synch'D2=MOSI ??£
Const TRISEinit = %00000000 '2=TEST INDICATOR, 0= S2M_BUF_FULL
TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit
'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000 'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000 'POSS MCLR RE3
Symbol yled = PORTD.6
Symbol rled = PORTD.7
'START UP LEDS
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000
yled = 1
WaitMs 1000
yled = 0
WaitMs 1000
Dim to_match_str As String ' the string to match
Dim gnrmc_str As String ' the string used for test purposes
Dim position As Byte ' the position in the main string to start from
main_loop: '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Toggle rled
' set the string to be checked (in this case called gnrmc_str)
gnrmc_str = "$gnrmc0.00A3723."
to_match_str = "gnrmc"
position = 1
'check For the id String
' I have called this funtion "match" - you can call it anything you like as long as the name is consistent
' match uses 3 inputs. The first is the string to be tested. I have used gnrmc_str but it can be any valid string variable
' The second input is the position to start checking from. in this case it is the numbber 1
' (arrays start at 0 so the second character in the array is 1)
' The third input is the string of characters to be checked against. I hane used gnrmc in
' this example but it could be robi, ROBI, bori, BORI etc
Call match(gnrmc_str, position, to_match_str)
'Break
If match = 1 Then
'Break
' if OK go to good string found
Else
'Break
'if not ok goto bad string found
Endif
Goto main_loop
End
'the corresponding match function
Function match(ByVal input_str As String, ByVal str_ix As Byte, ByVal match_str As String) As Bit ' these variable names can be changes as wished
Dim match_str_len As Byte 'the number of characters to be match checked
Dim position_counter As Byte ' the index pointer for the character to be checked
Dim position_ix As Byte
Dim shortstring As Byte
Dim shortposition As Byte
position_ix = str_ix + match_str_len 'the position to start checking from
match_str_len = Len(match_str) ' find the length of the test string to be compared
For position_counter = str_ix To position_ix
shortstring = position_counter - match_str_len
'Break
If input_str(position_counter) = match_str(shortposition) Then
match = 1
Else
match = 0
Exit ' jump out of the loop
Endif
Next position_counter
End Function
I agree, the best language in this case, an environment with an integrated simulator, is the one that allows you to do what you want without getting bored. I have also been supporting this project for more than 15 years.
Another issue is that on a personal level I like to go deeper into the system, possibly to a level that is not necessary.
In any case, all languages have their problems, I have had quite a few problems working with C, until I was able to overcome the bugs and oddities that each compiler has.
Focusing on the topic:
ByVal: are all the variables that are declared by default. It is not necessary to put it. It is only used to clarify the code when mixed with ByRef and ByRefOut.
Hi D,I agree, the best language in this case, an environment with an integrated simulator, is the one that allows you to do what you want without getting bored. I have also been supporting this project for more than 15 years.
I understand that 'byval' etc are for pointing, but I couldn't use them in a program, as they are just beiyond my brain.ByVal: are all the variables that are declared by default. It is not necessary to put it. It is only used to clarify the code when mixed with ByRef and ByRefOut.
'**************** Look for GNRMC, check if necessary************************
[If matchgnrmc("GNRMC", 1) = 1 Then]
'MATCHGNRMC GPS checks the 5x BYTES after the $ making sure they match GNRMC
Function matchgnrmc(gnrmc_str As String, BufIX As Byte) As Bit
Dim gnrmc_str_char As Byte 'local variables
Dim gnrmc_buf_char As Byte
Dim StrIX As Byte
StrIX = 0 'start at first char of passed string
MatchLoop: '<---
'Break '<<<<<<<<<<<<<<<<<<<
gnrmc_str_char = gnrmc_str(StrIX) 'get str char
If gnrmc_str_char = 0 Then 'if it is 0 then end of passed string and..
matchgnrmc = 1 'All GNRMC CHARS are equal
PORTE.2 = matchgnrmc '<<<<<<<<<<for indication<<<<<<<<<<<<@
Exit
Else
gnrmc_buf_char = gnrmc_buf(BufIX) 'else not end of string, get buf char and compare
If gnrmc_str_char <> gnrmc_buf_char Then
matchgnrmc = 0 'GNRMC CHARS are not equal
PORTE.2 = matchgnrmc '<<<<<<<<<<For indication<<<<<<<<<<<<@
Exit
Endif
Endif
StrIX = StrIX + 1 'else, not at end of string and no mismatch
BufIX = BufIX + 1 'bump indexes and do next
Goto MatchLoop '-->
End Function
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?