goodmanjl531 Posted February 14, 2014 Share Posted February 14, 2014 I was trying to find a way to find out via AutoIt what comm port a device was plugged into. I am using a Silicon Labs CP210x USB to UART Bridge. This has to be done behind the scenes so i can automatically setup the correct comm port for my communications software. Thanks in advance Link to comment Share on other sites More sharing options...
JohnOne Posted February 14, 2014 Share Posted February 14, 2014 There is a serial comm UDF in example scripts. Not saying it will help, I've never used it, but it's a good place to start. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Solution orbs Posted February 14, 2014 Solution Share Posted February 14, 2014 alternative, using WMI: code adapted from: http://artisgeek.com/weblog/scripts/-getdevices-autoit/ expandcollapse popup#include <Array.au3> $aDeviceList=_getDevices('Silicon Labs CP210x USB to UART Bridge',1) _ArrayDisplay($aDeviceList) ;Function Name: Get (Connected) Devices ;Written By: Amin Babaeipanah ;Usage: _getDevices(1,'') ;_getDevices("search for", flag) ;"search for": can be set to empty to list everything ;flag: ; 1 = List Device Name(s) ; 2 = List Device ID(s) ; 3 = List Device Name(s) @ Device ID(s) ;Example 1: ; Code below will list all the connected devices by name ; _getDevices('',1) ; Code below will list all the connected devices by ID ; _getDevices('',2) ; Code below will list all the connected devices by name that has the word "COM" ; _getDevices('COM',1) ; adaptation: replace ConsoleWrite with array return ; adaptation by: orbs ; original source at: http://artisgeek.com/weblog/scripts/-getdevices-autoit/ Func _getDevices($name,$type) Dim $aDeviceList[1]=[0] Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2') Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%"&$name&"%'", "WQL", 48) If IsObj($colItems) Then If $type = 1 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.Name ;ConsoleWrite($objItem.Name&@LF) Next ElseIf $type = 2 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.PNPDeviceID ;ConsoleWrite($objItem.PNPDeviceID&@LF) Next ElseIf $type = 3 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.Name&'@'&$objItem.PNPDeviceID ;ConsoleWrite($objItem.Name&'@'&$objItem.PNPDeviceID&@LF) Next EndIf EndIf Return $aDeviceList EndFunc the function returns an array of all devices by criteria (name or type). calling he function with your device name will return (hopefully) only one result, then use string manipulation - like _StringBetween() - to parse the port. goodmanjl531 and bobmcrae 2 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
goodmanjl531 Posted February 14, 2014 Author Share Posted February 14, 2014 Thanks, That did the trick!!! Link to comment Share on other sites More sharing options...
KF5WGB Posted December 23, 2018 Share Posted December 23, 2018 (edited) On 2/14/2014 at 2:28 PM, goodmanjl531 said: Thanks, That did the trick!!! Hi goodmanjl531, I recently bought an ICOM 7300 (Amateur radio Transceiver) which uses the Silicon Labs CP210x USB to UART Bridge. Finding the COM port with ORBS function works great. Now I have a question. How do you send date to the port? I used Martin's CommMG.au3 UDF for Yaesu radios with RS-232 ports without problems but it looks like it does not wort with the UART Bridge. Code so far for testing is: #include <CommMG.au3> #include <MsgBoxConstants.au3> Global $CMPort = 6 Global $CmBoBaud = 115200 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop =1 Global $setflow = 1 Global $freq, $TXon _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then MsgBox(16,"Error!","Can't connect to ICOM 7300 on port - "&$CMPort) Exit EndIf _CommSetRTS(1) _CommSetDTR(1) $sfreq = _CommSendString("FEFE94E003FD") ;Read frequency $TXon = _CommSendString("FEFE94E01C0001FD") ;TX on MsgBox(64,"IC-7300 sending..", "Transmit on: " & $TXon & @crlf & "Frequency: " & $sfreq) #cs here goes some stuff to send data over the air #ce $TXon = _CommSendString("FEFE94E01C0000FD") ; TX off I tried this but without success. Is there another UDF for sending DATA to the UART Bridge? Thanks for any help. KF5WGB Edited December 23, 2018 by KF5WGB Typo Link to comment Share on other sites More sharing options...
jchd Posted December 23, 2018 Share Posted December 23, 2018 Looking at bottom of page 19-7 of the ICOM-7300 manual I read that you must transmit a given number of 0xFE bytes depending on the baudrate: e.g. 150 0xFE bytes for 115kBd. I can't tell if that applies to your setup. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Nine Posted December 23, 2018 Share Posted December 23, 2018 @KF5WGB - you resurrected a post of almost 5 years old. I don't think OP is still there to respond to your reply. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
KF5WGB Posted December 23, 2018 Share Posted December 23, 2018 3 hours ago, Nine said: @KF5WGB - you resurrected a post of almost 5 years old. I don't think OP is still there to respond to your reply. Yep, I know. Thought I shoot for it anyway. Link to comment Share on other sites More sharing options...
KF5WGB Posted December 23, 2018 Share Posted December 23, 2018 (edited) 11 hours ago, jchd said: Looking at bottom of page 19-7 of the ICOM-7300 manual I read that you must transmit a given number of 0xFE bytes depending on the baudrate: e.g. 150 0xFE bytes for 115kBd. I can't tell if that applies to your setup. Thanks for the hint. I added _StringRepeat to the code to get 150 FE's but I think this is only needed if you want to remotely power on the radio. Added it anyway for testing. expandcollapse popup#include <CommMG.au3> #include <MsgBoxConstants.au3> #include <String.au3> Global $CMPort = 6 Global $CmBoBaud = 115200 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 2 Global $setflow = 2 Global $FE, $sfreq _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then MsgBox(16,"Error!","Can't connect to ICOM 7300 on port - "&$CMPort & @CRLF & @error) Exit EndIf _CommSetRTS(1) _CommSetDTR(1) $FE = _StringRepeat("FE",150) ;add 150 FE's _CommSendString($FE & "FEFE94E01801FD",1) ;power on _CommSendString("FEFE94E003FD") ;Read frequency $sfreq = _CommGetstring() ;Read buffer _CommSendString("FEFE94E01C0001FD") ;TX on MsgBox(64,"IC-7300 sending..", "Frequency: " & $sfreq) #cs here goes some stuff to send data over the air #ce _CommSendString("FEFE94E01C0001FD") ;TX off Adding 150 FE's does not send the command to the radio. Maybe commMG.au3 does not work with USB/UART Edited December 24, 2018 by KF5WGB Modified code Link to comment Share on other sites More sharing options...
jchd Posted December 24, 2018 Share Posted December 24, 2018 As I said I don't know what is required in your specific setup. The UDF should work fine with all USB-RS232 adapters. Can't you just use a direct USB link with the vendor's driver? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
KF5WGB Posted December 24, 2018 Share Posted December 24, 2018 6 hours ago, jchd said: ~~ The UDF should work fine with all USB-RS232 adapters. ~~ jchd, It is not a USB-RS232 adapter. Its on board the IC-7300 radio. I tried all settings for port speed, parity etc. Oh well it is one of the things that do not work. Thanks for your help anyway. It just boggles my mind that all other radios with 'real' serial adapters work just fine using CommMG.au3. I have to find a USB port sniffer and see what comes back from the radio or bite the bullet and find some info about native windooze DLL calls for USB port prigramming. If I ever find out what causes the problem, I let you know. Thanks again and Merry Christmas and a Happy New Year Link to comment Share on other sites More sharing options...
KF5WGB Posted December 26, 2018 Share Posted December 26, 2018 @jchd, Found the problem. The ICOM 7300 requires DATA send in binary instead of ASCII. Well, ICOM does not mention that once in the manual. Searching the forum pointed me to this post: rover had the answer. I changed the code and tadaaaa. expandcollapse popup#include <CommMG.au3> #include <MsgBoxConstants.au3> #include <String.au3> Global $CMPort = 10 Global $CmBoBaud = 115200 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 2 Global $setflow = 2 Global $FE, $sfreq, $errormsg _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then ; @error meaning error with ; 1 dll call failed ; 2 dll was not open and could not be opened ; -1 $iBaud ; -2 $iStop ; -4 $iBits ; -8 $iPort = 0 not allowed ; -16 $iPort not found ; -32 $iPort access denied (in use?) ; -64 unknown error If @error = -32 Then $errormsg = "Error: Access denied (Port in use?)" elseif @error = -16 then $errormsg = "Error: Port not found" EndIf MsgBox(16,"Error!","Can't connect to ICOM 7300 on port: "&$CMPort & @CRLF & $errormsg) Exit EndIf _CommSetRTS(1) _CommSetDTR(1) _CommClearOutputBuffer() _CommClearInputBuffer() MsgBox(64,"IC-7300", "Click OK ") ; pause to get VSPE displaying traffic _PowerOn() ; Turn Radio on _ReadFreq() ; Requesting Frequency setting _sendData() ; Sending DATA over air _PowerOff() _CommClearOutputBuffer() _CommClearInputBuffer() _Commcloseport() Exit ; End program Func _ReadFreq() $bBinData = Binary("0xFEFE94E003FD") ; code to request frequency $iNumbytes = BinaryLen($bBinData) $tBinData = DllStructCreate("byte["&$iNumbytes&"]") DllStructSetData($tBinData, 1, $bBinData) $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1) If @error Or $iRet = -1 Then ConsoleWrite("!Error: " & @error & @CRLF) ;here goes the code to read input buffer and change to ascii ;using BinaryToString, I guess ;$sfreq var holds frequency EndFunc Func _SendData() ; MsgBox(64,"IC-7300", "Data will be sent" & @CRLF & "using Frequency: " & $sfreq,10) ;display Frequency ; ;and send data over the air ; EndFunc Func _PowerOn() ; Turn Radio on - works MsgBox(0,"IC-7300","Click OK to turn" & @CRLF & "on the Transceiver") $bBinData = "" $bBinData = $bBinData & "0x" & _StringRepeat("FE",150) &"FEFE94E01801FD" $bBinData = Binary($bBinData) $iNumbytes = BinaryLen($bBinData) $tBinData = DllStructCreate("byte["&$iNumbytes&"]") DllStructSetData($tBinData, 1, $bBinData) $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1) If @error Or $iRet = -1 Then ConsoleWrite("!Error: " & @error & @CRLF) EndFunc Func _PowerOff() ; Turn Radio off - works MsgBox(0,"IC-7300","Click OK to turn" & @CRLF & "off the Transceiver") $bBinData = "" $bBinData = $bBinData & "0x" & _StringRepeat("FE",150) &"FEFE94E01800FD" $bBinData = Binary($bBinData) $iNumbytes = BinaryLen($bBinData) $tBinData = DllStructCreate("byte["&$iNumbytes&"]") DllStructSetData($tBinData, 1, $bBinData) $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1) If @error Or $iRet = -1 Then ConsoleWrite("!Error: " & @error & @CRLF) EndFunc Now I just have to figure out how to read the data coming back from the radio and convert to ASCII. Just thought you might be interested. Have a great week. KF5WGB Link to comment Share on other sites More sharing options...
jchd Posted December 26, 2018 Share Posted December 26, 2018 Good to know, but I'm not a radio-amateur at all. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
KF5WGB Posted December 26, 2018 Share Posted December 26, 2018 That's ok jchd, nobody is perfect,lol. Just kidding. Maybe you look into becoming a HAM op someday. Your post back up there mentioning the 150 0xFE got me on the right track. Anyway, it really does not matter what device is using the 210x UART Bridge, key is... how to talk to it and how to read the data coming back to the app. Thanks again and Happy New Year KF5WGB Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now