View previous topic :: View next topic |
Author |
Message |
Scarr
Joined: 21 Apr 2005 Posts: 85
|
Posted: Wed Oct 15, 2014 10:00 pm Post subject: INPUT command |
|
|
Well I didn't think I would be asking this but I have now spent ages trying to sort this.
here is the code
Code: |
dim command as string * 3
OPEN "com1:" for binary as #1
do
input #1,command
select case command
case "AAA":
call flashled1(100)
case "BBB"
call flashled1(100)
waitms 200
call flashled1(100)
waitms 200
end select
loop
|
This works first time I enter AAA or BBB then no matter what I put in it does not work
I have tried extending string size, this did not even flash at all!
I have tried taking first 3 chars into another string using LEFT
I have tried using just INPUT without open and the channel numbe
Please help it's driving me MAD!
Steve
P.S. no watchdogs or interrupts running
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2289
|
Posted: Wed Oct 15, 2014 10:38 pm Post subject: |
|
|
Likely your terminal program sends CR/LF, while Bascom's Input is configured by default to end input by a CR. Thus the LF isn't "eaten up" and is left in your string, thus following compares will fail.
Use Config Input to set the Input function accordingly your terminal program, or change the terminal program's behavior. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Oct 15, 2014 10:58 pm Post subject: |
|
|
Hello Scarr
Using Input to get commands from a serial line eg like a command line on a terminal, is not the best way to do it.
If you are trying to use a PC or like device to control the AVR have a look at the Blog section and my web servers they have a command line interface working on them they are modular so you can take just the file that is the command line and use it.
Also I have written a program for a clock that watches for a particular byte in the data then decodes the time from that data using Bytematch you can see the code here http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9950&highlight=bytematch
Note it also good to let people know what you are trying to acheive with your code then they can send you in the right direction.
Regards Paul |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2159
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2289
|
Posted: Thu Oct 16, 2014 3:15 pm Post subject: |
|
|
Evert wrote: | Code: |
dim command as string * 3
|
That's to short defined, increase it to 6 |
If things work correctly, means same input terminators for transmitting and receiving end, a string dimensioned for 3 chars is enough for an input of 3 chars plus terminators CR/LF, as the CR/LF doesn't make it into the string.
If things go wrong, like in this case, looping the second time, the first char of the string is a LF, which is left in the UART, followed by two input chars, like "AA".
The following compare fails, but nothing more happens, the Input command does not take more chars, than the string can hold.
In contrary, if the string would hold 6 chars, and terminators are mismatching, the string content would look like: "<LF>AAA"
A compare for "AAA" would still fail, so nothing is gained.
That's why I disagree, the string isn't defined too short, it is just right with 3 chars length. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 1038
|
Posted: Thu Oct 16, 2014 8:49 pm Post subject: |
|
|
I use this code to control one of my devices. Three digit string are send from PC programm but then Always vbCr command are send with that string, because Input can froze Your program without it. If I use Terminal and type a one char for example then AVR hold and wait for Enter.. so if any trash step behind "Ifchariswaiting" then better somme times send empty CR command.
Code: | Dim Y As String * 3
If Ischarwaiting() = 1 Then
Input Y
Z = Val(y)
Select Case Z
Case 0 To 255
X = Z
Case 300
Tryb = 0
Status = Chlodzenie_start
X = 0
Old_odczyt = 0
Case 301
Tryb = 1
Status = Tryb_reczny
Case 600 To 700
Hist = Z - 600
Writeeeprom Hist , 4
Case 800 To 900
Pilnuj = Z - 800
Old_odczyt = 0
Writeeeprom Pilnuj , 2
Case 900
Set Aux1
Set Aux2
Case 901
Reset Aux1
Set Aux2
Case 910
Set Aux1
Reset Aux2
Case 911
Reset Aux1
Reset Aux2
Case 999
Start Watchdog 'this for Bootloader
End Select
End If
|
This solution is my first and I don`t use it anymore. |
|
Back to top |
|
|
|