Post by Rod on Mar 13, 2019 4:49:47 GMT -5
Have a look at this code. I assume it is the serial read functions that are giving bother. This will be because your code is stuck in one or the other functions waiting on data. If you can be clearer about what error messages you get that would help.
'you have not set ADR$ or ADR1$ to any value prior to calling the function
'probably makes no difference as they are not used yet?
'you need to think about the timing of the serial link?
'how fast is the system cycling and how fast are the messages coming in?
'as you have it coded the program will be sitting waiting inside one function
'when the timer fires Thats a know problem, you should never wait or or get stuck
'in a function in a long loop if you know the timer is about to fire.
'what error messages are you getting?
koenr$=readADR$(ADR$)
ipnr$=readADR1$(ADR1$)
function readADR$(board$)
while lof(#com) < 1 ' the ADR always sends back 3 digits
wend
readADR$ = input$(#com,lof(#com))
end function
function readADR1$(board1$)
while lof(#com1) < 13 ' the ADR always sends back 3 digits
wend
readADR1$ = input$(#com1,lof(#com1))
end function
'suggested code, dont hang about in the function but be prepared for an empty string
'in the return value.
'You should call each function twice as fast as you expect the message frequency
'so if the messages are sent every 500ms then call the functions every 250 ms
'that way you will keep just ahead of the pace and messages will not accumulate
'in the serial buffer.
null$=""
koenr$=readADR$(null$)
ipnr$=readADR1$(null$)
function readADR$(null$)
if lof(#com) >=3 then readADR$ = input$(#com,3) ' the ADR always sends back 3 digits
end function
function readADR1$(null$)
if lof(#com1)>=13 then readADR1$ = input$(#com1,13) ' the ADR always sends back 13 digits
end function