View previous topic :: View next topic |
Author |
Message |
toto
|
Posted: Sat Jan 25, 2014 1:39 pm Post subject: Exists a way to implement a Timeout? |
|
|
Hello,
I use the hardware Usart to send and receive data trough RS485
dim as Ori byte , Rx_coman as byte , Quant_bytes as byte , Rx_end as byte, Temp_nr as word , pl_nr as word
dim yptas byte , Word_dbg as word , R_done as byte , Rx_dad(16) as byte , Master as byte
_a:
If Ischarwaiting(#1) <> 0 Then
Inputbin #1 , Serialchar 'get the byte
If Serialchar <> Master Then Goto localation2 'is the first byte not 254 continue to other location
Inputbin #1 , Ori , Rx_coman , Quant_bytes , Rx_end , Temp_nr , ypt , Word_dbg , R_done , Rx_dad(1) , Quant_bytes
If Temp_nr <> pl_nr Or R_done <> 125 Then 'test if part of the received data are correct or not
R_done = 0 : Rx_dados(1) = 0
Clear Serialin
Reset Watchdog
End If
End if
location2:
Note that the INPUTBIN statement doesn't wait for a <RETURN> but just for the number of bytes. Help from Bascom!!!!
What happend here if all the expected data not received correct "noise", wait the Inputbin forever?
If yes, exists a way to implement a Timeout?
Best regards
toto
(BASCOM-AVR version : 2.0.7.2 , Latest : 2.0.7.6 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Jan 25, 2014 8:03 pm Post subject: |
|
|
Hi,
Why not use inkey to grab individual Bytes, that you copy into an Array and when youget the end of message character process the message.
I quite often put the Serial Input processing in a uart receive ISR that handles to low Level processingand passes "complete" Messages to the main app.
something like
Code: |
Rfid_char = Inkey(#1) 'Read serial char
If Rfid_char = 2 Then 'Chr 2 - Start of MSG
Rfid_ptr = 0 'Reset pointer
End If
Incr Rfid_ptr 'Move to next byte
Rfid_array(rfid_ptr) = Rfid_char 'Save char to array
If Rfid_ptr = 13 Then 'and correct length
Rfid_have_buffer = 1 'tell user space
Rfid_ptr = 0 'Reset buffer
End If
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
toto
|
Posted: Sat Jan 25, 2014 10:07 pm Post subject: |
|
|
Hi i.dobson,
I never have used Inkey and dont know if it works for my case then in the Inputbin stream i receive the bytes quantity information to fill the byte array, thats why i use inputbin. But if it freeze if not receive the expected quantities of data, i can't use it in my program.
I look for a solution to implement a Timeout in my code
I apreciate if anyone can help me with the Timeout
Best regards
toto |
|
Back to top |
|
|
for_ro
Joined: 11 Nov 2007 Posts: 260
|
Posted: Sat Jan 25, 2014 10:24 pm Post subject: |
|
|
$Timeout ? |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Jan 25, 2014 10:35 pm Post subject: |
|
|
Hi,
inkey is like inputbin, just that it gets one character. So you need to manually copy the result into an Array.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
|
|
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
|
|