Taming of Mary-301MTM

    The device Maria-301MTM fell into the hands of ... This is the Ukrainian fiscal registrar - the printer of cash receipts.

    The protocol of this device is open and kindly provided by the manufacturer.
    Drivers for working with the device, I found only paid and rather old ones. Actually, this prompted the writing of the article.

    In stock: an old netbook with a COM port. The first thing I did was run putty and check 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 Mary.

    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 answers “WAIT”, “DONE”, “READY” to any command. "READY" - means readiness to accept the next team. There may be errors in the response. For example, "'HARDTXD' 'if the connection type specifies the wrong type of parity, or' 'SOFTPROTOC" is a sequence error command ...

    In general, vbscript to get Maria’s configuration 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)
      ret = MSComm1.Input
      txt.writeline "answ="+ret
      sendCmd = ret
    end function
    function initMaria()
      txt.writeline "init"
      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
      Set txt = Nothing
    end sub
    res = initComm()
    res = initMaria()
    'get maria configurarion
    res = sendCmd(txtcmd) 

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

    Printing a check:
    res = initComm()
    res = initMaria()
    'user login
    res = sendCmd(txtcmd) 
    'cancel check
    res = sendCmd(txtcmd) 
    'open check
    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
    res = sendCmd(txtcmd) 

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

    Also popular now: