SENA HD132x Series User Manual
Page 39

HD132x Series User Manual
39
documentations on Microsoft socket programming. Characters in bold font indicate main functions of
the socket such as socket, connect and 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] ;
int
clientLen ;
int
err ;
// Enter HelloDevice IP address
printf("Enter HelloDevice IP address(xxx.xxx.xxx.xxx) : ") ;
scanf("%s", ipAddrStr) ;
printf("\n\n") ;
// Convert IP address from string to long