Epson TM-T20II UB-R04 Technical Reference Guide - Page 50

Direct Printing by PORT 9100, For Windows Console

Page 50 highlights

Direct Printing by PORT 9100 For Windows Console The program is a sample of printing "EPSON UB-R04" to a TM printer with the UB-R04 from the Windows shell, through the Ethernet connection. TCP9100 programming sample for Win32 * HOW TO BUILD * cl tcp9100.c wsock32.lib */ #include #include int main(int argc, char* argv[]) { WSADATA data; SOCKET sock; struct sockaddr_in addr; if (argc != 2) { printf("usage: tcp9100 IP_ADDRESS\n"); exit(1); } /* Initialize windows sockets */ WSAStartup(0x0101, &data); /* Create sockets */ if ((sock = socket(AF_INET, SOCK_STREAM, 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(9100); addr.sin_addr.s_addr = inet_addr(argv[1]); /* connect */ if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { fprintf(stderr, "Error connect(): %d\n", WSAGetLastError()); exit(1); } printf("connected\n"); /* send data */ send(sock, "\x1b@EPSON UB-R04\x0a", 8, 0); /* close socket */ closesocket(sock); return 0 50

  • 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

50
Direct Printing by PORT 9100
For Windows Console
The program is a sample of printing "EPSON UB-R04" to a TM printer with the UB-R04 from the Windows
shell, through the Ethernet connection.
------------------------------------------------------------------------------------------------------------------
/* TCP9100 programming sample for Win32
* HOW TO BUILD
*
cl tcp9100.c wsock32.lib
*/
#include <stdio.h>
#include <winsock.h>
int main(int argc, char* argv[])
{
WSADATA data;
SOCKET sock;
struct sockaddr_in addr;
if (argc != 2) {
printf("usage: tcp9100 IP_ADDRESS\n");
exit(1);
}
/* Initialize windows sockets */
WSAStartup(0x0101, &data);
/* Create sockets */
if ((sock = socket(AF_INET, SOCK_STREAM, 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(9100);
addr.sin_addr.s_addr = inet_addr(argv[1]);
/* connect */
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "Error connect(): %d\n", WSAGetLastError());
exit(1);
}
printf("connected\n");
/* send data */
send(sock, "\x1b@EPSON UB-R04\x0a", 8, 0);
/* close socket */
closesocket(sock);
return 0;
}
------------------------------------------------------------------------------------------------------------------