Epson C32C824151 Technical Reference - Page 69

For Linux

Page 69 highlights

4.7.8.2 For Linux /* UDP3289 programming sample for LINUX * HOW TO BUILD * cc ludp.c */ #include #include #define MAXBUF 512 char buf[MAXBUF]; int main(int argc, char* argv[]) { int sock; struct sockaddr_in addr; int i, len; socklen_t fromlen; if (argc != 2) { printf("usage: udp3289 IP_ADDRESS\n"); exit(1); } /* create sockets */ sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { perror("socket()"); exit(1); } /* initialize the parameter */ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(3289); addr.sin_addr.s_addr = inet_addr(argv[1]); /* make a packet (PRINTER STATUS) */ buf[0] = 'E'; buf[1] = 'P'; buf[2] = 'S'; buf[3] = 'O'; buf[4] = 'N'; buf[5] = 'Q'; // PacketType (Q) buf[6] = 0x03; // DeviceType(3) buf[7] = 0x00; // DeviceNumber(0) buf[8] = 0x00; // Function(0010h) buf[9] = 0x10; buf[10] = 0x00; // Result buf[11] = 0x00; buf[12] = 0x00; // parameter length Length UB-E02 Technical Reference Guide Rev. A 4-13 Programming Samples

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84

Rev. A
4-13
Programming Samples
UB-E02 Technical Reference Guide
4.7.8.2 For Linux
/* UDP3289 programming sample for LINUX
* HOW TO BUILD
*
cc ludp.c
*/
#include <stdio.h>
#include <netdb.h>
#define MAXBUF 512
char buf[MAXBUF];
int main(int argc, char* argv[])
{
int sock;
struct sockaddr_in addr;
int i, len;
socklen_t fromlen;
if (argc != 2) {
printf("usage: udp3289 IP_ADDRESS\n");
exit(1);
}
/* create sockets */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
perror("socket()");
exit(1);
}
/* initialize the parameter */
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(3289);
addr.sin_addr.s_addr = inet_addr(argv[1]);
/* make a packet (PRINTER STATUS) */
buf[0]
= 'E';
buf[1]
= 'P';
buf[2]
= 'S';
buf[3]
= 'O';
buf[4]
= 'N';
buf[5]
= 'Q';
// PacketType (Q)
buf[6]
= 0x03; // DeviceType(3)
buf[7]
= 0x00; // DeviceNumber(0)
buf[8]
= 0x00; // Function(0010h)
buf[9]
= 0x10;
buf[10] = 0x00; // Result
buf[11] = 0x00;
buf[12] = 0x00; // parameter length Length