![MEL M2-iLAN Series User Manual Download Page 40](http://html1.mh-extra.com/html/mel/m2-ilan-series/m2-ilan-series_user-manual_1766769040.webp)
M2i-LAN Laser-Scanner manual
HB-M2-iLAN-UDP-E.doc
page 40 of 44
MEL Mikroelektronik GmbH, Breslauer Str. 2, 85386 Eching / Germany
www.MELSensor.de
// set TimeOut for “
recv
”-Function
setsockopt(sTCP, SOL_SOCKET, SO_RCVTIMEO, (const char*)&dwRecvTimeOut, sizeof(int));
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);
Tipp:
more information about Windows Socket functions and network programming can be found
in the documentation of the Windows operating–system.
the Scanner commands are listed in the register tables of this manual.