TheByteWorks

    Quality ready made and affordable custom software

Home
What's new here

Software

PHP Serial
rsterm
Easy Control
Rack Designer
EzCom2Web

Quick Texts
Wallpaper Slideshow

Articles

All articles
WS2300 weather station PHP project
Your own terminal in 17 lines
PC PIC Voltmeter
Network messenger in 22 lines
Phone Dialer

Download
Purchase

Support

Details
E-mail

Copyright 2001-2016
© Cosmin Buhu

  Detecting device

Detecting device

How to detect on which PC serial port your device is alive.

Easy Control code that will do the job (for version 1.4):

#ports variable will contain all my ports names, as a string
ports=enumports ()
#how many ports to check
maxports=4
#my device is setup to respond at this query (yes, it's a modem)
query="atz"&chr(13)&chr(10)
#will respond with this
response="OK"&chr(13)&chr(10)
#check all ports
for (i,1,maxports,1)
#myport will be com1,then com2, com3, com4...
myport="com"&i
#check if actual myport is known to Windows and available, so enumports reported it
poz=pos (myport,ports)
if (poz <> 0)
#if it is, then open it and send query
openport (myport,9600,8,n,1)
#if I want to see data:
#showterm (myport)
send (myport,query)
#setup a reasonable timeout, 1 second
settimer (1000)
#and wait for interval to finish
repeat
tim=gettimer ()
until (tim==0)
#copy data received (if any) in received variable
received=receive (myport)
#and check if it contains my response
posofres=pos (response,received)
if (posofres==0)
#this doesn't
goto notfound
endif
#this does
#close actual port
closeport (myport)
#I found it
goto found
notfound:
#so on this port is not my device, close it
closeport (myport)
endif
#and go next, or finish
myport="none"
next
found:
writelog ("Device is on port : "&myport)

Enjoy !