2.12 Communications with a Windows PC (Visual Basic Application)
Using Automatic Reception with the MP3000 as a Slave
2-333
If (sock < 0) Then
MsgBox("Socket error " & WSAGetLastError())
Return -1
End If
'---- Bind the local port number and socket ----
rc = bind(sock, PC_addr, Len(PC_addr))
If (rc <> 0) Then
MsgBox("Bind error " & WSAGetLastError())
closesocket(0)
WSACleanup() ’Release the Winsock.DLL
Return -1
End If
'---- Establish connection ----
If (TransPort = 0) Then
rc = connect(sock, MP_addr, Len(MP_addr))
If (rc <> 0) Then
MsgBox("Connect error " & WSAGetLastError())
closesocket(0)
WSACleanup() ’Release the Winsock.DLL
Return -1
End If
End If
Return 0
End Function
'------------------------------------------------------------------------------
Send command data, receive response data
'------------------------------------------------------------------------------
Function MemobusMsg(ByVal TransPort As Short, ByRef Ssbuf As String, ByRef Srbuf As String) As Short
Dim rc As Short
If TransPort = 0 Then
rc = TcpMsg(Ssbuf, Srbuf)
Else
rc = UdpMsg(Ssbuf, Srbuf)
End If
Return rc
End Function
'------------------------------------------------------------------------------
Send command data, receive response data (TCP)
'------------------------------------------------------------------------------
Function TcpMsg(ByRef Ssbuf As String, ByRef Srbuf As String) As Short
Dim rc, slen As Integer
Dim rlen As Short