mario52 Posted June 2, 2011 Posted June 2, 2011 Hell all, I need your help for something that is stucking me since some days (since I have no clue how to handle this) I am using a the dial code from Dale and customized by a member to get an answer from the modem when command is sent. In this case, the expected answer is "OK". $Time2Wait = 5000 dim $FromModem = "" $ModemString = "ATH" & ";" & @CR $com = ObjCreate ("NETCommOCX.NETComm") With $com .CommPort = 9 .PortOpen = True .Settings = "9600,N,8,1" .InBufferCount = 0 .Output = $ModemString EndWith $StopWatch = TimerInit() While 1 If $com.InBufferCount Then $FromModem = $FromModem & $com.InputData If StringInStr($FromModem, "OK") Then MsgBox (0,"","OK") ExitLoop EndIf EndIf If (TimerDiff($StopWatch) > $Time2Wait) Then ExitLoop EndIf WEnd 1st - Problem is that I don't receive OK from the modem. 2nd problem is that the port comm is always changing after rebooting or unplugging the phone. I would like to know is a charitable soul could help me to find the right serial port the phone is connected to. The phone is a Sony or a Samsung. My wish would be to plug the phone launch the script so that it scans the serial port for the right one and then lauch my phone command. Thank you all for reading and helping me out.
AUTTRY Posted July 16, 2012 Posted July 16, 2012 I also want to know how to scan for the right serial port and generally there is a serial port always exiting for modem.
AUTTRY Posted July 16, 2012 Posted July 16, 2012 I just found a way using WMI (for USB devices). Refer: How Can I Determine Which USB Devices are Connected to a Computer?Getting the USB Devices Information using WMI
NiVZ Posted July 30, 2012 Posted July 30, 2012 I wrote this a while ago for getting the COM port for a Diabetic Meter connected via USB serial cable expandcollapse popupOpt("TrayMenuMode", 1) $DEBUG = FALSE $ERROR_COM_PORT_NOT_FOUND = -1 $Port = _FindCOM("Prolific USB-to-Serial Comm Port", "USB") If $Port = $ERROR_COM_PORT_NOT_FOUND Then MsgBox(16, "COM Port Finder", "No Data Cable Detected") Else MsgBox(64, "COM Port Finder", "Data Cable Found on Port " & $Port) EndIf #cs ############################################################################################################## # Function: _FindCOM($inDeviceName, $inClassKey) # # $inDeviceName - is the registry 'FriendlyName' of the device you want to find # $inClassKey - is the Bass class under HKLMSystemEnum where you want to search, eg USB, UMPPORT # # Function searches through all the device GUID's looking for a match and then compares the 'PortName' from # 'Device Parameters' with the open COM ports in HKLMSystemHardwareSerialCOMM # # Function returns the COM port name if an active COM port is found for the device, eg 'COM1' # or -1 if an active COM port is NOT found # ############################################################################################################## #ce Func _FindCOM($inDeviceName, $inClassKey) If $DEBUG Then ConsoleWrite("*** Getting COM Port for: " & $inDeviceName & @CRLF) Local $i = 1 $ClassKey = "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetEnum" & $inClassKey ; DEVICE LOOP - Loop through all DEVICE GUID's While 1 ; Get the Device GUID for this loop $DeviceKey = RegEnumKey($ClassKey, $i) If @error Then ExitLoop Local $j = 1 ; INSTANCE LOOP - Loop through all instances of the device (if it has been connected to different ports) While 1 ; Get the Device Instance for this loop $InstanceKey = RegEnumKey($ClassKey & "" & $DeviceKey, $j) If @error Then ExitLoop ; Read the friendly name $FriendlyName = RegRead($ClassKey & "" & $DeviceKey & "" & $InstanceKey, "FriendlyName") If @error Then ExitLoop ; The registry FriendlyName has the COM Port in brackets so need to remove this before trying the match If StringLeft($FriendlyName, StringInStr($FriendlyName, " (COM")-1) = $inDeviceName Then ; We have a match so get the COM port for this instance $COMtoCheck = RegRead($ClassKey & "" & $DeviceKey & "" & $InstanceKey & "Device Parameters", "PortName") If $DEBUG Then ConsoleWrite(@TAB & "Device Found at: " & $ClassKey & "" & $DeviceKey & "" & $InstanceKey & " using port " & $COMtoCheck & @CRLF) ; Check if this is an Active COM Port Local $k = 1 ; COM PORT LOOP - Loop through all the open COM ports While 1 ; Get the Active COM port for this loop $ActiveCOMPort = RegRead("HKEY_LOCAL_MACHINEHARDWAREDEVICEMAPSERIALCOMM", RegEnumVal("HKEY_LOCAL_MACHINEHARDWAREDEVICEMAPSERIALCOMM", $k)) If @Error then ExitLoop If $ActiveComPort = $COMtoCheck Then ; If the Active COM port for this loop equals our Device COM port then we have found the correct port $Active = True ExitLoop Else ; Otherwise keep checking the other Active COM ports $Active = False EndIf $k += 1 WEND If $Active Then ; If we set active variable to true then return the COM port If $DEBUG Then ConsoleWrite(@TAB & "Port " & $COMtoCheck & " is ACTIVE" & @CRLF) If $DEBUG Then ConsoleWrite("*** RETURN: " & $COMtoCheck & @CRLF) Return $COMtoCheck Else ; The COM port on this instance is not active If $DEBUG Then ConsoleWrite(@TAB & "Port " & $COMtoCheck & " is NOT ACTIVE" & @CRLF) EndIf EndIf $j += 1 WEnd $i += 1 WEnd ; Could Not Find Active COM Port for matching device If $DEBUG Then ConsoleWrite("*** RETURN: -1" & @CRLF) Return $ERROR_COM_PORT_NOT_FOUND EndFunc
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