Internet Connect got an error: Connection is invalid

Hi Folks,

in this application I get the following error (from time to time) when connecting to the Internet - but alltough I get this error the Connection will be opened → and the status reports will not be displayed (pegel_con, pegel_signal) - The Problem must be at the “on click” handler… The rest looks ok and the application compiles ok…

[b]Error Message:

Apple Script Error[/b]

Internet Connect got an error: Connection is invalid. (-609)


-- Web'n'walk Manager MacOS.applescript
-- Web'n'walk Manager MacOS

--  Created by Stefan Lehrner on 11/10/06.
--  Copyright 2006 T-Mobile.at.

on launched theApplication
	set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to true
	set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to false
	--Modemabfrage - dieser Block muss identisch mit dem OnClick Handler sein!
	set modem_check to serialport list
	if modem_check contains "/dev/cu.HUAWEIMobile-Modem" then
		set modem to "/dev/cu.HUAWEIMobile-Modem"
		set modem_display to "Web'n'walk Box compact"
		--display dialog modem_display
		--display dialog modem
		
	else if modem_check contains "/dev/cu.HUAWEIMobile-Diag" then
		set modem to "/dev/cu.HUAWEIMobile-Diag"
		set modem_display to "Kein gültiges Modem gefunden"
		return modem_display
		return modem
	end if
	-- Hier wird das Modem angezeigt
	set contents of text field "device_con" of tab view item "Connection" of tab view "tab" of window id 1 to modem_display
	
	-- Hier wird der Provider gecheckt
	
	set portRef to serialport open modem
	
	if portRef is equal to -1 then
		display dialog "Kein Modem verbunden"
		quit
	else
		--delay 1
		set provider to "at+cops?" & return
		serialport write provider to portRef
		delay 1
		set provider_show to serialport read portRef for 35
		serialport close portRef
	end if
	
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "\"" -- again, quotes escaped
	set Q to text item 2 of provider_show
	set AppleScript's text item delimiters to tid
	--display dialog Q
	if Q is not equal to "T-Mobile A" then
		set provider to "at+cops?" & return
		serialport write provider to portRef
		--delay 1
		set provider_show to serialport read portRef for 35
		serialport close portRef
		set tid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to "\"" -- again, quotes escaped
		set Q to text item 2 of provider_show
		set AppleScript's text item delimiters to tid
		--display dialog Q
	end if
	set contents of text field "provider" of tab view item "Connection" of tab view "tab" of window id 1 to Q
	
	--Hier wird der Pegel des netzwerkes gecheckt
	set portRef1 to serialport open modem
	if portRef1 is equal to -1 then
		display dialog "could not open port"
	else
		--delay 1
		set foundOffset to 0
		set pegel to "at+CSQ" & return
		serialport write pegel to portRef1
		delay 1
		set pegel_show to serialport read portRef1
		
		set AppleScript's text item delimiters to the ":"
		set the pegel_show to 2nd text item of pegel_show
		set AppleScript's text item delimiters to the ","
		set the pegel_show to 1st text item of pegel_show
		--	display dialog pegel_show
		
		set pegel_show to pegel_show as number
		serialport close portRef1
	end if
	
	if pegel_show is less than or equal to 10 then
		set content of control "pegel_signal" of tab view item "Connection" of tab view "tab" of window id 1 to 1
	else if pegel_show is less than or equal to 15 then
		set content of control "pegel_signal" of tab view item "Connection" of tab view "tab" of window id 1 to 2
	else if pegel_show is less than or equal to 20 then
		set content of control "pegel_signal" of tab view item "Connection" of tab view "tab" of window id 1 to 3
	else if pegel_show is less than or equal to 25 then
		set content of control "pegel_signal" of tab view item "Connection" of tab view "tab" of window id 1 to 4
	else if pegel_show is less than or equal to 35 then
		set content of control "pegel_signal" of tab view item "Connection" of tab view "tab" of window id 1 to 5
	end if
	
	
	-- Hier wird die Telefonnummer abgefragt:
	
	set portRef1 to serialport open modem
	if portRef1 is equal to -1 then
		display dialog "could not open port"
	else
		--delay 1
		set foundOffset to 0
		set own_number to "at+cnum" & return
		serialport write own_number to portRef1
		delay 1
		set number_show to serialport read portRef1
		set AppleScript's text item delimiters to the "\""
		set the number_show to 4th text item of number_show
		set contents of text field "pegel" of tab view item "Connection" of tab view "tab" of window 1 to number_show
		serialport close portRef
	end if
