Population of a PullDownMenu with USB Port Names

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Redlance305
Posts: 30
Joined: Sun Feb 28, 2010 9:52 pm
Location: Miami, Florida
Contact:

Population of a PullDownMenu with USB Port Names

Post by Redlance305 » Mon Mar 01, 2010 3:29 pm

After two hours of googlin' and searching the runrev sites, I've been unable to find an example of how to populate a pull down menu with available USB/Serial Ports. How do we get a hardware list of ports to populate such a list? (Mostly for the Mac)

Hard coded list:

/dev/cu.usbserial-A9006LdD
/dev/cu.Bluetooth-PDA-Sync
/dev/cu.ARDUINOBT-BluetoothSeri-1
-
/dev/cu.modem

However I need one with devices currently plugged in.

Thanks
~David

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Population of a PullDownMenu with USB Port Names

Post by bn » Mon Mar 01, 2010 4:11 pm

David,
does this help?
http://n4.nabble.com/list-of-USB-driver ... ml#a332688
especially
http://pdslabs.net/stacks/libUsbDrive.rev.zip
by Phil Davis
I don't know anything about USB.
regards
Bernd

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: Population of a PullDownMenu with USB Port Names

Post by NoN' » Wed Mar 03, 2010 6:01 pm

Hello David,

On Mac you can use with advantage the BSD commands.

Under Revo, these commands are accessible via the function : shell ()
Here is a script which allows to get back the list of the active ports such as it appears in " informations system ".

The ideal being to launch the script at the opening of the stack.

Code: Select all

on openstack
  set cursor to busy
  put "put return & shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPIDEDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPSCSIDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPUSBDataType" & quote & ") after resum" & quote into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPFireWireDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPAirPortDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPModemDataType" & quote & ") after resum" into lacomm
  do lacomm
  sort resum
  repeat with i = the number of lines in resum down to 1
    if char 1 of line i of resum is not " " then next repeat
    if char 1 to 5 of line i of resum = "     " then
      exit repeat
    else
      if "Hardware" is in line i of resum then
        next repeat
      end if
      if "modem" is in line i of resum then
        put word 1 of line i of resum after portList
        put return after last char of portList
        next repeat
      end if
      delete char 1 to 4 of line i of resum
      put line i of resum after portList
      put return into last char of portList
    end if
  end repeat
  delete last char of portList
  put "Choose a port" & return & "-" & return & portList into btn "ThePorts"
end openstack
[/size]

The last part of this code just extract the type of the existing ports and bring it to a button with pull down menu. But a lot of other informations are accessible via the "system_profiler" command. By exemple, with the "SPUSBDataType" argument :

USB Bus:

Vendor Name: Apple Computer, Inc.
Product ID: 32773 ($8005)
Speed: Up to 12 Mb/sec
Bus Power (mA): 500

U3 Smart Drive:

Capacity: 974.5 MB
Drive Type: CD-ROM
Removable Media: Yes
Detachable Drive: Yes
BSD Name: disk3
OS9 Drivers: No
Product ID: 7760 ($1e50)
Speed: Up to 12 Mb/sec
Vendor Name: EMTEC
Bus Power (mA): 500
Serial Number: 070007771FB00018


With the hope it will help you.

regards,

renaud

vascoribeiro
Posts: 33
Joined: Tue Apr 25, 2017 8:13 pm

Re: Population of a PullDownMenu with USB Port Names

Post by vascoribeiro » Mon Aug 14, 2017 7:52 pm

Hi!

Reviving this thread :P
I'm having trouble trying to figure out how to make this pull down menu not with the USB port names but with the "BSD Device Name". This way it would be easier to select the right port to connect with an arduino for example.
Any suggestions?
Thanks!
NoN' wrote:Hello David,

On Mac you can use with advantage the BSD commands.

Under Revo, these commands are accessible via the function : shell ()
Here is a script which allows to get back the list of the active ports such as it appears in " informations system ".

The ideal being to launch the script at the opening of the stack.

Code: Select all

on openstack
  set cursor to busy
  put "put return & shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPIDEDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPSCSIDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPUSBDataType" & quote & ") after resum" & quote into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPFireWireDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPAirPortDataType" & quote & ") after resum" into lacomm
  do lacomm
  put "put return & shell (" & quote & "system_profiler SPModemDataType" & quote & ") after resum" into lacomm
  do lacomm
  sort resum
  repeat with i = the number of lines in resum down to 1
    if char 1 of line i of resum is not " " then next repeat
    if char 1 to 5 of line i of resum = "     " then
      exit repeat
    else
      if "Hardware" is in line i of resum then
        next repeat
      end if
      if "modem" is in line i of resum then
        put word 1 of line i of resum after portList
        put return after last char of portList
        next repeat
      end if
      delete char 1 to 4 of line i of resum
      put line i of resum after portList
      put return into last char of portList
    end if
  end repeat
  delete last char of portList
  put "Choose a port" & return & "-" & return & portList into btn "ThePorts"
