Class: Driver::Datecs::Fp550

Inherits:
Extface::Driver::Base::Fiscal
  • Object
show all
Includes:
Extface::Driver::Datecs::CommandsV1
Defined in:
app/models/extface/driver/datecs/fp550.rb

Defined Under Namespace

Classes: Frame

Constant Summary collapse

NAME =
'Datecs FP550 (Serial)'.freeze

Instance Method Summary collapse

Instance Method Details

#build_packet(cmd, data = "") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/extface/driver/datecs/fp550.rb', line 33

def build_packet(cmd, data = "")
  "".b.tap() do |packet|
    packet << STX                     #Preamble. 1 byte long. Value: 01H.
    packet << 0x20 + 4 + data.length  #Number of bytes from <01> preamble (excluded) to <05> (included) plus the fixed offset of 20H
    packet << sequence_number         #Sequence number of the frame. Length : 1 byte. Value: 20H – FFH.
    packet << cmd                     #Length: 1 byte. Value: 20H - 7FH.
    packet << data                    #Length: 0 - 218 bytes for Host to printer
    packet << PA1                     #Post-amble. Length: 1 byte. Value: 05H.
    packet << Frame.bcc(packet[1..-1])#Control sum (0000H-FFFFH). Length: 4 bytes. Value of each byte: 30H-3FH
    packet << ETX                     #Terminator. Length: 1 byte. Value: 03H.
  end
end

#check_status ⇒ Object



14
15
16
17
18
# File 'app/models/extface/driver/datecs/fp550.rb', line 14

def check_status
  flush #clear receive buffer
  fsend(Info::GET_STATUS, 'X') # get 6 bytes status
  errors.empty?
end

#fsend(cmd, data = "") ⇒ Object

return data or nil



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/extface/driver/datecs/fp550.rb', line 20

def fsend(cmd, data = "") #return data or nil
  packet_data = build_packet(cmd, data) #store packet to be able to re-transmit it with the same sequence number
  invalid_frames = 0 #counter for bad responses
  nak_messages = 0 #counter for rejected packets (should re-transmit the packet)
  push packet_data #send packet
  begin
    errors.clear #start with slate clean
    if resp = frecv(RESPONSE_TIMEOUT)
      
    end
  end
end

#handle(buffer) ⇒ Object



7
8
9
10
11
12
# File 'app/models/extface/driver/datecs/fp550.rb', line 7

def handle(buffer)
  if i = buffer.index(/[\x03\x16\x15]/)   # find position of frame possible delimiter
    rpush buffer[0..i]                    # this will make data available for #pull(timeout) method
    return i+1                            # return number of bytes processed
  end
end

#human_status_errors(status) ⇒ Object

6 bytes status



52
53
54
55
56
57
58
59
# File 'app/models/extface/driver/datecs/fp550.rb', line 52

def human_status_errors(status) #6 bytes status
  status_0 = status[0].ord
  errors.add :base, "Fiscal Device General Error" unless (status_0 & 0x20).zero?
  errors.add :base, "Invalid Command" unless (status_0 & 0x02).zero?
  errors.add :base, "Date & Time Not Set" unless (status_0 & 0x04).zero?
  errors.add :base, "Syntax Error" unless (status_0 & 0x02).zero?
  status_1 = status[1].ord
end

#paper_cut ⇒ Object



46
47
48
49
50
# File 'app/models/extface/driver/datecs/fp550.rb', line 46

def paper_cut
  device.session('Paper Cut') do |s|
    s.push build_packet(Printer::PAPER_CUT)
  end
end