background image

M2D-Laser-Scanner with Ethernet-Interface 

Manual 

 

 

HB-M2D-Ethernet-E 

Page 36 of 39 

www.MElsensor.com

 

 

E

E

t

t

h

h

e

e

r

r

n

n

e

e

t

t

 

 

W

W

i

i

n

n

S

S

o

o

c

c

k

k

 

 

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

 

 

 

To communicate with a M2D Ethernet–Scanner so called Windows Socket „WinSock“-functions are used. These functions are 
part of all windows operating systems. Other operating systems provide similar functions.  

 

„WinSock”-functions are encapsulated into a „ws2_32.dll“-file. These files belong to Windows. 
The communication uses a TCP/IP-protocol with M2D Scanner working as a server. So the communication partner, in our 
case the PC, has to be set up as a client. Before using the network functions the „WSAStartup“-function has to be called. So 
the regular functions from „WinSock“ can be used. 

 

Next a valid TCP-SOCKET (a kind of object) has to be received from the system. This is done by calling the function „socket“. 
If there is a valid SOCKET, it is possible to establish a connection to the M2D Scanner. This will be made by the function 
„connect“. After a successful call of this function, PC and scanner are connected and it is possible to exchange data with the 
two commands „send“ and „recv“. 

 

At the end of each communication stream all memories and sockets have to be released. This is done by using the two 
functions „closesocket“ and „WSACleanup“ at the end. 

E

E

x

x

a

a

m

m

p

p

l

l

e

e

:

:

 

 

(

(

C

C

)

)

 

 

u

u

s

s

i

i

n

n

g

g

 

 

W

W

i

i

n

n

S

S

o

o

c

c

k

k

 

 

a

a

n

n

d

d

 

 

S

S

c

c

a

a

n

n

n

n

e

e

r

r

 

 

 

 

f

f

u

u

n

n

c

c

t

t

i

i

o

o

n

n

s

s

:

:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

// receiving block size should be modulo 2.048 
// the Scanner sends blocks in size of 2.048 Bytes. 

#define TCPBUFSIZE 2048 

// structure  for WinSocket 

WSADATA wsaData; 

// socket-Variable 

SOCKET sTCP; 

// receive buffer of the size mentioned above 

char chBuffer[TCPBUFSIZE]; 

// number of received bytes from scanner 

DWORD dwReceived = 0; 

// permanently try to reach socket, when connection is broken 

BOOL bRunSocket = TRUE; 
  // permanently try to establish connection, when receive function returns an error 
BOOL bRunConnect = TRUE; 

// permanently receive data from scanner 

BOOL bRunRead = TRUE; 

// define TimeOut in [ms] for receive function 
// after this time, the “recv”-Function returns with dwReceived=0 
// then the link will be locked and transmission established 

DWORD dwRecvTimeOut = 10000; 

//  try to run WinSocket  Version 2.1 

if (WSAStartup (MAKEWORD(2, 1), &wsaData) != NULL) 

   AfxMessageBox("Fehler: WSAStartup", MB_OK | MB_ICONEXCLAMATION, NULL); 
   return; 

//Structure for the “connect”-command 

SOCKADDR_IN serv_addr; 

// MUST have the value “AF_INET” 

serv_addr.sin_family = AF_INET; 

// transmit Port-Number of Scanner 

serv_addr.sin_port = htons(atoi(“3000”)); 

// transmit IP-Adresse of Scanner 

serv_addr.sin_addr.S_un.S_addr = inet_addr(“192.168.123.224”); 
while(bRunSocket) 

   bRunConnect = TRUE; 
   

 // get Socket for TCP=SOCK_STREAM 

   sTCP = socket(AF_INET, SOCK_STREAM, 0); 
  

  // socket-Error? 

   if (sTCP == INVALID_SOCKET) 
   { 

      sTCP = 0; 
      bRunConnect = FALSE; 
      TRACE("SocketError\n"); 

   } 

    

// set TimeOut for “recv”-Function 

   setsockopt(sTCP, SOL_SOCKET, SO_RCVTIMEO, (const char*)&dwRecvTimeOut, sizeof(int)); 

 

 

Summary of Contents for M2D/LAN

Page 1: ...ner with Ethernet Interface Manual Version 3 6 4 a MEL Mikroelektronik GmbH Breslauer Str 2 D 85386 Eching Tel 49 89 327 150 0 Fax 49 89 319 20 23 www MELsensor de october 2007 Copyright MEL 2004 2006...

Page 2: ...ub 25 pin 9 Ground connection connector D Sub 25 9 Technical data 10 M2DF LAN Laser Scanner electronic system in Blue Box with Ethernet interface 10 Dimensions of the electronic box 10 Other MEL Laser...

