How to communicate with printer from ruby language?

18 views
Skip to first unread message

Sanjay Salunkhe

unread,
Jun 8, 2016, 5:35:27 AM6/8/16
to Ruby on Rails: Talk

I want to communicate with printer by using ruby language. i am using socket programming to communicate with printer. my printer ip is "192.168.24.687" and port number is "20000".

Below is the code that i am using to communicate with printer


require 'socket'
sock = TCPSocket.new('192.168.24.687', 20000)
sock.write 'MARK START'
sock.close


In the above code i am sending "MARK START" command to the printer which will turn printer ON , but it's not working. with above code i am able to established connection with remote server but not able to send "MARK START" command.

But the same is working with putty. with putty i am using connection type as "raw" and connecting to the printer.After connection is successful i can send command "MARK START" to putty and able to turn on printer.

I want to know why my code is not able to send "MARK START" command to printer??


Greg Navis

unread,
Jun 8, 2016, 5:47:50 AM6/8/16
to rubyonra...@googlegroups.com
A few ideas:

1. Bind netcat to a port and connect your script to it to see whether stuff is really being sent.
2. Maybe you should write "\r", "\n" or "\r\n" after "MARK START".
3. Maybe firewall is blocking you.
--
Greg Navis
I help tech companies to scale Heroku-hosted Rails apps.

Reply all
Reply to author
Forward
0 new messages