Wait for a serial response, how to do it?

techknight

Well-Known Member
Licensed User
Longtime User
My program is setup to use the AsyncStream, borrowed much of the code from the bluetooth example.

Well, I can send and receive packets fine. BUT....

I want my program to send a packet, and then wait around for a reply, once a reply is received the program will move on. If a reply is not received within a specified period of time, then exit and move on with null data.

Ive done this a bazillion times in VB6 with Timers, flags, DoEvents, and the OnComm routine.

Well, Trying to do this in B4A in Prefix mode, the NewData routine only gets called when the full packet arrives. that is fine. That works ok. I have the NewData setup to convert the buffer to HexString, and set the RxFlag to true.

However, If i try a simple old routine like this:

RxTimer.Enabled = true
Do until RxFlag = True OR RxTimedOut = true
DoEvents
Loop until RxFlag = true

the serial data never arrives and I could be sending it a million times, it doesnt matter. The timer still ticks and runs out though, itll run out throwing my timedout flag and it exits the Do loop with no data.

Once the loop eventually ends, the NewData routine will execute when serial data gets sent. But i never seem to get data while inside the wait loop.

ugh.

Any way to do this any better?
 
Last edited:

techknight

Well-Known Member
Licensed User
Longtime User
That is going to present a problem then.

I am trying to implement xmodem checksum protocol over the bluetooth, its in a loop and advances an address pointer every page, which is 128bytes on the AVR.

Basically its an app that writes a hex file through bluetooth to my AVR Atmel CPU via the bluetooth serial link, which there is a bootloader on the atmel CPU that receives the xmodem checksum data and writes the page, and sends a reply to indicate the checksum is good and such.

How would i code around this?

The purpose? Well, Android is going to control my external hardware peripheral and it checks if there is a firmware update for my connected serial device. if a newer firmware is found on my server, it downloads the hex and flashes the CPU inside my hardware over the bluetooth connection.

ive done this in VB6 without problems. The transfer method is xmodem checksum and each page is 128bytes, 128bytes get sent and checked/written to the chip, a reply is made and it moves on to the next address page pointer. until its complete.
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I guess really the only way around it is use a timer to re-run the sub. Run the sub to send the 128bytes, prepare for receive and then disable the timer.

Wait for newdata to reply, once replied, perform the data evaluation there to make sure everything is A-ok, If ok, advance the address pointer in a global variable and re-enable the timer. Timer fires, and the process starts all over again.

I guess this is the only way around it. Any ideas?
 
Upvote 0

nozlaf

New Member
Licensed User
Longtime User
how did you go?

did you get this working? im thinking of doing a project that is going to need to transfer data from an atmel based device and i was thinking of using xmodem so if you have an example of how you got yours to work that would be appreciated
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
I work with embedded systems too. No timer, or wait loops. Just put the information in a packet with header information that can be used when received in full by NewData. I use a Select statement, so if it is a checksum, do that task, if data to log, log it ....
 
Last edited:
Upvote 0

Similar Threads

Top