
2.12 Communications with a Windows PC (Visual Basic Application)
Using Automatic Reception with the MP3000 as a Slave
2-334
rc = 0
'---- Send command data ----
slen = send(sock, Ssbuf, DATAi
∗
2, 0)
If (slen <> DATAi
∗
2) Then
MsgBox("send error " & WSAGetLastError())
closesocket(0)
WSACleanup() ’Release the Winsock.DLL
Return -1
End If
'---- Receive response data ----
Srbuf = Space(4096)
rlen = recv(sock, Srbuf, 4096, 0)
If (rlen <= 0) Then
MsgBox("receive error " & WSAGetLastError())
closesocket(0)
WSACleanup() ’Release the Winsock.DLL
Return -1
End If
'---- Check response data ----
rc = ChkRspData(rlen, Srbuf)
If (rc <> 0) Then
MsgBox("receive data format error")
End If
Return rc
End Function
'------------------------------------------------------------------------------
Send command data, receive response data (UDP)
'------------------------------------------------------------------------------
Function UdpMsg(ByRef Ssbuf As String, ByRef Srbuf As String) As Short
Dim rc, slen As Integer
Dim rlen As Short
Dim from_len As Short
rc = 0
'---- Send command data ----
slen = sendto(sock, Ssbuf, DATAi
∗
2, 0, MP_addr, Len(MP_addr))
If (slen <> DATAi
∗
2) Then
MsgBox("send error " & WSAGetLastError())
End If