• Support
  • Articles
  • Resources
  • Products

How can i store value from tera term screen to any variable?

Moderator: boris

4 postsPage 1 of 1

mayank867
Newbie

Posts:
5
Joined: Thu Apr 06, 2017 1:23 pm
by mayank867 » Mon Apr 10, 2017 10:20 am
I am using Tera term to device communication if I fire command 'switch ok_p' then device sends me a value 10 how can I store this value in any variable so I can use this value runtime in macro.
Trevor
Guru

Posts:
476
Joined: Wed Jul 26, 2006 8:47 am
by Trevor » Mon Apr 10, 2017 1:13 pm
Is the response line based? I.e. is there an end of line (carriage retrun and/or line feed character) and the end/beginning of the response?

If so then here is an example (not tested) using recvln

Code: Select all

  1. timeout = 5
  2. sendln "switch ok_p"
  3. recvln ; may need two of these (one to consume the command echo if present)
  4. if result = 1 then
  5.     ;convert to integer
  6.     str2int number inputstr
  7.     if result == 1 then
  8.         ; display the integer
  9.         sprintf2 str "response as number = %d" number
  10.         messagebox str "switch ok_p"
  11.     else
  12.         ; deal with an unexpected non-numeric response
  13.         messagebox inputstr "Error, response ="
  14.     endif
  15. else
  16.     ; deal with timeout
  17.     messagebox "timeout waiting for response" "Error"
  18. endif



And here is an example (not tested) using waitregex which would be my preference as it's very flexible and will just ignore things like command echo.

Code: Select all

  1. timeout = 5
  2. sendln "switch ok_p"
  3. waitregex "(%d+)$"
  4. if result = 1 then
  5.     ;convert to integer
  6.     str2int number groupmatchstr1
  7.    
  8.     ; display the integer
  9.     sprintf2 str "response as number = %d" number
  10.     messagebox str "switch ok_p"
  11. else
  12.     ; deal with timeout
  13.     messagebox "timeout waiting for expected response" "Error"
  14. endif
Last edited by Trevor on Wed Apr 12, 2017 8:02 am, edited 1 time in total.
Trevor
Guru

Posts:
476
Joined: Wed Jul 26, 2006 8:47 am
by Trevor » Mon Apr 10, 2017 1:17 pm
Hi,
This seems to be the same question as asked in http://logmett.com/forum-index/3/is-there-any-command-in-tera-term-like-scanf-in-c-2988?p=9233#p9233. It would have been better to post this question there when I asked for an example of what you are trying to send/receive rather than starting a new post. In this question you are providing the example I asked for.
Lagman
Newbie

Posts:
1
Joined: Wed Apr 19, 2017 5:51 am
by Lagman » Sat Apr 22, 2017 9:14 am
Thanks for pointing that out! I didn't know about that thread.
Display posts from previous:
Sort by:

4 postsPage 1 of 1

Users browsing this forum: No registered users
cron