end launched

on idle theObject
	
	--Anzeige Onlinezeit
	tell application "Internet Connect"
		set time_conn to seconds connected of status as string
	end tell
	
	
	set numSeconds to time_conn mod 60
	set temp to time_conn - numSeconds
	set numMinutes to temp div 60
	set numMinutes to numMinutes mod 60
	set temp to (numMinutes * 60) + numSeconds
	set temp to time_conn - temp
	set numHours to temp div 3600
	if numHours < 10 then set numHours to "0" & numHours
	if numMinutes < 10 then set numMinutes to "0" & numMinutes
	set finalTime to numHours & ":" & numMinutes & ":" & numSeconds as string
	
	
	-- Statusanzeige (Internet)
	
	tell application "Internet Connect"
		set con_status to state of status as string
	end tell
	
	if con_status is "0" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 1
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to true
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to false
	else if con_status is "2" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 2
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to false
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to true
	else if con_status is "4" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 3
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to false
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to true
	else if con_status is "7" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 4
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to false
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to true
	else if con_status is "8" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 5
		set contents of text field "print_time" of tab view item "Setting" of tab view "tab" of window id 1 to finalTime
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to false
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to true
		
	else if con_status is "10" then
		set content of control "pegel_con" of tab view item "Connection" of tab view "tab" of window id 1 to 1
		set enabled of button "Connect" of tab view item "Connection" of tab view "tab" of window id 1 to true
		set enabled of button "Disconnect" of tab view item "Connection" of tab view "tab" of window id 1 to false
	end if
	
	-- Anzeige empfangene Daten	
	tell application "Internet Connect"
		set bytes_received to bytes received of status as string
	end tell
	set received_print to bytes_received / 1024
	set received_final to received_print as integer
	
	set contents of text field "print_received" of tab view item "Setting" of tab view "tab" of window id 1 to received_final
	
	-- Anzeige gesendetete Daten	
	tell application "Internet Connect"
		set bytes_sent to bytes sent of status as string
	end tell
	
	set sent_print to bytes_sent / 1024
	set sent_final to sent_print as integer
	set contents of text field "print_sent" of tab view item "Setting" of tab view "tab" of window id 1 to sent_final
	
	
	return 1
	serialport close
end idle

on awake from nib
	
	--quit
	
end awake from nib

on clicked theObject
	
	-- dieser block muss immer gleich sein mit dem obersten block
	set modem_check to serialport list
	if modem_check contains "/dev/cu.HUAWEIMobile-Modem" then
		set modem to "/dev/cu.HUAWEIMobile-Modem"
		set modem_display to "Web'n'walk Box compact"
		
		
	else if modem_check contains "/dev/cu.HUAWEIMobile-Diag" then
		set modem to "/dev/cu.HUAWEIMobile-Diag"
		set modem_display to "Kein gültiges Modem gefunden"
		return modem_display
		return modem
	end if
	--serialport close modem_check
	
	
	--display dialog modem_display
	
	if name of theObject is "Connect" then
		tell window "main"
			set PopupButtonItem to modem_display
		end tell
		
		set theMatrixItem to title of current cell of matrix "theMatrix" of tab view item "Setting" of tab view "tab" of window id 1
		
		-- Check Huawei E220 gprsinternet
		if (PopupButtonItem is "Web'n'walk Box compact") and (theMatrixItem is "HSDPA Internet") then
			tell application "Internet Connect"
				set configName to "HUAWEI Mobile"
				set currentStatus to status of configuration configName
				connect PPP configuration 1 to telephone number "gprsinternet"
				quit
			end tell
		end if
		-- Check Huawei E220 business.gprsinternet
		if (PopupButtonItem is "Web'n'walk Box compact") and (theMatrixItem is "HSDPA Business") then
			tell application "Internet Connect"
				--activate
				set configName to "HUAWEI Mobile"
				set currentStatus to status of configuration configName
				connect PPP configuration 1 to telephone number "business.gprsinternet"
				quit
			end tell
		end if
		
	end if
	
	if name of theObject is "Disconnect" then
		tell application "Internet Connect"
			if modem_display is "Web'n'walk Box compact" then
				set configName to "HUAWEI Mobile"
			end if
			set currentStatus to status of configuration configName
			disconnect configuration configName
		end tell
	end if
end clicked


thanks for any feedback…

Best Regards,

Stefan

Model: iBook G4 with 1.2GHZ
Browser: Safari 419.3
Operating System: Mac OS X (10.4)