Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can Oshonsoft use 'byref' in a FUNCTION? (Plus examples of CHAR MATCHING CODE)

camerart

Well-Known Member
Hi,
Here is a PROCEDURE from one of my programs:
'These extract characters from the raw RX buffer array to OSH string types
===================================
'AddChar: adds passed character to passed string at
'passed StrIx. Terminates result with 0 to keep it a string
Proc Addchar(ByRef str As String, ByRef StrIX As Byte, char As Byte)
str(StrIX) = char
StrIX = StrIX + 1
str(StrIX) = 0
End Proc
===================================
it uses 'byref'

I would like to know if 'byref' can also be used in an Oshonsoft FUNCTION please?
Camerart
 
Hi D,
Just a note: Youn will see, in the #31 CODE I posted (Serout PORTB.0, 9600, "XXXXX ",.........) was used. The reason is that for this CODE to fit all 4x PICs in the project the UART output is used for a different purpose.
C.
 
ByRef cannot be used with functions.
What ByRef does is modify the global variables without having to declare them within the Procedure. What happens is that it is not very optimized and consumes ram memory, so it is not advisable to use it if there is little ram memory left.

With the new update the language has turned out very well, I only have to ask oshonsoft to optimize the use of "ByRef", so that it can be used when there is little Ram memory, and a small update with the "Const" declaration, and This would be really good.
 
Last edited:
ByRef cannot be used with functions.
What ByRef does is modify the global variables without having to declare them within the Procedure. What happens is that it is not very optimized and consumes ram memory, so it is not advisable to use it if there is little ram memory left.

With the new update the language has turned out very well, I only have to ask oshonsoft to optimize the use of "ByRef", so that it can be used when there is little Ram memory, and a small update with the "Const" declaration, and This would be really good.
Hi D,
I've almost got the #31 CODE working witin the full program, as 'byref' was changed to 'byval' which does appear to work.
Do you know how to contact Oshonsoft?
C
 
My English is not very good, so my explanations are not the best.
Hi D,
English people have tried to explain, but as my programming language is also not good, it goes passed me.
Not to worry, I use my limited abilities, to move slowly forward, which is only possible with people like you helping me, thanks.
C
 
My English is not very good, so my explanations are not the best.
Hi D,
Here's a comment on language:
Your first language may not be English, and neither are the 4x Youtube posters I looked at for my byref question, as they spoke Computer language.
When explaining something to the 'layman' (an average person) simple language should be used, and not words like 'argument' which needs another search to find it's computer meaning.
Cheers, C.
 
If you've been programming for more than a week and you don't understand the definition of 'argument' then you need to re-read "programming for dummies".

If you don't understand the basics, there's no definition of 'byref' that will make any sense at all.
 
Hi C.
Don't call it an argument, In basic its just call it a parameter functions and proc use parameters. We're NOT doing C here. Functions return a parameter.

That said.. ByVal just mean pass the variable "as is". By value is a copy of the variable you need to work on.
to speed things up you can just pass a parameter by reference. I don't know how deep Vladimir went, never checked, but by a reference is basically a pointer to the variable in memory, so its always an address size.
The trouble here is you are working on that memory location. Care must be taken as you can accidentally do stuff to variables close to it. Like a string for example. by val copies the string, but by ref just passes the position of the first char in the string.. If you write to that string in the function and write too many times you will destroy the values of other variables outside that string. Its not dire, but can cause headaches...
 
If you've been programming for more than a week and you don't understand the definition of 'argument' then you need to re-read "programming for dummies".

If you don't understand the basics, there's no definition of 'byref' that will make any sense at all.
Hi T,
I learnt simple programming, in the early 80s, and have improved very slightly since then, but the programming skills, I've mainly learnt are how to program, without the skill to program. With all of the help I've had, the projecty I'm working on has gone a very long way, but I'm still poor at the basics of programming, and always will be. I have to put up with it.
C
 
Hi C.
Don't call it an argument, In basic its just call it a parameter functions and proc use parameters. We're NOT doing C here. Functions return a parameter.

That said.. ByVal just mean pass the variable "as is". By value is a copy of the variable you need to work on.
to speed things up you can just pass a parameter by reference. I don't know how deep Vladimir went, never checked, but by a reference is basically a pointer to the variable in memory, so its always an address size.
The trouble here is you are working on that memory location. Care must be taken as you can accidentally do stuff to variables close to it. Like a string for example. by val copies the string, but by ref just passes the position of the first char in the string.. If you write to that string in the function and write too many times you will destroy the values of other variables outside that string. Its not dire, but can cause headaches...
Hi I,
The Function we're talking about was written by someone else, and as usual, and I've tried to understand it for weeks, but have given in. I only change things in it, when I'm at my mates (Saturday's) with his permission :)

Thanks for your description.
C.
 
Hi,
We've been trying to get any of the MATCH CODEs to work but so far not succeded, so I've decided to move on withouth MATCH, while my mate tries to get it working, then we can add it into the 4x full programs later.
C.
 
With the new updates to the IDE, the match function of #55 is simplified to the following:

'The corresponding match function (IDE Pic18 v5.30).
Function match(input_str As Word, str_ix As Byte, match_str As Word) As Byte 'variable names can be changes
Symbol position_counter = input_str
Symbol shortposition = match_str
position_counter = input_str + str_ix
While Pointer(shortposition) > 0
If Pointer(position_counter) = Pointer(shortposition) Then
ReturnValue 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
ReturnValue 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function
 
A long time ago (80s) we needed to find a string within a (very) long string. To speed it up we added up the characters of the find string and the same length of the beginning of the long string. If there was a match you've possibly found it and can check for an actual match, if not then take away the first character and add the next character along. It speeded it up tremendously but was very specialised and probably (definitely) no good for this. There's probably a much more efficient algorithm now.

An interesting exercise.

Mike.
 
A long time ago (80s) we needed to find a string within a (very) long string. To speed it up we added up the characters of the find string and the same length of the beginning of the long string. If there was a match you've possibly found it and can check for an actual match, if not then take away the first character and add the next character along. It speeded it up tremendously but was very specialised and probably (definitely) no good for this. There's probably a much more efficient algorithm now.

An interesting exercise.

Mike.
Hi M,
I've got a fairly good idea, of what you did, also the above FUNCTION, but fairly is not good enough for progamming, so my mate is in charge of the MATCH CODE, while I work on the main prog without it.

And people wonder why this project is taking such a long time :)
C.
 
With the new updates to the IDE, the match function of #55 is simplified to the following:

'The corresponding match function (IDE Pic18 v5.30).
Function match(input_str As Word, str_ix As Byte, match_str As Word) As Byte 'variable names can be changes
Symbol position_counter = input_str
Symbol shortposition = match_str
position_counter = input_str + str_ix
While Pointer(shortposition) > 0
If Pointer(position_counter) = Pointer(shortposition) Then
ReturnValue 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
ReturnValue 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function
Hi D,
Thanks.
I substituted the old MATCH with yours, and got this error?
C
 

Attachments

  • Match.jpg
    Match.jpg
    376.2 KB · Views: 52
Last edited:
Yes, you have to update the IDE for it to compile.
In any case, that version of "match" is to work with the memory addresses of the arrays, if you do not supply the memory addresses to the function, even if it compiles it will not work for you.
 
Yes, you have to update the IDE for it to compile.
In any case, that version of "match" is to work with the memory addresses of the arrays, if you do not supply the memory addresses to the function, even if it compiles it will not work for you.
Hi D,
My IDE was updated a while ago.
I'll send this CODE to my mate who's looking at the MATCH CODE.
Thanks, C.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top