Page 3: ...ses and commands 26 3 Command 0x21 dump 27 example read out FiFo status and sensor temperature 32 Setting the IP Address by software 34 Representation of the Serial Number 34 Ports 35 Ethernet WinSock...

Page 4: ...n S So of ft tw wa ar re e C Co on nt tr ro ol ll le ed d P Pa ar ra am me et te er rs s TCP IP address subnet mask TCP ports Operation controls shutter control Laser intensity control Video gain cont...

Page 5: ...ctor Both connections will provide the same function Both connections can never be used in parallel When the connection is made at the RJ 45 connector no Ethernet cable must be connected at the D Sub...

Page 6: ...and display the Scan profile information retrieved from the scanners The performance of CPU and graphic card could cause dropped frames Use the image count number delivered with the scan profile data...

Page 7: ...s s From PC board version 1 3 on the digital inputs may be used to feed encoder signals The digital A B inputs feed a counter which is read out over the registers 13 16 The encoder counter information...

Page 8: ...block See page 5 for details Register 12 sets the version of protocol 1 3 R Re eg gi is st te er r 0 0x x1 1B B P Pr ro of fi il le e p pe ea ak k r re ec co og gn ni it ti io on n t th hr re es sh h...

Page 9: ...Sync input has internal pull down resistor using firmware update is on customers risk no warranty connect RIP Pin Pin 5 to ground Then cycle power After restart the Scanner will communicate on the def...

Page 10: ...ors at the box D Sub 9pin female scanner connector D Sub 25pin male Supply Ethernet Sync ext Trigger RJ 45 Ethernet D Di im me en ns si io on ns s o of f t th he e e el le ec ct tr ro on ni ic c b bo...

Page 11: ...ther the MEL configuration software or a Web Browser could be used UDP version is available on request S Se et t u up p o of f t th he e S Sc ca an nn ne er rs s w wo or rk ki in ng g I IP P A Ad dd d...

Page 12: ...r 3 192 168 123 224 Address Scanner 4 192 168 123 225 Address Scanner 5 192 168 123 226 Address Scanner 6 192 168 123 227 Address Scanner 7 192 168 123 224 wrong IP Address conflict with scanner 3 Add...

Page 13: ...splay of one scanner to display of up to four scanners The red profile is the counter X the white profile shows the coordinate Z as a function of x and the yellow curve is the intensity display Tab 4...

Page 14: ...ield on Tab1 on an inactive IP address and overwrite the temporary IP address Press Enter when done and click the checkbox on the left side of Tab1 to connect to the temp IP address This temp IP addre...

Page 15: ...reserve unsigned char 2 Reserved 52 59 null_8 unsigned char 8 Synchronization raster 8 Null bytes 60 60 version unsigned char 1 Protocol version number default 1 range 1 3 or 10 61 61 status unsigned...

Page 16: ...are version The FiFO status filling level is given also with every scan profile packet of the length 2048 bytes Status registers are the registers marked in yellow on page 15 Status registers can be q...

Page 17: ...Version 4 0x13 19 Reset camera chip reset hours counter and camera 0x14 20 0 2 3 5 4 Do not use Measurement control Field out definition Bit 0 2 is only for Rev 1 hardware 0 continuous 1 single shot t...

Page 18: ...ways 0 R Re eg gi is st te er r v va al lu ue e 2 2 3 3 v ve er rs si io on n n nu um mb be er r o of f c ca am me er ra a a an nd d e el le ec ct tr ro on ni ic c s sy ys st te em m Reg value Bit Nr...

Page 19: ...surface of interest 3 read out laser control Bit 2 9 4 set laser to external manual control mode 5 write back Bit 0 1 as 0 and Bit 2 9 of the previously read out value R Re eg gi is st te er r v va al...

Page 20: ...asurement range Z not linearized 54 6 0 LB 55 6 0 HB Min scan range X not linearized 56 6 0 LB 57 6 0 HB Max measurement range Z not linearized 58 6 0 LB 59 6 0 HB Max scan range X not linearized 60 0...

Page 21: ...I7 I6 I5 I4 I3 I2 I1 Distance Z 0 2048 Scan range X 0 1024 Intensity I 0 127 The value of the Bytes is never bigger than 254 FEh Byte value 255 FFh is invalid and appears when the FiFo is empty Proto...

Page 22: ...segment marked in grey colour Type the password MELSENSOR all capital letters without and hit ENTER or press the lower left button Send and wait for the second prompt from the Scanner stating that th...

