📜 ⬆️ ⬇️

The Taming of Mary-301MTM

I got into the hands of the device Maria-301MTM ... This is a Ukrainian fiscal registrar - a cashier receipt printer.
image

The protocol of this device is open and kindly provided by the manufacturer.
I found only paid and rather old drivers for working with the device. Actually this led to the writing of the article.

Available: an old netbook with a COM port. First of all, I launched the putty and checked the connection. Sweat settings parity: Even; stopbit: 2; speed: 57600 pass two letters “U” and get “READY”. The protocol works, the port is alive. On the netbook from previous experiments installed mscomctl.ocx . This set is quite enough to write a service console for Maria.
')
Transport protocol:
1. commands: <start> <command_and_parameters> <length> <end>;
2. Answer: <start> <information> <length> <end>,
where <start> = chr (253), <end> = chr (254). The length of the command can be no more than 255 characters.


The printer responds to any command with "WAIT", "DONE", "READY". “READY” means readiness to accept the next command. There may be errors in the response. For example, "'HARDTXD' 'if the connection parameters contain the wrong type of parity, or"' SOFTPROTOC "- command sequence error ...

In general, vbscript to get the configuration of Mary looks like this:
dim MSComm1 dim txt function fillcmd(txtma) ret = chr(253) & txtma & chr(len(txtma)+1) & chr(254) fillcmd = ret end function function sendCmd(cmdTxt) ret = "" txt.writeline "cmd="+txtcmd MSComm1.Output = fillcmd(txtcmd) WScript.Sleep(100) ret = MSComm1.Input txt.writeline "answ="+ret sendCmd = ret end function function initMaria() txt.writeline "init" MSComm1.Output="U" WScript.Sleep(1) MSComm1.Output="U" WScript.Sleep(20) rez = MSComm1.Input txt.writeline "answ="+rez initMaria = rez end function function initComm() Set MSComm1=CreateObject("MSCOMMLib.MSComm") MSComm1.Settings = "57600,e,8,2" MSComm1.CommPort = 2 MSComm1.InBufferCount = 0 MSComm1.PortOpen = True MSComm1.DTREnable = True set fso = CreateObject("Scripting.FileSystemObject") set txt = fso.CreateTextFile("maria.log") initComm = "Ready" end function sub closePort() MSComm1.DTREnable = False MSComm1.PortOpen = False Set MSComm1 = Nothing txt.close Set txt = Nothing end sub res = initComm() res = initMaria() 'get maria configurarion txtcmd="CONF" res = sendCmd(txtcmd) closePort() 

Useful features:
initComm () - opens the port and log file
fillcmd (txtma) - surrounds text command with special protocol characters

Print check:
 res = initComm() res = initMaria() 'user login txtcmd="UPAS111111111112345" res = sendCmd(txtcmd) 'cancel check txtcmd="CANC" res = sendCmd(txtcmd) 'open check txtcmd="PREP0" res = sendCmd(txtcmd) 'add line txtcmd="FISC"&" "&"000003000"&"000001000"&"00003"&"10"&_ "02000"&"000000"&"000000"&"000000"&"000000"&"000000"&"000000"&"000000"&"0001" '+"&'" "&" "&"" res = sendCmd(txtcmd) 'close check txtcmd="COMP"&"0000003000"&"0000000000"&"0000000000"&"0000000000"&"0000000000"&"0000003000" res = sendCmd(txtcmd) closePort() 


This code is enough to print checks, reports from 1C, ACESS, EXCEL
I think to write a driver using the nativ-API to replace the old OLE32 ...

Source: https://habr.com/ru/post/199066/


All Articles