Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

INPUT command

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Scarr

Bascom Member



Joined: 21 Apr 2005
Posts: 85

blank.gif
PostPosted: Wed Oct 15, 2014 10:00 pm    Post subject: INPUT command Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Oct 15, 2014 10:38 pm    Post subject: Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Oct 15, 2014 10:58 pm    Post subject: Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Thu Oct 16, 2014 7:52 am    Post subject: Reply with quote

Code:

dim command as string * 3
 


That's to short defined, increase it to 6

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Oct 16, 2014 3:15 pm    Post subject: Reply with quote

Evert Smile 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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Oct 16, 2014 8:49 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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