Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECONNREFUSED when printing by network #421

Open
gzimbron opened this issue Mar 14, 2023 · 0 comments
Open

ECONNREFUSED when printing by network #421

gzimbron opened this issue Mar 14, 2023 · 0 comments

Comments

@gzimbron
Copy link

USB interface tested and worked.

But I'm getting this error while trying to print by Network interface:

Error: connect ECONNREFUSED 192.168.1.119:9100
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.1.119',
  port: 9100
}

Ping to printer:

➜  ~ ping 192.168.1.119
PING 192.168.1.119 (192.168.1.119): 56 data bytes
64 bytes from 192.168.1.119: icmp_seq=0 ttl=64 time=6.388 ms
64 bytes from 192.168.1.119: icmp_seq=1 ttl=64 time=7.135 ms
64 bytes from 192.168.1.119: icmp_seq=2 ttl=64 time=5.781 ms
64 bytes from 192.168.1.119: icmp_seq=3 ttl=64 time=7.053 ms
^C
--- 192.168.1.119 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 5.781/6.589/7.135/0.549 ms

Code:

const escpos = require('escpos');
escpos.Network = require('escpos-network');

const netPrint = (ip: string, text: string, encode: string, fontSize: number, port: number) => {
	const device = new escpos.Network(ip, port);

	const options = { encoding: 'GB18030' };
	const printer = new escpos.Printer(device, options);

	device.open(function (err: unknown) {
		if (err) {
			console.log(err);
			return;
		}

		printer
			.font('B')
			.align('LT')
			.style('NORMAL')
			.size(fontSize, fontSize)
			.marginBottom(1)
			.encode(encode)
			.text(text + '\n\n')
			.cut()
			.close();
	});
};

export default netPrint;

Anyone had this problem??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant