Page 1 of 1

Problem with serinp$

Posted: Wed Sep 17, 2014 9:51 am
by umineral
I need a serial input on RX (pin 37) and output to TX (pin 36) just like "INPUT" and "PRINT" works on the USB port 0. I have tried the below code but it just falls thru with out any string or characters being received. The input to serinp$ could come at any time.

command$ = "" ' null command variable
serinit 1,9600,8,1,0 ' Init port
.
.
command$ = serinp$(1,20,13,1) ' Input string with max characters = 20, stop on CR, ?
error = serout(1,command$)
.
.
Now test for valid command. ' It never gets a valid command or any character, just falls thru the serinp$.
end

Is there something wrong with what I'm expecting from the code or how it is being used? I believe that signals are being sent into the hardware pin 36.
Phil

Re: Problem with serinp$

Posted: Wed Sep 17, 2014 10:40 am
by Daniel
Hi

You seem to have an awfully short time set for the 'timeout' parameter. The syntax is <instring>=SERINP$(<port #>,<numchars>,<endchar>,<timeout>) and a value of 50000 for timeout will have the function pause for a second waiting for the character. Try using command$ = serinp$(1,20,13,1000000) and see if you have the desired behavior.

Since you say that the input may come at any time, you would normally use a smaller value for 'timeout' and then the function will return the characters allready in the buffer. You would then need to process the buffer to detect the 'CR'.

Daniel