Epson C32C824151 Technical Reference - Page 61

For Linux

Page 61 highlights

UB-E02 Technical Reference Guide 4.2.2 For Linux The program is a sample of printing "EPSON UB-E02" to a TM printer with the UB-E02 from Linux, through the ethernet connection. /* TCP00 programming sample for LINUX * HOW TO BUILD * cc ltcp.c */ #include #include int main(int argc, char* argv[]) { int sock; struct sockaddr_in addr; if (argc != 2) { printf("usage: ltcp \n"); exit(1); } /* create socket */ sock = socket(AF_INET, SOCK_STREAM, 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(9100); addr.sin_addr.s_addr = inet_addr(argv[1]); /* connect */ if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { perror("connect()"); } printf("connected\n"); /* send data */ send(sock, "EPSON\n", 6, 0); /* close socket */ close(sock); return 0; } Rev. A 4-5 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-5
Programming Samples
UB-E02 Technical Reference Guide
4.2.2
For Linux
The program is a sample of printing “EPSON UB-E02” to a TM printer with the UB-E02 from
Linux, through the ethernet connection.
/* TCP00 programming sample for LINUX
* HOW TO BUILD
*
cc ltcp.c
*/
#include <stdio.h>
#include <netdb.h>
int main(int argc, char* argv[])
{
int sock;
struct sockaddr_in addr;
if (argc != 2) {
printf("usage: ltcp <ip address>\n");
exit(1);
}
/* create socket */
sock = socket(AF_INET, SOCK_STREAM, 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(9100);
addr.sin_addr.s_addr = inet_addr(argv[1]);
/* connect */
if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
perror("connect()");
}
printf("connected\n");
/* send data */
send(sock, "EPSON\n", 6, 0);
/* close socket */
close(sock);
return 0;
}