#include "..\..\..\SDK\SDK_ApossC.mc"
#include <SysDef.mh>
#define SERVER_IP_ADDRESS 192.168.1.81 // IP address of the server socket.
#define SERVERT_PORT_NUM 3000 // Port of the server socket.
#define CYCLE_TIME 1000 // ms → 0 to disable
void EthernetSendData_sendCycle(void);
void FunctionEthernetHandler(void);
long client_handle;
long status, status_old;
long main(void)
{
ErrorClear();
print("EthernetOpenClient with IP: ",SERVER_IP_ADDRESS," and Port: ",SERVERT_PORT_NUM);
client_handle = EthernetOpenClient(PROT_TCP, SERVER_IP_ADDRESS, SERVERT_PORT_NUM);
print(" returned handler 'client_handle' : ",client_handle);
if(client_handle<0)
{
print("Exit program");
Exit(0);
}
print("Wating for connection");
while(3 != status)
{
status = EthernetGetConnectionStatus(client_handle);
if(status != status_old)
{
status_old=status;
Delay(1);
}
}
InterruptSetup(ETHERNET, FunctionEthernetHandler, client_handle);
InterruptSetup(PERIOD, EthernetSendData_sendCycle, CYCLE_TIME);
while (1) {
status = EthernetGetConnectionStatus(client_handle);
if(status != status_old)
{
status_old=status;
Delay(1);
}
}
return(0);
}
void FunctionEthernetHandler(void)
{
long result;
wchar receiveArray[50]="";
wchar sendResponse[]="sendResponse";
arrayset(receiveArray,0,result);
result = EthernetReceiveTelegram(client_handle, receiveArray);
print("\nwe received a Ethernet Telegram at time: ", Time());
print("num of received data: ",result);
print("receiveArray: ", receiveArray);
return;
}
void EthernetSendData_sendCycle(void)
{
long result;
wchar sendArray[30] = "";
sprintf(sendArray, "EthernetSendData_sendCycle\n");
return;
}