Page 23: ...D Auswertung 36 2 017 Working Data 018 MAC 00 08 DC 2B 10 6F 019 IP 192 168 123 224 3000 020 SubNetz 255 255 255 0 021 GateWay 192 168 123 1 022 023 TCP Connecting 024 0x0A 025 On the RS 232 interface...

Page 24: ...eed for the update procedure o Flashm16 exe executable updater o M2d_eth_1 10 6 firmware binary o Start_1 10 6 bat batch file startBackup is an optional report generator Before you rewrite the firmwar...

Page 25: ...wer up of scanner Check if the IP is free Power down the scanner to see if another device has taken the IP Try M2D iVision exe Ping the IP Cmd ping xxx xxx xxx xxx When the scanner is down no other de...

Page 26: ...76543210 76543210 76543210 0xxxxxxx 1xxxxxxx 0xxxxxxx 1xxxxxxx Software Examples 1 Switch on Off FPGA LED Lo Byte Hi Byte 0x0B 0x80 LED on 0x0B 0x81 LED off 0x0B register address decimal 11 0x80 comm...

Page 27: ...values are stored until next reset command 0x1F Reset Ethernet in memory 4 examples of accessing registers functions and data These examples have been taken from the M2Dmini c For use as a complete pa...

Page 28: ...f ioPort 2 M2DWrite write to M2D Register anz 0 registerNr command e g 0x1C reset FIFO value not used 1 write value to registerNr 2 write value to registerNR registerNr 1 shift value to fit low high r...

Page 29: ...le 1 val ByteFromM2 inf if val 1 return 1 timeout if val 0 synCnt else if synCnt 8 ifdef M2D_DEBUG if synCnt 8 ifdef __RT__ printk n d n synCnt else printf n d n synCnt endif endif sync info 4 byte in...

Page 30: ...if v1 1 return 1 v2 ByteFromM2 inf if v2 1 return 1 v3 ByteFromM2 inf if v3 1 return 1 x i v0 v1 0x60 2 v3 0x07 9 z i v2 v1 0x1F 7 v3 v3 0xF8 intensity i v3 128 v3 127 1 v3 127 1 else not linear for i...

Page 31: ...urn 0 ok 1 fail inf sync 3 status int M2DStatus M2DInfo inf int num int i res result int res M2DStatus sens 3 result 1 M2DWrite inf 0x11 num 1 select status register M2DWrite inf 0x1C 0 0 clear FIFO f...

Page 32: ...0 break if hw opt1 8 0 hw amb 10 f hw mb 10 f hw sbAmb 10 f hw abEmb 10 f res MwDStatusInt inf 48 2 hw maxZ if res 0 break res MwDStatusInt inf 50 2 hw maxX if res 0 break res MwDStatusInt inf 2 1 hw...

Page 33: ...ferUARTTx 2 scanner 0x07 uiBufferUARTTx 3 Scanner_data scan uiBufferUARTTx 0xFF uiBufferUARTTx scanner 31 0x80 scanner 17 Temperatur abfragen For y 0 y 31 y scanner y 0x80 Scanner_data scan y scanner...

Page 34: ...ubnet mask 3rd octet 23 0 Subnet mask 4th octet 24 192 IP address 1st octet 25 168 IP address 2nd octet 26 123 IP address 3rd octet 27 224 IP address 4th octet 28 PORT LOWORD 0xB8 29 PORT HIWORD 0x0B...

Page 35: ...gEEPROMData 37 0x7F 7 ulTemp unsigned long ucRegEEPROMData 38 0x7F 14 ulTemp unsigned long ucRegEEPROMData 39 0x7F 21 P Po or rt ts s Ports are a part of the IP address definition When setting the wor...

Page 36: ...le e C C u us si in ng g W Wi in nS So oc ck k a an nd d S Sc ca an nn ne er r f fu un nc ct ti io on ns s receiving block size should be modulo 2 048 the Scanner sends blocks in size of 2 048 Bytes d...

Page 37: ...he 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...

Page 38: ...atoi 3000 0x00FF chTemp 30 atoi 3000 0xFF00 8 Note the UDP transmission protocol has been implemented in a new project of the MEL EthernetScanner demo software Typical TCP functions have been dropped...

Page 39: ...s Seitenzahlen ge ndert 2007 3 6 2 2 Register 6 7 Default Wert 950 12 3 2007 3 6 2 2 nderungsliste im Handbuch hinzugef gt 12 3 2007 3 6 2 2 Erdungskonzept Seite 10 hinzugef gt 12 5 2007 3 6 3 Firmwar...

Reviews: