Following code is b4j. I can read/write data with remote PLC.
Same code i running in B4A. I could connect PLC but i cann't read/write with remote PLC(no any respones).
Why ... ?
P.S This socket library, I try to running in a service !
Same code i running in B4A. I could connect PLC but i cann't read/write with remote PLC(no any respones).
Why ... ?
P.S This socket library, I try to running in a service !
B4X:
Private client As Socket
Private AStreams As AsyncStreams
Private ReconnectTimer As Timer
Sub Open
If client.Connected = False Then
client.Initialize("client")
Try
client.Connect(vIP, vPort,30000)
Catch
Log("OpenException:"&LastException)
End Try
End If
End Sub
private Sub client_Connected (Successful As Boolean)
ReconnectTimer.Enabled = False
If AStreams.IsInitialized Then AStreams.Close
If Successful Then
mcLog("ClientConnected")
Try
AStreams.Initialize(client.InputStream, client.OutputStream, "AStreams")
timer1.Enabled=True
Catch
mcLog("ClientConnectedException:"&LastException.Message)
End Try
Else
mcLog("ClientConnected:"&Successful)
End If
DoOnConnected(Successful)
End Sub
// Receive Data From remote PLC
private Sub AStreams_NewData (Buffer() As Byte)
Dim n1 As Int=Buffer.Length
If n1 > 0 Then
For n1=0 To Buffer.Length-1
Rxbuf.Data(Rxbuf.Count) = Buffer(n1)
Rxbuf.Count = Rxbuf.Count+1
Next
End If
End Sub
// Write data to remote PLC
private Sub Write2(buffer() As Byte,start As Int,count As Int) As Boolean
If AStreams.IsInitialized Then
Try
Return AStreams.Write2(buffer,start,count)
Catch
Log("Write2Exception:"&LastException)
Return False
End Try
Else
b4jlib.Throwex("AStream not Initialzed")
Return False
End If
End Sub
Last edited: