Determining Serial Ports available on Windows

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
tjm167us
Posts: 49
Joined: Sat Dec 03, 2011 8:27 pm
Location: San Ramon, CA

Determining Serial Ports available on Windows

Post by tjm167us » Tue Jun 27, 2017 6:53 pm

Greetings,
Courtesy of hutchfx (from 6 years ago), I found two methods for determining the available COM ports on a windows machine in livecode: One uses brute force (attempting to open each one and relying on the error you get if it doesn't exist), and the other, queries of the windows registry.

Code: Select all

put queryRegistry("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM") into field "my field"
Querying the registry is definitely the way to go, but I can't for the life of me figure out why it's not working. I can view this path using RegEdit, but when I look at the response of the query, I get nothing!
Could there be some sort of administrative lock-down that would prevent LiveCode from accessing the Windows registry? I tried to run LiveCode as an administrator to test this, but with no luck.

Help, please!
Tom
Last edited by tjm167us on Tue Jun 27, 2017 11:46 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6105
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Determining Serial Ports available on Windows

Post by FourthWorld » Tue Jun 27, 2017 7:22 pm

What is the type of the value? Is it a string?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

tjm167us
Posts: 49
Joined: Sat Dec 03, 2011 8:27 pm
Location: San Ramon, CA

Re: Determining Serial Ports available on Windows

Post by tjm167us » Tue Jun 27, 2017 11:32 pm

Hi Richard,
Nearest I can tell it is a string (although I'm really unfamiliar with this whole windows registry business. The example in the LiveCode docs for the function queryRegistry is:

Code: Select all

put  queryRegistry("HKEY_CLASSES_ROOT\.rev\") into msg
This works as expected putting "RevolutionStack" into msg which is the data from the HKEY_CLASSES_ROOT\.rev\ key.

The data for the serial com ports is also human readable and looks like:
COM4
COM22
etc.

Thanks,
Tom

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6105
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Determining Serial Ports available on Windows

Post by FourthWorld » Wed Jun 28, 2017 1:00 am

What happens if you take off the trailing "\"?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

tjm167us
Posts: 49
Joined: Sat Dec 03, 2011 8:27 pm
Location: San Ramon, CA

Re: Determining Serial Ports available on Windows

Post by tjm167us » Wed Jun 28, 2017 1:34 am

Hi Richard,
If you remove the "\" from the LiveCode example, it stops working. However, adding a "\" after SERIALCOMM doesn't work. In fact, I methodically changed the path in the following ways:
"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\"
"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\"
"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP"
"HKEY_LOCAL_MACHINE\HARDWARE\"
"HKEY_LOCAL_MACHINE\HARDWARE"
"HKEY_LOCAL_MACHINE\"
"HKEY_LOCAL_MACHINE"

Only the very last one in this list responded, and it did with "no key".

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6105
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Determining Serial Ports available on Windows

Post by FourthWorld » Wed Jun 28, 2017 5:44 pm

Testing here, with confirmation from a friend on the email discussion list, this appears to be a bug. I've submitted a report for it - you can add your email address to the CC list to follow progress:
http://quality.livecode.com/show_bug.cgi?id=19970
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6105
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Determining Serial Ports available on Windows

Post by FourthWorld » Wed Jun 28, 2017 6:40 pm

One of the email list members, Mike Bonner, offered this workaround for now:
One can use the shell to do this.. *get* shell("reg query
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\KeyboardClass")

I used KeyboardClass because SERIALCOMM doesn't exist for me. (windows 10)
but at least when i tried it I got back a helpful message telling me that
it doesn't exist.
http://lists.runrev.com/pipermail/use-l ... 38652.html
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

tjm167us
Posts: 49
Joined: Sat Dec 03, 2011 8:27 pm
Location: San Ramon, CA

Re: Determining Serial Ports available on Windows

Post by tjm167us » Wed Jun 28, 2017 8:39 pm

Richard and Mike,
Thanks a lot for taking the time to look into this - The solution works great. Below is the final implementation to extract the data portion of the registry:

Code: Select all

   
    //This is a workaround for using the queryRegistry command (bug was reported)
   //Must be VERY careful doing this as different versions of windows have a different location for the serial comm ports.
   put shell("reg query HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM") into tempVar
   
   repeat for each line tLine in tempVar
      if the number of words in tLine>1 then
         put the last word of tLine & return after theAnswer
      end if
   end repeat
   put theAnswer into msg
For the benefit of others that aren't familiar with the "reg query" command in windows, I have attached the usage of it to this post. You can get this information yourself by typing the following into the command prompt:

Code: Select all

reg query /?
Attachments
Reg Query grab.jpg

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2690
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Determining Serial Ports available on Windows

Post by mwieder » Wed Jun 28, 2017 8:51 pm

I just checked this on a real Windows system (not a vm) and I also don't have a SERIALCOMM sub-key.

It's been a while since I've had to work with a M$ system, but my recollection is that the queryRegistry() function needs a parameter that is an exact path to a key endpoint, i.e., you can't just say "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", you'd also need either a trailing "\" to return the default value for that key or a trailing "\Com1" or similar to get down to where there aren't any more subkeys.

The listRegistry() function should tell you whether or not there are subkeys.

Post Reply

Return to “Talking LiveCode”