• Support
  • Articles
  • Resources
  • Products

Connects to a COM port with both connection and link

Moderator: boris

1 postPage 1 of 1

JamesL
Newbie

Posts:
16
Joined: Wed Aug 31, 2016 7:20 pm
by JamesL » Wed Aug 31, 2016 7:27 pm
It starts by trying COM port 6, COM7, COM8....all the way until COM port 20. The first one it gets both a valid connection and link is the one it connects to.

Code: Select all

  1.  
  2. USB_COM=0
  3.  
  4. ; Search for USB COM port; assumes port number will be greater than 5
  5. for i 6 20
  6.     ; Disconnect between Tera Term and host (COM channel)
  7.     disconnect
  8.     ; Wait for Full Disconnection
  9.     do
  10.         mpause 10
  11.         testlink
  12.     loop while result = 2
  13.     sprintf2 port '/C=%d' i
  14.     do
  15.         connect port
  16.         mpause 10
  17.         testlink
  18.     loop while !result
  19.     gethostname hostName
  20.     if result=2 then
  21.         USB_COM=i
  22.         break
  23.     endif    
  24.     ; Uncomment below for debugging
  25.     sprintf2 itr '%s link: %d' hostName result
  26.     messagebox itr 'Count'
  27. next
  28. setbaud 115200
  29. if USB_COM then
  30.     sprintf2 msg 'USB port is %s' hostName
  31.     messagebox msg 'USB port'
  32. else
  33.     messagebox "Couldn't find USB serial COM port!" 'USB port'
  34. endif
  35.  

1 postPage 1 of 1

Users browsing this forum: No registered users
cron