Solved
Creo VB API cannot connect when I switch network.
I am using Creo Parametric Release 8.0 and Datecode 8.0.12.0
I have some Creo VB API program. All work fine if you stay on same network all the time. If I start Creo with LAN (eternet) connection and take my laptop to a conference room with WiFi. Then I cannot connect with Creo API.
Here are the errors that I faced
pfcExceptions::XToolkitNotFound
Code:
Public Shared Function ACon(sender As System.Object)
'Connect to Creo... first with last saved connection data...
Dim cs As String = $"c:\ptc\Creo8\connection_string.ini"
Try
If File.Exists(cs) Then connection_id = File.ReadAllLines(cs).FirstOrDefault()?.Trim()
local_connId = ConId.Create(connection_id)
asyncConnection = ccon.ConnectById(local_connId, ".", 30)
Catch ex As Exception
If asyncConnection IsNot Nothing AndAlso asyncConnection.IsRunning Then
asyncConnection.Disconnect(1)
End If
End Try
'If it did not work above, try to connect with std connection string, if failed kill pfclscom and it might work next loop..
If asyncConnection Is Nothing Then
System.Threading.Thread.Sleep(500)
Try
If asyncConnection Is Nothing OrElse Not asyncConnection.IsRunning Then
asyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, 5)
End If
Catch ex2 As Exception
For Each p In Process.GetProcessesByName("pfclscom")
Try : p.Kill() : Catch : End Try
Next
End Try
End If
'Last chance....
If asyncConnection Is Nothing Then
System.Threading.Thread.Sleep(500)
Try
If asyncConnection Is Nothing OrElse Not asyncConnection.IsRunning Then
asyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, 5)
End If
Catch ex2 As Exception
Return asyncConnection
Exit Function
End Try
End If
Try
File.WriteAllText(cs, asyncConnection.GetConnectionId.ExternalRep & Environment.NewLine)
Catch
End Try
Return asyncConnection
End Function
I have some Creo VB API program. All work fine if you stay on same network all the time. If I start Creo with LAN (eternet) connection and take my laptop to a conference room with WiFi. Then I cannot connect with Creo API.
Here are the errors that I faced
pfcExceptions::XToolkitNotFound
Code:
Public Shared Function ACon(sender As System.Object)
'Connect to Creo... first with last saved connection data...
Dim cs As String = $"c:\ptc\Creo8\connection_string.ini"
Try
If File.Exists(cs) Then connection_id = File.ReadAllLines(cs).FirstOrDefault()?.Trim()
local_connId = ConId.Create(connection_id)
asyncConnection = ccon.ConnectById(local_connId, ".", 30)
Catch ex As Exception
If asyncConnection IsNot Nothing AndAlso asyncConnection.IsRunning Then
asyncConnection.Disconnect(1)
End If
End Try
'If it did not work above, try to connect with std connection string, if failed kill pfclscom and it might work next loop..
If asyncConnection Is Nothing Then
System.Threading.Thread.Sleep(500)
Try
If asyncConnection Is Nothing OrElse Not asyncConnection.IsRunning Then
asyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, 5)
End If
Catch ex2 As Exception
For Each p In Process.GetProcessesByName("pfclscom")
Try : p.Kill() : Catch : End Try
Next
End Try
End If
'Last chance....
If asyncConnection Is Nothing Then
System.Threading.Thread.Sleep(500)
Try
If asyncConnection Is Nothing OrElse Not asyncConnection.IsRunning Then
asyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, 5)
End If
Catch ex2 As Exception
Return asyncConnection
Exit Function
End Try
End If
Try
File.WriteAllText(cs, asyncConnection.GetConnectionId.ExternalRep & Environment.NewLine)
Catch
End Try
Return asyncConnection
End Function

