PDA

View Full Version : SerIn Looping problem ???



gtvmarty
- 23rd September 2009, 07:01
Hi All,

I'm trying to find out what happens to the "SerIn" command when no valid data is present on the RS232 line.


For example:



Loop:
SerIn pin1,T9600,SerialData 'get serial data from Pin1,
'store it in variable "SerialData"

SerOut pin2,T9600,[SerialData] 'send the variable to a terminal to
'view the variable value on screen.

GoTo Loop 'do it forever.



If i press a key, i see the key appear on the screen.

But, while no keys are pressed (and the program is still looping), what value does the variable "SerialData" become?
I expected to see a column of say 0's to run down my screen, or at least the previous value of SerialData, but that doesnt happen.

It doesn't appear to be 0 and think it might be a null (alt-255) or is it just an idle DC level until data arrives?

What i'm trying to acheive is a condition that can tell the difference between 'active data' and 'no data'.

Hope this made sense???
Marty.

mackrackit
- 23rd September 2009, 07:55
In your code the program is not looping. It is sitting there waiting for data. Once data arrives it will move on. Put a LED blinky after the SERIN and you will see what is going on.

Now then, I will suggest you use SERIN2. You have more options and when you end up using hardware serial the syntax is the same.

To see if data is coming in look at the SERIN2 section in the manual. You will find a way to wait for a given amount of time and a given character. If neither is present the code will then continue to the routine of your choosing.

Melanie
- 23rd September 2009, 08:04
Your program is not looping when there is no Data.

It is suspended, sitting at SERIN waiting for valid Data to arrive. If Data never arrives, it will be there until the end of time or until you forget to pay your electricity bill (whichever comes first).

SERIN has the ability to wait suspended like this for a TIMEOUT period, and if no Data arrives within that given period to jump out to a LABEL elsewhere into your program.

Beat me to the answer Dave... bah... too slow... not enough coffee yet this morning...

mackrackit
- 23rd September 2009, 08:13
Beat me to the answer Dave... bah... too slow... not enough coffee yet this morning...
Middle of the night for me and to much Mountain Dew :D

gtvmarty
- 23rd September 2009, 09:08
Thanx Melanie (ladies first) & Dave, i didn't know that the SerIn behaved like that with lack of data.

Ok, i'll go fiddle my code to accomodate that, and see what happens ;-)

Thanx again.

gtvmarty
- 23rd September 2009, 23:07
Hi again,

For a quick test, i tried :



SerIn pin1,T9600,[1000],SerialData


but nothing happens. (assuming a 1000ms timeout).

Am i meant to be adding other code to accomodate the elapsed timeout? or does the SerIn just "let go" after 1000mS, and return back to any previous gosubs/code etc?


Once again, the PBP Manual is "light" with information in most of it's commands, i'd love to see an entire re-write someday. :)

Is there an ADVANCED PBP link/pdf i should be looking at these days???

Regards,
Marty.

aratti
- 23rd September 2009, 23:19
Loop:
SerIn pin1,T9600,500 Jumpout,SerialData 'get serial data from Pin1,
'store it in variable "SerialData"
Jumpout:

SerOut pin2,T9600,[SerialData] 'send the variable to a terminal to
'view the variable value on screen.

GoTo Loop 'do it forever.


The added code in red, wait for 500 ms the data, then jump to label JUMPOUT executing the serout command.

Al.

gtvmarty
- 24th September 2009, 00:31
Thanx AL, i discovered that just moments ago, and got it to work pretty much the same as you've indicated....

Marty