M2D-Laser-Scanner with Ethernet-Interface
Manual
HB-M2D-Ethernet-E
Page 37 of 39
www.MElsensor.com
while(bRunConnect)
{
// establish connection
if (connect(sTCP, (SOCKADDR*) &serv_addr, sizeof(SOCKADDR)) == INVALID_SOCKET)
{
// when it is not possible to establish a connection…
}
else
{
// connection established: get data …
bRunRead = TRUE;
while(bRunRead)
{
dwReceived = recv(sTCP, chBuffer, TCPBUFSIZE, NULL);
if ((dwReceived == 0) || (dwReceived == INVALID_SOCKET))
{
// probably the connection has been disrupted, make sure,...
// to establish new connection
bRunRead = FALSE;
bRunConnect = FALSE;
closesocket(sTCP);
}
else
{
// here are the received data
// the total number of received data is in dwReceived
}
}
}
}
// finally free up the socket
closesocket(sTCP);
WSACleanup();
}
To send data to the scanner the „send“ – function is used.. Similar to example with the „recv“ – function it is nessesary to have
an existing connection to the scanner, this means to have a valid socket.
// create Data-Buffer
// this Data-Buffer has already a command to set the Scanner
// in Single-Shot-Mode
char chBuffer[2] = {0x14, 0x01};
!
send(sTCP, chBuffer, 2, NULL);
M
of
U
ore information about Windows Socket functions and network programming can be found in the documentation
the Windows operating–system. The Scanner commands are listed in the register tables of this manual.
U
D
D
P
P
I
I
m
m
p
p
l
l
e
e
m
m
e
e
n
n
t
t
a
a
t
t
i
i
o
o
n
n
Scanner-IP/Scanner-Port, Rechner-IP/Rechner-Port
The Scanner electronic system sends scan data to computer =
PC-IP : PC-Port-Number
The computer sends commands to the scanner electronic system =
Scanner-IP : Scanner-Port-Number
In the Scanner-electronic unit a UDP-Server is active, as well as in the PC. The scanner data format for UDP
transmission is the same as for TCP. The interface register description is valid for UDP as well as for TCP.