end openstack
[/size]

The last part of this code just extract the type of the existing ports and bring it to a button with pull down menu. But a lot of other informations are accessible via the "system_profiler" command. By exemple, with the "SPUSBDataType" argument :

USB Bus:

Vendor Name: Apple Computer, Inc.
Product ID: 32773 ($8005)
Speed: Up to 12 Mb/sec
Bus Power (mA): 500

U3 Smart Drive:

Capacity: 974.5 MB
Drive Type: CD-ROM
Removable Media: Yes
Detachable Drive: Yes
BSD Name: disk3
OS9 Drivers: No
Product ID: 7760 ($1e50)
Speed: Up to 12 Mb/sec
Vendor Name: EMTEC
Bus Power (mA): 500
Serial Number: 070007771FB00018


With the hope it will help you.

regards,

renaud

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: Population of a PullDownMenu with USB Port Names

Post by NoN' » Mon Aug 14, 2017 11:53 pm

Hi Vasco,

After seven years of reflection, I can tell you that the solution was already in my precedent post... :wink:

Try that :

Code: Select all

on mouseUp

   set cursor to busy
   
   put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum"  into lacomm
   do lacomm
   
  set itemdelimiter to ":"
   
   repeat with i = 1 to the number of lines in resum
      if line i of resum contains "BSD name" then
         put last item of line i of resum & return after ron2
      end if
   end repeat
   delete last char of ron2
   
  put "Choose a port" & return & "-" & return & ron2 into btn "ThePorts"
end mouseup
Hope it will help

regards,

renaud

vascoribeiro
Posts: 33
Joined: Tue Apr 25, 2017 8:13 pm

Re: Population of a PullDownMenu with USB Port Names

Post by vascoribeiro » Tue Aug 15, 2017 12:31 am

It really was but I'm quite dumb, I'm sorry... And thank you for your help!

In fact, I'm not a programmer and I still have some doubts of how this code works, but I do know enough to "tinker" pieces of code. For example what you gave me didn't work at first, but I was ready for this possibility. It works if I do this changes:

Code: Select all

 put "put shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") into resum"  into lacomm
   do lacomm
and

Code: Select all

  if line i of resum contains "BSD Device Name" then
         put last item of line i of resum & return after ron2
      end if
:D
It shows a little more stuff than I wanted but the name is there, so I have now a way to work it out.

Thank you so much! :wink:

NoN' wrote:Hi Vasco,

After seven years of reflection, I can tell you that the solution was already in my precedent post... :wink:

Try that :

Code: Select all

on mouseUp

   set cursor to busy
   
   put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum"  into lacomm
   do lacomm
   
  set itemdelimiter to ":"
   
   repeat with i = 1 to the number of lines in resum
      if line i of resum contains "BSD name" then
         put last item of line i of resum & return after ron2
      end if
   end repeat
   delete last char of ron2
   
  put "Choose a port" & return & "-" & return & ron2 into btn "ThePorts"
end mouseup
Hope it will help

regards,

renaud

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: Population of a PullDownMenu with USB Port Names

Post by NoN' » Tue Aug 15, 2017 2:36 am

Don't be sorry and bravo, it's a beautiful transformation for a "non programmer"!

Have a good day.

renaud

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Population of a PullDownMenu with USB Port Names

Post by Klaus » Tue Aug 15, 2017 2:46 pm

Hi friends,

why not just:

Code: Select all

...
## put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum"  into lacomm
## do lacomm
put shell ("system_profiler SPUSBDataType") into resum
...
? :D


Best

Klaus

vascoribeiro
Posts: 33
Joined: Tue Apr 25, 2017 8:13 pm

Re: Population of a PullDownMenu with USB Port Names

Post by vascoribeiro » Tue Aug 15, 2017 5:54 pm

NoN' wrote:Don't be sorry and bravo, it's a beautiful transformation for a "non programmer"!

Have a good day.

renaud
Thank you Renaud! ;) Using your code I got to another way of doing what I wanted again, I think it is a simpler way, so I'll leave here... It can be useful for other noobs like me! :lol:

Code: Select all

set cursor to busy
put shell ("ls /dev/cu.*") into resum
put "Choose a port" & return & "-" & return & resum into btn "ThePorts"
Best regards,
Vasco

EDIT
Klaus wrote:Hi friends,

why not just:

Code: Select all

...
## put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum"  into lacomm
## do lacomm
put shell ("system_profiler SPUSBDataType") into resum
...
? :D


Best

Klaus
Thank you Klaus, I think my tinker spirit got me to a similar conclusion. :P

Best regards,
Vasco

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: Population of a PullDownMenu with USB Port Names

Post by NoN' » Tue Aug 15, 2017 9:09 pm

Hi Klaus,

Because of the beauty of course :D

No, you are absolutly right I don't remember the reason why I used this structure in my initial post seven years ago, but there is no reason here.

Thank you for this simplification.

Best

Renaud

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”