Rev. A
4-11
Programming Samples
UB-E02 Technical Reference Guide
4.7.8 Programming Sample
4.7.8.1 For Windows Console
/* UDP3289 programming sample for win32
* HOW TO BUILD
* cc wudp.cpp wsock32.lib
*/
#include <stdio.h>
#include <winsock.h>
#define MAXBUF 512
char buf[MAXBUF];
int main(int argc, char* argv[])
{
WSADATA data;
SOCKET sock;
struct sockaddr_in addr;
int i, len, fromlen;
if (argc != 2) {
printf("usage: wudp <IP address>\n");
exit(1);
}
/* initialize windows socket */
WSAStartup(0x0101, &data);
/* Create socket */
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
fprintf(stderr, "Error socket(): %d\n", WSAGetLastError());
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
Summary of Contents for UB-E02
Page 2: ......
Page 4: ...ii Rev A Revision Information Revision Page Altered Items and Contents Rev A ...
Page 14: ...xii Contents Rev A ...
Page 26: ...2 10 Installation Rev A ...
Page 85: ......
Page 86: ...EPSON SEIKO EPSON CORPORATION Printed in Japan ...