HelloDevice ( HD1320E/1320/1321) Version 11 1
2
1 2 3 31 HD1320/1320E 311 312 313 RS232 32 HD1321 321 322 33 4 41 42 421 HD1320/1320E 422 HD1321 43 431 IP 432 IP 44 441 442 443 RS232 5 51 52 521 TCP 522 TCP 523 3
6 RS232-TCP/IP 61 TCP 611 TCP 612 TCP 613 TCP / 62 RS232 4
HelloDevice 1320/1320E/1321 1 HD132x HD1320E HD1320 HD1321 PCB PCB PCB 75V - - RS232 - - CD-ROM - - HelloDevice http://wwwsenacom/korean/hellodevice/downloadshtml - - - = 75 V ~ 9 V DC (HD1320/1320E), 5V DC ±10% (HD1321) - = 150mA - = 0 ~ 95% - = 5 ~ 55 HelloDevice 137-130 210 : (02) 573-7772 : (02) 573-7710 : support@senacom : http://wwwsenacom 5
HelloDevice 1320/1320E/1321 2 HD132x, RS232 TCP/IP, RS232 TCP/IP,, TCP/IP RS232 HD132x HD1320E/1320/1321, 21 RS232 TCP/IP, HD1320E HD1320, HD1321, DIP HD1320/HD1320E/HD1321 CPU Ubicom Sx52BD (8-Bit, 50 MIPS) 32 KB SRAM 10 Base-T (IEEE8023) 1 RS-232, 115 Kbps DHCP TCP IP / ICMP / ARP (IEEE8023) HelloDevice ( 95/98/NT/2000 ) : IP, 21 HelloDevice 132X 6
HelloDevice 1320/1320E/1321 3 31 HD1320/HD1320E HD1320E 31 (a), (b), 32 Status LEDS Power Collision Rx Tx RJ-45 Connector To Ethernet Serial Connector (RS-232) Power Connection ( 75V ~ 9V DC ) 31(a) HD1320E 32 KB SRAM Ethernet Controller Microprocessor UART Status LEDS Power Collision Rx Tx RJ-45 Connector To Ethernet Serial Connector (RS-232) Power Connection ( 75V ~ 9V DC ) 31(b) HD1320/1320E 7
HelloDevice 1320/1320E/1321 RJ45 connector to Ethernet 10 Base-T filter Ethernet controller (10 Base-T) Sx52BD microprocessor 32 KB RAM Power supply 1 serial port RS232 32 HD1320 311 = 75 V ~ 9V DC = 150mA 312 HelloDevice RJ45, 100m (1),,, : RealTek Full-duplex : RTL8019AS IEEE8023 10Base-T NE2000 8
HelloDevice 1320/1320E/1321 (2) RJ45 AT&T258 Shield 1=Tx+ 2=Tx- 7=NC 8=NC Pin 1 Tx+ White with orange 2 Tx- Orange 3 Rx+ White with green 4 Not used Blue 5 Not used White with blue 6 Rx- Green 7 Not used White with brown 8 Not used Brown 3=Rx+ 6=Rx- 4=NC 5=NC 33 RJ45 (3) LED LED Tx, Rx, Collision, Power LED 4 ( 31), Power LED HelloDevice ON Rx LED / Tx LED HelloDevice 1 /,, ping PC / Collision LED, 9
HelloDevice 1320/1320E/1321 313 RS232 RS232 DB9 150bps ~ 115Kbps 3=TxD 2=RxD 4=NC 1=NC 5=GND 6=NC 9=NC 7=RTS 8=CTS Pin 1 NC Not connected - 2 RxD Receive Data Data Input 3 TxD Send Data Data Output 4 NC Not connected - 5 GND Signal Ground - 6 NC Not connected - 7 RTS Ready To Send Handshake Output (+12V=Ready to Rx, -12V=Not Ready to Rx) 8 CTS Clear To Send Data sent 9 NC Not connected Data sent only at +3V ~ 12V 34 HelloDevice DSUB 10
HelloDevice 1320/1320E/1321 32 HD1321 HD1321 35, 36 Rear side 10BaseT Ethernet Chip microprocessor UART External interface Ethernet interface Power Connection ( 5V DC ) TTL RS232 interface 32 KB SRAM 35 HD1321 32 KB SRAM Ethernet controller (10 Base-T) Sx52BD microprocessor Ethernet RS232 Interface Power supply 36 HD1321 11
HelloDevice 1320/1320E/1321 321 = 5 V DC ±10% = 150mA 322 HD1321,, UART, JP1, JP2 20 37, 31 HD1321 # 1 GND 2 Reset System Reset Low Active JP1 3 ~ 5 LED2 ~ LED0 LED LED0: Tx, LED1: Rx, LED2: Collision 6 TPOut- TPOut- 7 TPOut+ TPOut+ JP2 8 TPIn+ TPIn+ 9 TPIn- TPIn- 10 Vcc 5V 1 Vcc 5V 2 NC 3 DSR RS232 Data Set Ready 4 CTS RS232 Clear To Send 5 DTR RS232 Data Terminal Ready 6 RTS RS232 Ready To Send 7 RxD RS232 Data Input 8 TxD RS232 Data Output 9 NC 10 GND TTL Level 31 HD1321 12
HelloDevice 1320/1320E/1321 GND Reset LED2 LED1 LED0 TPOut- TPOut+ TPIn+ TPIn- Vcc 1 2 3 4 5 6 7 8 9 10 JP1 1 2 3 4 5 6 7 8 9 10 JP2 Vcc NC DSR CTR DTR RTS RxD TxD NC GND 37 HD1321 13
HelloDevice 1320/1320E/1321 33 4 KWORD, (OSI : Open System Interconnection) TCP/IP RS232 32, OSI 7 HelloDevice 7 Application RS232 DHCP 6 Presentation 5 Session 4 Transport 3 Network TCP UDP 2 Data link IP / ICMP ARP 1 Physical layer (IEEE8023) 32 OSI 7 HelloDevice 132X 14
HelloDevice 1320/1320E/1321 4 HelloDevice (1) HelloDevice (2) HelloDevice (3) HelloDevice IP (4) HelloDevice 41 PC HelloDevice CD-ROM \HD_UTILITY\HD1x20 setup132xexe Setup132xexe 95/98/ME/ NT/2000 [setup type] [Complete] [Custom] [Next] 41 HelloDevice [Complete], Program Files\sena\HelloDevice Utility_HD1320\ [Custom] 15
HelloDevice 1320/1320E/1321 42(a) [Custom setup] 42(b) [Change] 16
HelloDevice 1320/1320E/1321, 42 (a), (b) [Custom] [Change], HelloDevice, HelloDevice 43 HelloDevice 17
HelloDevice 1320/1320E/1321 42 HD1320/1320E,, RS232, 1320E 421 HD1320/1320E (1) 75V ~ 9V DC HD1320E 110/220 V 75V HD1320E 44 HD1320E 75V (2) RJ45 HD1320E (HD1320E RJ45 3 ) 110/220 V Ethernet backbone 75V HD1320E 45 HD1320E (3) HD1320E LED Tx LED 1 / 31 [ LED] ) 18
HelloDevice 1320/1320E/1321 422 HD1321 HD1321 DIP, HD1321,, RJ45 46 HD1321 46 HD1321 19
HelloDevice 1320/1320E/1321 43 431 IP HD132x 10BaseT, 47 HelloDevice - IP IP - IP HD132x DHCP, IP DHCP(Dynamic Host Configuration Protocol) HelloDevice IP DHCP(RFC2131) 20
HelloDevice 1320/1320E/1321 HelloDevice IP 0000, HelloDevice DHCP IP, HelloDevice Tx LED ( 31 [ LED] ) (1) DHCP DHCP HelloDevice IP, DHCP IP, Tx LED, HelloDevice IP (2) HelloDevice DHCP, DHCP HelloDevice DHCP HelloDevice IP IP, IP HelloDevice MAC 1 -IP IP HelloDevice IP IP, IP 1 MAC,, 6 byte HelloDevice MAC MAC 00-01-95 xx-xx-xx ) 00-01-95-01-aa-08, 00-01-95-01-02-01 21
HelloDevice 1320/1320E/1321 HelloDevice IP 47 HelloDevice IP (1) PC HelloDevice, [IP Address] [IP Address] DHCP IP ([DHCP Start], [DHCP Stop]), IP ([IP Find]) ([IP Clear]) (2) [Server Setting], DHCP HelloDevice DHCP [Router] IP IP 48 DHCP DHCP Server IP PC IP 22
HelloDevice 1320/1320E/1321 48 DHCP (3) [Add], DHCP 49 DHCP HelloDevice MAC IP MAC type MAC length HelloDevice, 1 6 MAC Address HelloDevice IC 49, MAC 00:01:95:04:0B:1B, HelloDevice IP 192168115 [Default Router], 48 DHCP 23
HelloDevice 1320/1320E/1321 Router IP (4) [Add], (2) IP (5) [DHCP start], DHCP [DHCP start] HelloDevice Utility Program DHCP Server [Status] Monitoring Listening DHCP request DB List HelloDevice IP [Status] Listening DHCP request " DHCP ACK sent [ 192168 115 ]" HelloDevice DB List HelloDevice Utility Program "DB Setting for DHCP" IP IP HelloDevice IP (6) HelloDevice TX LED HelloDevice IP, HelloDevice IP, [Status] DHCP ACK sent [ 192168 115 ] HelloDevice TX LED /, IP, [Status] DHCP ACK sent [ 192168 115 ], HelloDevice IP DHCP IP, It was Request to other DHCP server! Packet Discarded (7) ping, HelloDevice IP ping Command prompt, ping >> ping 192168115 >> Pinging 192168115 with 32 bytes of data: Reply from 192168115: bytes=32 time=10ms TTL=251 Reply from 192168115: bytes=32 time<10ms TTL=251 Reply from 192168115: bytes=32 time=10ms TTL=251, IP, (5), (6), (7) (8) [IP Find], HelloDevice IP 24
HelloDevice 1320/1320E/1321 [ IP Find], 410 HelloDevice MAC, [Find], Found IP IP 410 [IP Find] IP, [more], [System info], HelloDevice 411 [System Info], 41 25
HelloDevice 1320/1320E/1321 411 [System info] Group HellDevice Info TCP COM Client info TCP COM Server info MAC Address MAC IP Address IP Base TCP Port # TCP Current TCP Port # TCP Current TCP State TCP TCP State timer TCP State Power-ON timer IP setup mode IP TCP mode setup TCP Current TCP mode TCP Default Router IP MAC Address HD Server Client MAC IP Address HD Server Client IP TCP Port # HD Server Client MAC Address IP Address HD Server MAC HD Server IP HelloDevice Server Server/Client Mode HelloDevice Client Server/Client 26
HelloDevice 1320/1320E/1321 info TCP Port # HD Server 41 [System Info] Mode Note: 1) [IP Find], [IP Find] HelloDevice 441 2) [IP Find] LAN(Local Area Network), 432 IP IP, IP 0000 431 IP, IP, IP 192168115 192168118, IP (1) MAC IP 192168115 0000, IP HelloDevice MAC HelloDevice MAC HelloDevice, DHCP (2) IP [IP Address] [IP Clear], IP 412 HelloDevice MAC, [Clear] IP 192168115 HelloDevice IP 0000 Note: IP Mode Dynamic IP [IP Clear] IP Dynamic IP IP IP Mode 442 27
HelloDevice 1320/1320E/1321 412 IP Clear (3) IP HelloDevice TX LED IP, IP, HelloDevice TX LED / Note: DHCP, HelloDevice IP [Dynamic-IP], DHCP IP, TX LED IP 44 (4) IP IP 192168118, DHCP [Edit] IP /, 431 IP 28
HelloDevice 1320/1320E/1321 413 DHCP [Edit] IP 44 HD132x RS232 TCP/IP [Network Mode] Serial Interface [Serial], Parameter [Password] 414 Parameter (1) Password HelloDevice MAC IP Note: Parameter MAC LAN HelloDevie 29
HelloDevice 1320/1320E/1321 MAC Destination IP 255255255255 Parameter (WAN ) HelloDevice Parameter HelloDevice MAC Destination IP HelloDevice IP (2), [Send] [Send], HelloDevice,, 441 [Password], 1) HelloDevice, HelloDevice, ID : AAAAAAAA Password : AAAAAAAA,, 415, [Send] 415 30
HelloDevice 1320/1320E/1321 416, 416, [Change] Combo box,, [Send] 417 418 ID GOSENA00 HelloDevice 417 418 31
HelloDevice 1320/1320E/1321 HelloDevice ID / Password 8, / / ID / Password PWDini MAC, ID / Password [IP Clear], [IP Find], [Network mode], [Serial], [ID/Password / ],, Note: PWD 442 Network Mode 419 Network Mode HelloDevice MAC IP TCP TCP TCP (TCP ) TCP IP (TCP ) HelloDevice TCP/IP System info System info 419, HelloDevice HelloDevice TCP 32
HelloDevice 1320/1320E/1321 (1) IP Mode Static IP IP, IP, IP, [IP Clear] IP 432 IP Dynamic IP Dynamic IP,, DHCP IP DHCP IP DHCP, HelloDevice 24 DHCP IP, Dynamic IP, 24 IP Note: Dynamic IP [IP Clear] IP (2) Device Comm Server Mode TCP HelloDevice Port TCP, HelloDevice, TCP/IP HelloDevice RS232 HelloDevice TCP, TCP TCP TCP, TCP Client Mode HelloDevice RS232 TCP HelloDevice 1 5 Server & Client Mode HelloDevice TCP HelloDevice TCP TCP IP, TCP, TCP, Note: 33
HelloDevice 1320/1320E/1321 HD PORT RS232 TCP TCP, HelloDevice TCP TCP, 2000 ~ 65535 Server IP, Server PORT Server IP Server PORT HelloDevice TCP, HelloDevice, TCP IP 2000 ~ 65535 HelloDevice TCP (3) Notifier HelloDevice [Time Interval] IP IP HelloDevice, HelloDevice Dynamic IP, TCP (DHCP, TCP ), Dynamic IP, IP 24, HelloDevice IP, HelloDevice IP PC HelloDevice UDP 53 6, 6, [Time Interval] 1 30 443 RS232 RS232 HelloDevice RS232 420 RS232 [Serial] baud rate 150, 300, 600, 900, 1200, 2000, 2400, 3600, 4800, 7200, 9600, 19200, 38400 parity None, Even, Odd Data bits 5, 6, 7, 8 bits 34
HelloDevice 1320/1320E/1321 Stop bits 1, 1½, 2 bit handshake Œ Time None, H/W, X On/Off RS232, TCP/IP, 4, 100, Unlimited 420 [Serial], MAC 00:01:95:04:0B:1B, 9600 baud rate, Parity None, Data bit 8, Stop bit 1, Handshake None, Time 50 420 RS232 35
HelloDevice 1320/1320E/1321 5, TeraTerm Pro, HyperTerminal, Telnet RS232-TCP/IP, HelloDevice PC,, HelloDevice Dynamic IP, TCP, IP, TeraTerm Pro 51 HD1320E RS232 PC TCP/IP, RS232 1) PC RS232 HelloDevice RS232 RS232 3 Ethernet backbone TCP/IP TCP/IP HelloDevice 192168118 192168124 HD PORT 6001 RS232 (COM1 COM2) RS232 51 RS232-TCP/IP 36
HelloDevice 1320/1320E/1321 2) HelloDevice, HelloDevice TCP RS232 443 9600 baud rate Parity None Data bit 8 Stop bit 1 Handshake None, Time 50 3) PC RS232, TeraTerm Pro COM2 4) Tera term Pro COM2, HelloDevice RS232 52 TeraTerm RS232 5) [OK], 37
HelloDevice 1320/1320E/1321 6) PC TCP/IP 7) HelloDevice IP TCP TCP/IP 53 TCP/IP TCP/IP 8) TCP/IP, RS232 RS232, TCP/IP 54 TCP/IP RS232 Note: HelloDevice RS232 [Time] RS232 Hello Device TCP/IP, 2) 50 TCP/IP 38
HelloDevice 1320/1320E/1321 54 HelloDevice / 52 HelloDevice TCP/IP, 51 - HelloDevice TCP ( 51 Server ) - HelloDevice TCP ( 51 Client ) - HelloDevice ( 51 UDP Server ) 55 HelloDevice 39
HelloDevice 1320/1320E/1321, Visual C/C++ 60, (*dsw), Visual C/C++ 60 521 TCP, HelloDevice 51 TCP, HelloDevice, TCP/IP, 51, HelloDevice TCP 1) 51, HelloDevice RS232 PC RS232, RS232 2) Server Serverdsw Open Build, Run 3) HelloDevice IP 56 HelloDevice IP 192168115 56 40
HelloDevice 1320/1320E/1321 4), [Enter] PC RS232 TCP, TCP, TCP/IP, socket, connect, send //--------------------------------- // Process Serial data send //--------------------------------- void SerialSend() { char commandbuf[512]="" ; int commandlen ; int err ; // Re-Initialize TCP socket TCPSocketInit() ; // Read serial data //: just ASCII string excluding control characters //: Max size is limited to 512 bytes in this demo printf("\nenter the string you want to send to HelloDevice\n>>") ; scanf("%s", commandbuf) ; // Calc serial data length commandlen = strlen(commandbuf) ; // Send command to HelloDevice err = sendto ( sock, &commandbuf, commandlen, 0, (struct sockaddr*)&serveraddr, sizeof(serveraddr) ) ; if (err == -1 ) { perror("\nsend error\n"); exit (1); //-------------------------------- // Initialize TCP socket //-------------------------------- void TCPSocketInit() { char ipaddrstr[32] ; 41
HelloDevice 1320/1320E/1321 int clientlen ; int err ; // Enter HelloDevice IP address printf("enter HelloDevice IP address(xxxxxxxxxxxx) : ") ; scanf("%s", ipaddrstr) ; printf("\n\n") ; // Convert IP address from string to long ipaddr = decodeaddress(ipaddrstr) ; // Windows requires that winsock be initialized err = WSAStartup (0x0101, &lpwsadata); if ( err!= 0 ) { printf("\ncannot open WinSock???\n"); exit (1) ; else printf("1) WinSock Opened\n") ; // Create TCP socket clientlen = sizeof(serveraddr); sock = socket(af_inet, SOCK_STREAM, 0); if ( sock < 0 ) { perror("\nsocket error???\n"); exit (1) ; // Clear IP address fields memset( (char*) &addr, 0, sizeof( addr ) ); memset( (char*) &serveraddr, 0, sizeof( serveraddr ) ); // Set my IP address : TCP port 6001 addrsin_family = AF_INET; // You may use any port other than 6001 in host side! addrsin_port = htons(6001); addrsin_addrs_addr = INADDR_ANY; // Set HelloDevice IP address : TCP port 6001 serveraddrsin_family = AF_INET; serveraddrsin_port = htons(6001); printf("\tby Using port %d on the HelloDevice\n", ntohs(serveraddrsin_port) ); serveraddrsin_addrs_addr = htonl(ipaddr); // Connecting to HelloDevice err = connect( sock, (struct sockaddr*) &serveraddr, sizeof(serveraddr) ); if ( err == -1 ) { perror("\ncannot connect to HelloDevice???\n"); exit (1) ; printf("2)connected to HelloDevice, %d port\n", ntohs(serveraddrsin_port) ); 42
HelloDevice 1320/1320E/1321 //------------------------------ // Close TCP socket //------------------------------ void TCPSocketClose() { closesocket(sock) ; 522 TCP 51, HelloDevice TCP, TCP, TCP IP, HelloDevice TCP, RS232 HelloDevice, HelloDevice IP,,, HelloDevice, HelloDevice RS232, RS232, RS232 PC, RS232 HelloDevice, 1) 51, HelloDevice RS232 PC RS232, RS232 2) HelloDevice [Network Mode] [TCP mode] [Client], [Server IP, PORT] PC IP, 6001, 521 57 PC IP 1921681111, [Send] HelloDevice TCP, HelloDevice RS232 IP 1921681111 TCP 6001, HelloDevice RS232 43
HelloDevice 1320/1320E/1321 57 HelloDevice TCP 3) HelloDevice [Serial] [Serial Time Unlimited], HelloDevice TCP, RS232 TCP 58, Serial Time Unlimited, [Send] HelloDevice TCP, TCP 44
HelloDevice 1320/1320E/1321 58 HelloDevice [Serial] 4) Client Clientdsw Open Build, Run 5), RS232 [Received Data], HelloDevice, RS232 59 listen, bind, accept, socket, recv, sendto,, 521 //---------------------------------------- 45
HelloDevice 1320/1320E/1321 // Process listening : ProcessRecv called //---------------------------------------- void ProcessListen() { int clientlen; char chdumm; clientlen = sizeof(addrclient); memset((char*) &addrclient, 0, sizeof(addrclient)); while (1) { //------------------------------------------------------------ // accept an incoming connection attempt on the server socket //------------------------------------------------------------ sockclient = accept(sock,(lpsockaddr)&addrclient,&clientlen); if (sockclient == INVALID_SOCKET) { printf("\naccept error???\n"); printf("\nplease, try later(press ENTER)"); scanf("%c", &chdumm); break; else { printf("connected from client[%d%d%d%d]\n",addrclientsin_addrs_uns_un_bs_b1,addrclientsin_addrs_uns_un_bs_b2,addrclientsin_addrs_uns_un_bs_b3,addrclientsin_addrs_uns_un_bs_b4); //--------------------------------------------------------- // receives data from the client socket(hd1320) //--------------------------------------------------------- if(processrecv()) { // Exit Program break; else { // Continue Listen // Just close the client socket TCPSocketClose(CLOSE_CLIENT_SOCKET); memset((char*) &addrclient, 0, sizeof(addrclient)); //---------------------------------------------- // Process receive : socket recv function called // return 9 : exit program // 0 : continue listening //---------------------------------------------- int ProcessRecv() { char bufreceived[bufsize]; int ncountreceived = 0; int ncommand = 0; int nshowmenu = 0; memset(bufreceived,'\0',sizeof(bufreceived)); while(1) { //--------------------------------------------------------- // receives data from a connected socket(hd1320) //--------------------------------------------------------- ncountreceived = recv(sockclient,bufreceived,sizeof(bufreceived),0); if (ncountreceived == 0) { // HelloDevice closed the client socket printf("disconnected from client[%d%d%d%d]\n",addrclientsin_addrs_uns_un_bs_b1 46
HelloDevice 1320/1320E/1321,addrClientsin_addrS_unS_un_bs_b2,addrClientsin_addrS_unS_un_bs_b3,addrClientsin_addrS_unS_un_bs_b4); DisplayMenu(); scanf("%d", &ncommand); return ncommand; else if (ncountreceived < 0) { if (++nshowmenu == SHOWMENU) { DisplayMenu(); scanf("%d", &ncommand); return ncommand; else { continue; else { // received some data // Send echo to client if(!serialsend(bufreceived, ncountreceived)){ // Sending echo error printf("fail to send echo to client[%d%d%d%d]\n",addrclientsin_addrs_uns_un_bs_b1,addrclientsin_addrs_uns_un_bs_b2,addrclientsin_addrs_uns_un_bs_b3,addrclientsin_addrs_uns_un_bs_b4); DisplayMenu(); scanf("%d", &ncommand); return ncommand; printf("[received Data]%s\n", bufreceived); ncountreceived = 0; nshowmenu = 0; memset(bufreceived,'\0',sizeof(bufreceived)); //---------------------------------------- // Process sending serial data to HelloDevice // return : 1 - success, 0 - failure //---------------------------------------- int SerialSend(char* strreceived, int nreceived) { int err; char* pcommandbuf = (char*)malloc(nreceived + 2); memcpy(&pcommandbuf[0], strreceived, nreceived); // Send command to HelloDevice err = sendto ( sockclient, pcommandbuf, nreceived + 2, 0, (struct sockaddr*)&addrclient, sizeof(addrclient) ) ; free(pcommandbuf); if (err == -1 ) { return 0; return 1; 47
HelloDevice 1320/1320E/1321 //---------------------------------- // Initialize TCP server socket // return : 1 - success, 0 - failure //---------------------------------- int TCPServerSocketInit() { char chdummy; int err ; //----------------------------------------------------- // Initiate use of WS2_32DLL by a process //----------------------------------------------------- err = WSAStartup (0x0101, &lpwsadata); if ( err!= 0 ) { printf("\nfail to start up winsock???\n"); scanf("\nplease, try later(press ENTER)"); scanf("%c", &chdummy); return 0; else printf("winsock Opened\n") ; //----------------------------------------------------- // create a server socket //----------------------------------------------------- sock = socket(af_inet, SOCK_STREAM, 0); if ( sock < 0 ) { printf("\nsocket error???\n"); printf("\nplease, try later(press ENTER)"); scanf("%c", &chdummy); return 0; printf("server socket created\n") ; // Clear server IP address fields memset( (char*) &addr, 0, sizeof( addr ) ); // Set server IP address : TCP port 6001 addrsin_family = AF_INET; // You may use any port other than 6001 in host side! addrsin_port = htons(6001); addrsin_addrs_addr = INADDR_ANY; //----------------------------------------------------- // associate a local address with a socket //----------------------------------------------------- if(bind(sock,(lpsockaddr)&addr,sizeof(addr)) == SOCKET_ERROR) { printf("\nserver socket bind error???\n"); scanf("\nplease, try later(press ENTER)"); scanf("%c", &chdummy); return 0; printf("server socket bound\n") ; //----------------------------------------------------- // places a socket a state where it is listening for an // incoming connection 48
HelloDevice 1320/1320E/1321 //----------------------------------------------------- if(listen(sock,5) == SOCKET_ERROR) { printf("\nserver socket listen error???\n"); scanf("\nplease, try later(press ENTER)"); scanf("%c", &chdummy); return 0; printf("server socket listening for an incoming connection\n"); return 1; //------------------------------------------------------------------ // Close TCP socket // parameter //bcloseonlyclient : CLOSE_CLIENT_SOCKET(1) - close just client socket //CLOSE_ALL_SOCKET(0) - close all socket and clean up //------------------------------------------------------------------ void TCPSocketClose(int bcloseonlyclient) { //----------------------------------------------------- // close the client socket //----------------------------------------------------- if (sockclient!= INVALID_SOCKET) { closesocket(sockclient); sockclient = INVALID_SOCKET; if (!bcloseonlyclient) { //----------------------------------------------------- // close the server socket //----------------------------------------------------- closesocket(sock); //----------------------------------------------------- // terminate use of the WS2_32DLL //----------------------------------------------------- WSACleanup(); 523 HelloDevice Dynamic IP, TCP,, HelloDevice IP HelloDevice Dynamic IP, IP, HelloDevice IP, HelloDevice IP, HelloDevice IP IP, UDP (User Datagram Protocol), HelloDevice IP, HelloDevice Dynamic IP HelloDevice, HelloDevice, HelloDevice 49
HelloDevice 1320/1320E/1321 IP, LAN, IP LAN HelloDevice, IP, UDP 514 MAC, Local Port, IP IP 442 HelloDevice 14 OK (2 Byte)+ MAC (6 Byte) + Local Port(2 Byte) + IP (4 Byte) HelloDevice /************************************************************************** UDP-based data server sample program HelloDevice notifying message format : total 14 bytes data : The number in the parenthisis means the byte size 'O'(1)+'K'(1)+ MAC address(6) + local port number(2) + IP address(4) eg 4f-4b-00-01-95-04-04-01-17-71-c0-a1-a8-0f **************************************************************************/ #include <stdioh> #include <timeh> #include <winsockh> // Global Variable definition WSADATA lpwsadata; // Socket data structure SOCKADDR_IN addrfrom; int sock ; // Socket int byte_received ; // byte received struct sockaddr_in addr ; // My IP address // UDP Socket function void UDPSocketCreate() ; void UDPSocketRun() ; void UDPSocketClose() ; // Main function void main() { printf("udp Hello Device Program \n"); // 1) Socket Creation UDPSocketCreate() ; while(1) { 50
HelloDevice 1320/1320E/1321 // 2) Listen until any incoming data // 3) Receive if any incoming data // 4) Print data UDPSocketRun(); // 5) Close UDP Socket UDPSocketClose() ; //--------------------- // UDP Socket Creation //--------------------- void UDPSocketCreate() { // Windows requires that winsock be initialized if (WSAStartup (0x0101, &lpwsadata) == INVALID_SOCKET) { printf("\ncannot open WinSock???\n"); exit (1) ; else printf("winsock Openedwaiting\n") ; // Create Windows socket for UDP sock = socket(af_inet, SOCK_DGRAM,0); if (sock < 0) { perror("\nsocket error???\n"); exit (1) ; // Setupo the port configuration // UDP port : 514 addrsin_family = AF_INET; addrsin_port = htons(514); addrsin_addrs_addr = htonl(inaddr_any); // Launch UDP socket if (bind(sock,(lpsockaddr)&addr,sizeof(addr)) == SOCKET_ERROR) { printf("\n Socket error program terminated\n " ); exit(1); //--------------------- // UDP Socket Run //--------------------- void UDPSocketRun() { int naddrfromlen = sizeof(addrfrom); IN_ADDR infrom; char test_buff[300]; char dbuffer [9]; char tbuffer [9]; int i ; // Wait until it receives data byte_received = 51
HelloDevice 1320/1320E/1321 recvfrom(sock,test_buff,250,0,(lpsockaddr)&addrfrom,&naddrfromlen); if (byte_received==socket_error) { printf("\n Socket error program terminated\n"); exit(1); memcpy(&infrom, &addrfromsin_addr,4); // Calculate date & time _strdate( dbuffer ); printf( "\n Info was notified on %s ", dbuffer ); _strtime( tbuffer ); printf( "%s \n", tbuffer ); // Decode the incoming datagram printf("\n from %s \n\n MAC address: ", inet_ntoa(infrom) ); for(i=2; i<8; i++) printf("%2x ",(unsigned char)test_buff[i]); printf("\n Port # :"); for(i=8;i<10;i++) printf("%3x",(unsigned char)test_buff[i]); printf(" \n IP address :"); for(i=10;i<14;i++) printf(" %3d ",(unsigned char)test_buff[i]); printf("\n \n \n \n"); //--------------------- // UDP Socket Close //--------------------- void UDPSocketClose() { closesocket(sock); Visual C/C++ console application, 510 HelloDevice 52
HelloDevice 1320/1320E/1321 510 6 RS232-TCP/IP 61 TCP PC HelloDevice RS232, PC HelloDevice, RS232 TCP RS232 HelloDevice TCP [Client], RS232 HelloDevice TCP/IP TCP, TCP/IP RS232 HelloDevice TCP [Server] RS232, PC TCP/IP 53
HelloDevice 1320/1320E/1321 HelloDevice RS232, HelloDevice TCP/IP PC HelloDevice TCP [Server/Client], TCP, TCP, RS232,,, [Server] [Client], 611 TCP HelloDevice TCP TCP HelloDevice TCP/IP HelloDevice TCP,, TCP, RS232, TCP, TCP ( 32KB) TCP, RS232 IP, [RS232 ], TCP, TCP, TCP (Socket Close) 612 TCP HelloDevice TCP TCP HelloDevice TCP/IP TCP, HelloDevice TCP HelloDevice TCP, RS232 54
HelloDevice 1320/1320E/1321, TCP RS232, TCP, 5, RS232, TCP TCP,, [RS232 ],, TCP TCP, HelloDevice RS232, TCP (Socket Close) 613 TCP / HelloDevice TCP TCP HelloDevice TCP/IP TCP, TCP, RS232, TCP, TCP, RS232,,, 611 612 62 RS232 61 RS232 9 Pin 1 Received Line Signal Detector (Data Carrier Detect) Pin 2 Received Data Pin 3 Transmit Data Pin 4 Data Terminal Ready Pin 5 Signal Ground Pin 6 Data Set Ready Pin 7 Request To Send Pin 8 Clear To Send DCD RxD TxD DTR GND DSR RTS CTS 55
HelloDevice 1320/1320E/1321 Pin 9 Ring Indicator RI 61 RS232 9 HelloDevice RS232, HD1320/1320E RxD, TxD RS232 RTS, CTS, DTR, DSR, DTR, DSR, 61 RS232 1(DCD), 4(DTR), 6(DSR), RTS, CTS HelloDevice 3=TxD 2=RxD 5=GND 7=RTS 8=CTS HelloDevice HelloDevice RxD RxD RxD RxD TxD TxD TxD TxD GND GND GND GND RTS RTS RTS RTS CTS CTS CTS CTS DTR DTR DTR DTR DSR DSR DSR DSR DCD DCD DCD DCD (a) (b) 61 HD1320/1320E RS232 HD1321, RS232 5V TTL,, RXD, TXD, RTS, CTS, DTR, DSR 56