EasyManua.ls Logo

Epson UB-E03 - Direct Printing by PORT9100; For Windows Console

Epson UB-E03
58 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
48
Direct Printing by PORT9100
For Windows Console
Theprogramisasampleofprinting“EPSONUBE03”toaTMprinterwiththeUBE03fromthe
Windowsshell,throughtheEthernetconnection.
/* TCP9100 programming sample for win32
* HOW TO BUILD
* cl wtcp.cpp wsock32.lib
*/
#include <stdio.h>
#include <winsock.h>
int main(int argc, char* argv[])
{
WSADATA data;
SOCKET sock;
struct linger Linger;
struct sockaddr_in addr;
if (argc != 2) {
printf("usage: wtcp <IP_ADDRESS>\n");
exit(1);
}
/* Initialize windows socket */
WSAStartup(0x0101, &data);
/* Create socket */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
fprintf(stderr, "Error socket(): %d\n", WSAGetLastError());
exit(1);
}
/* Set connection timeout */
Linger.l_onoff = 1;
Linger.1_linger = 60;
setsockopt(sock, SOL_SOCKET, SO_LINGER,(char*)&Linger,sizeof(struct linger));
/* 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, "EPSON|n", 6, 0);
/* gracefully close */
shutdown(sock, 1);/* SD_SEND*/
while(1){
char buf[64];
int n = recv(sock, buf, 64, 0);
if(n = SOCKET_ERROR||n==0)
break;
}
shtdown(sock, 2);/*SD_BOTH*/
/* close socket */
closesocket(sock);
return 0;
}

Table of Contents

Other manuals for Epson UB-E03

Related product manuals