abplc5_senddf1.c

来自「在LINUX环境下」· C语言 代码 · 共 55 行

C
55
字号
#include "libabplc5.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/un.h>
#include <unistd.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>

struct ethernet_header senddf1 (struct _comm comm1, struct ethernet_header header, int hlen, int debug)
{

	byte junk[255],response[255];
	struct ethernet_header rcvd;
	int x,response_len;
	
	switch (comm1.mode)
	{
		case ETHERNET:
			if (debug==1)
			{
				memcpy (&junk, &header,hlen);
				printf ("Sending...\n");
				for (x=0; x<hlen; x++)
					printf ("%02X  ",junk[x]);
				printf ("\n\n");
			}
		
			write (comm1.handle, &header,hlen);
			
			response_len = read (comm1.handle, &response, 255);

			if (debug==1)
			{
				printf ("Received %d bytes back...\n",response_len);
				for (x=0;x<response_len;x++)
					printf ("%02X  ",response[x]);
				printf ("\n");
			}
	
			memcpy (&rcvd, &response, response_len);

			return rcvd;
	}
	

	return rcvd;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?