I would like to connect a VP from a NON UI B4J program.
Hardware/network initialization flow is as follows :
- socket Initialize
- socket connect
- wait for socket connected
- send specific pattern to VP
- wait for VP response.
I group all the code in a subroutine as the VP frequently disconnects and my subroutine is used to reconnect from different places in my main program
First question : I call the subroutine by ConnectToVP and it works BUT control returns to main program just after
I did not arrive to write a "Wait For .... complete.... "
I get a syntax error
How to keep control in my subroutine because my main program cannot continue execution before the 3 steps of the whole connexion to the VP ?
Second question :
If I modify the subroutine in a "resumable sub" by
- changing its name : Private Sub ConnectToVP As ResumableSub
- adding True or False after each Return
- changing call in main main program by "Wait For (ConnectToVP) Complete (Result As Boolean)"
I got the error : StartMessageLoop is missing.
I made several trials but I did not find where and how I should add this instruction ?
Third question :
How could it be possible to add a timeout test on the whole subroutine if VP never responds ?
Thanks for your help
Hardware/network initialization flow is as follows :
- socket Initialize
- socket connect
- wait for socket connected
- send specific pattern to VP
- wait for VP response.
I group all the code in a subroutine as the VP frequently disconnects and my subroutine is used to reconnect from different places in my main program
B4X:
Private Sub ConnectToVP
If FluxVP.IsInitialized Then
FluxVP.Close
End If
If Socket.IsInitialized Then
Socket.Close
End If
Log("Initialise le socket pour communiquer avec l'EPSON")
Socket.Initialize("SocketVP")
Socket.Connect(IPEpson,PortEpson,0) ' No TimeOut
Wait For SocketVP_Connected(ConnexionOK As Boolean)
' Revient ici au retour de l'initialisation de la connexion avec l'EPSON
If ConnexionOK = True Then
Log("Connect initial EPSON Sucessful")
FluxVP.Initialize(Socket.InputStream, Socket.OutputStream, "FluxVP")
Else
Log("Connection EPSON failed")
Return
End If
' Initialise le VP EPSON avec une pattern de démarrage
' Pattern(string) = ESC/VP.net<DLE><ETX><NUL><NUL><NUL><NUL>
Dim StartPattern = "4553432F56502E6E6574100300000000" As String
Log("Envoie la Pattern de démarrage au VP")
Dim Buffer() As Byte
Buffer = BConv.HexToBytes(StartPattern)
FluxVP.Write(Buffer)
'
Wait For FluxVP_NewData (Buffer() As Byte)
Dim RetourVP As String
Dim MessRetour As String = "Retour du VP après envoi pattern: "
RetourVP = BytesToString(Buffer, 0, Buffer.Length, "ASCII")
If RetourVP.StartsWith("ESC/VP.net") Then
VPEpsonOK = 1 ' Connecté
Log(MessRetour & "OK")
Else
VPEpsonOK = 0 ' NON Connecté
Log(MessRetour & "Retour VP pas conforme")
End If
Return
End Sub
First question : I call the subroutine by ConnectToVP and it works BUT control returns to main program just after
B4X:
Wait For SocketVP_Connected(ConnexionOK As Boolean)
I get a syntax error
How to keep control in my subroutine because my main program cannot continue execution before the 3 steps of the whole connexion to the VP ?
Second question :
If I modify the subroutine in a "resumable sub" by
- changing its name : Private Sub ConnectToVP As ResumableSub
- adding True or False after each Return
- changing call in main main program by "Wait For (ConnectToVP) Complete (Result As Boolean)"
I got the error : StartMessageLoop is missing.
I made several trials but I did not find where and how I should add this instruction ?
Third question :
How could it be possible to add a timeout test on the whole subroutine if VP never responds ?
Thanks for your help