Page 1 of 1 1
Topic Options
#199069 - 2010-07-22 03:52 PM Need access to modem comport
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I need to script a connection to com4, send ATI1, catch the output into a file so I can parse the output

I have tried Putty with plink, serialterm 1.1, and hyperterm

Any ideas?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#199072 - 2010-07-22 05:38 PM Re: Need access to modem comport [Re: Radimus]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Modem? What's a modem? ;\)

In the "old days" we were able to OPEN('COM#:,1200,8,1,N').

Look into the MSComm object for direct COM port I/O - This is a good link to get started.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#199073 - 2010-07-22 05:40 PM Re: Need access to modem comport [Re: Radimus]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
This link shows connecting to a com port with c# and net 2.0: c# com port
Here is another one in a similar vein: serial port with .net

Hopefully, that might show the way. \:\)

Top
#199074 - 2010-07-22 05:47 PM Re: Need access to modem comport [Re: BradV]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I need to get the ESN of the Sprint cards that many of our laptops/tablets have. There is nothing in the registry or WMI of the PCMCIA slot, but if I send a "ATI1" to the modem port/com4, it replies back with the device description and ESN.

problem is to get that info from the serial port.

I'll look at the mscomm info
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#199077 - 2010-07-22 09:56 PM Re: Need access to modem comport [Re: Radimus]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ok, I finally got it to work using putty and plink

(still refining the code, but it does produce the results)

 Code:
Break On

$objWMIService = GetObject("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_POTSModem",,48)
For Each $objItem in $colItems
	If InStr($objItem.Description,'Wireless') And $objItem.Status = 'OK'
		$comport = $objItem.AttachedTo
  	EndIf
Next

$puttykey = 'HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings'
$nul = WriteValue($puttykey,'Protocol','serial',REG_SZ)
$nul = WriteValue($puttykey,'SerialLine',$comport,REG_SZ)

Del 'c:\logfiles\sprintcard.txt'

Run 'cmd /c echo ati1 | plink > c:\logfiles\sprintcard.txt'

Sleep 5
$nul = FindPROC(@wksta,'plink.exe',1)
Sleep 3

$SprintData = Readfile('c:\logfiles\sprintcard.txt')
For Each $line in $SprintData
	Select
		Case InStr($line,'Manufacturer')	$man=Trim(SubStr($line,InStr($line,':')+1))
		Case InStr($line,'Model')		$mod=Trim(SubStr($line,InStr($line,':')+1))
		Case InStr($line,'Revision')		$rev=Trim(SubStr($line,InStr($line,':')+1))
		Case InStr($line,'ESN')			$esn=Trim(SubStr($line,InStr($line,':')+1))
	EndSelect
Next

?
? 'Manufacturer: '+$man
? 'Model: '+$mod
? 'Revision: '+$rev
? 'ESN: '+$esn
? 'COM Port: '+$comport
?
? 'press enter'
Gets $k

Function FindPROC($COMPUTER,$PROC,optional $terminate)
	Dim $GetObject, $Select
	$GetObject="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER"
	$select="select * from Win32_Process where Name='$PROC'"
	For Each $Process in GetObject("$GetObject").ExecQuery("$select")
		If $terminate		$Process.Terminate	EndIf
		$FindPROC=$Process.ProcessId
	Next
EndFunction

Function ReadFile($file)
	Dim $lf, $f, $_, $t
	$lf = Chr(10)
	$f = FreeFileHandle
	$_ = Open($f, $file)
	If @error Exit @error EndIf
	Do $t = $t + $lf + ReadLine($f) Until @error
	$_ = Close($f)
	$ReadFile = Split(SubStr($t, 2), $lf)
EndFunction
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1045 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.057 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org