-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcliFP550menu.py
More file actions
438 lines (377 loc) · 11.2 KB
/
cliFP550menu.py
File metadata and controls
438 lines (377 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import climenu
import inspect
#from serialtest_1Def import *
#import serialtest_1Def
import serial
import time
from commands_v1 import *
# print chr(SALE)
#print SUBTOTAL, TOTAL
def whoami():
cmd_name=inspect.stack()[1][3]
cmd_name=cmd_name[4:]
return cmd_name
def bcc(packet):
bcc=""
sum=0
for c in packet:
sum=sum+ord(c)
sum=sum-1
crc1=(sum&0x000f)+0x30
crc2=0x30+((sum&0x00f0)>>4)
crc3=0x30+((sum&0x0f00)>>8)
crc4=0x30+((sum&0xf000)>>12)
bcc=chr(crc4)+chr(crc3)+chr(crc2)+chr(crc1)
return bcc
def build_packet(cmd, data = ""):
# global seq_num
packet = ""
packet = packet + chr(STX) # \x01
lenbyte=0x20+4+len(data)
packet = packet + chr(lenbyte) #<< 0x20 + 4 + data.b.length
packet=packet+ chr(seq_num()) #'\x22' #SEQ
packet=packet+chr(cmd)
packet=packet +data
packet=packet+chr(PA1)
packet=packet+bcc(packet)
packet=packet+chr(ETX)
for character in packet:
print character, character.encode('hex'),';',
print '-->'
return packet
#Sequence number , svaki poziv inkrementuje, ako je seq_num(false) ne inkrementuje(zadrzava prethodni)
seq=0x1F
def seq_num(incr=True):
global seq
if incr:
seq += 1
if seq==0x7f:
seq=0x1f
return seq
# Waiting for FP response (ACK, NAK, packet)
def recv():
global pck_Data
global pck_Len
global pck_Cmd
global pck_Seq, pck_Sts
line= []
eot=0
bIx=0
print" RECEIVED packet from FP550"
while eot==0:
for c in port.read():
if c=='\x16':
print "ACK",
break
line.append(c)
bIx=bIx+1
#print len(line), hex(ord(c)),';;',
if c=='\x03' : # or c=='\x16':
eot=1
print 'eot'
#print line
str1 = "".join(line)
#str1=[:-3]
print "Article:"
print (repr(str1).replace(" ",""))
print 'bIx=', bIx
line=[]
elif c=='\x01':
bIx=1
break
elif bIx==2:
print "--->"
pck_Len=hex(ord(c))
#print 'LEN', hex(ord(c))
break
elif bIx==3:
pck_Seq=hex(ord(c))
#print'SEQ', hex(ord(c))
break
elif bIx==4:
pck_Cmd=hex(ord(c))
#print'CMD', hex(ord(c))
break
elif c=='\x04':
print 'Poz EndData-x04=',bIx
#print line[4:(bIx-1)]
bSt=bIx
str_data = "".join(line[4:(bIx-1)])
#print 'DATA Field:', #str_data
#print (repr(str_data).replace(" ",""))
pck_Data=repr(str_data).replace(" ","")
break
elif c=='\x05':
print 'Poz EndStatus -x05=',bIx
#str_data1 = "".join(line[bSt:(bIx-1)])
pck_Sts=line[bSt:(bIx-1)]
print 'STATUS Field:', line[bSt:(bIx-1)]
break
# break
# break
print line, 'out' # print what is received
def cmd_Get_Diag():
print "GET DIAG x47_______________________"
data=""
cmd1= 0x47 #GET_STATUS #\x4A
pack=build_packet(cmd1, data)
'''for character in pack:
print character, character.encode('hex'),';',
print '-->' '''
port.write(pack) #send packet
print "GET DIAG-Command -Sent"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Get_PIB():
print "GET PIB 0x63______________________"
data=""
cmd1= 0x63 #GET_PIB #\x63
pack=build_packet(cmd1, data)
''' for character in pack:
print character, character.encode('hex'),#';',
print '-->' '''
port.write(pack) #send packet
print "GET PIB-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
print 'Recv class packet data:', pck_Data
print 'LEN=', pck_Len
print 'SEQ=', pck_Seq
print 'Cmd=', pck_Cmd
print 'Status:', pck_Sts
port.close
def cmd_Last_Fwrite():
print "LAST_FWrite 0x77______________________"
data=""
cmd1= 0x6e #Last Fwrite#\x77
pack=build_packet(cmd1, data)
for character in pack:
print character, character.encode('hex'),';',
port.write(pack) #send packet
print "Last_Fwrite-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Read_Article():
global fn
# fn="F"
print "Read Artical0x6b______________________"
data=fn
cmd1= 0x6B #Read Article x6B
pack=build_packet(cmd1, data)
for character in pack:
print character, character.encode('hex'),';',
port.write(pack) #send packet
print "Read Artical-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Write_Article():
print "Write Artical 0x6b______________________"
# data="p'"+"\xc3\x31\x2c\x31\x30\x2c\xc0\xf0\xf2\xe8\xea\xe0\xeb"
usr_go=input ("Press enter to continue:")
data="P"+"\x80"+"00034,55,ROBA-AB"
# data="P" + chr(0xC0)+"1234,666,ROBA-AA"
print 'from write art:',data
cmd1= 0x6B #Write Article x6B
pack=build_packet(cmd1, data)
for character in pack:
print character, character.encode('hex'),';',
port.write(pack) #send packet
print "Write Artical-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Get_Tax():
print "GET TAXES _______________________"
usr_go=input ("Press 1 to continue:")
data=""
cmd1= 0x61 # ???GET_STATUS #\x4A
pack=build_packet(cmd1, data)
for character in pack:
print character, character.encode('hex'),';',
print '-->'
port.write(pack) #send packet
print "GET TAX-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Get_Status():
print "GET STATUS _______________________"
usr_go=1
usr_go=input ("Press enter to continue:")
data=""
cmd1=GET_STATUS #\x4A
pack=build_packet(cmd1, data)
''' for character in pack:
print character, character.encode('hex'),';',
print"WRITE PACKET"
print '-->' '''
port.write(pack) #send packet
print "GET STATUS-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
print 'Recv class packet data:', pck_Data
print 'LEN=', pck_Len
print 'SEQ=', pck_Seq
print 'Cmd=', pck_Cmd
print 'Status:', pck_Sts
port.close
def cmd_Paper_Move():
print "PAPER MOVE________________________"
cmd1=PAPER_MOVE #'\x2c'
data='3'
pack=build_packet(cmd1, data)
''' for character in pack:
print character, character.encode('hex'),';:',
print '-->' '''
port.write(pack) #send packet
print "PAPER MOVE-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
print 'Recv class packet data:', pck_Data
print 'LEN=', pck_Len
print 'SEQ=', pck_Seq
print 'Cmd=', pck_Cmd
print 'Status:', pck_Sts
port.close
def cmd_Non_Fiscal():
print "MACRO NON FISCAL___________________________"
cmd1=START_NON_FISCAL_DOC #0x26
data=''
pack=build_packet(cmd1, data)
port.write(pack) #send packet
print "start non fiscal Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
# ___________________
cmd1=PRINT_NON_FISCAL_TEXT
data='POPRAVLJENO********DUSAN'
print data
pack=build_packet(cmd1, data)
port.write(pack) #send packet
print "starting received buffer-TEXT non fiscal"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
#-_____________________
cmd1=end_NON_FISCAL_DOC # 0x27
data=''
pack=build_packet(cmd1, data)
port.write(pack) #send packet
print "Command SENT-end non fiscal"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
def cmd_Get_Date_Time():
#print "GET Date_TimeS _______________________"
print (whoami())
usr_go=input ("Press enter to continue:")
data=""
cmd1=0x3E #GET_Date_time \x3e
pack=build_packet(cmd1, data)
port.write(pack) #send packet
print "\n Transmited command:"
print whoami() ,"\n"
print 'SeqNum:',hex(seq_num(False)), "\n\n"
# Prijem odziva od FP
recv()
print 'Recv class packet data:', pck_Data
print 'LEN=', pck_Len
print 'SEQ=', pck_Seq
print 'Cmd=', pck_Cmd
print 'Status:', pck_Sts
port.close
def cmd_Get_Set_Tax():
usr_go=input ("Press enter to continue:")
print "GET SET TAX_______________________"
data=""
cmd1=0x53 #GET_Set_TAX \x53
pack=build_packet(cmd1, data)
''' for character in pack:
print character, character.encode('hex'),';',
print '-->' '''
port.write(pack) #send packet
print "GET SET TAX-Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
print 'Recv class packet data:', pck_Data
print 'LEN=', pck_Len
print 'SEQ=', pck_Seq
print 'Cmd=', pck_Cmd
print 'Status:', pck_Sts
port.close
def cmd_report_ART_All():
print "Print All articles from DB_ !! Warrning -Long Print !! _________"
usr_go=input ("Press enter to continue:")
data="1"
cmd1=0x6f #report art_all\x69
pack=build_packet(cmd1, data)
''' for character in pack:
print character, character.encode('hex'),';',
print '-->' '''
port.write(pack) #send packet
print "Report ARTICLE_ALL - Command SENT"
print 'SeqNum:',hex(seq_num(False))
# Prijem odziva od FP
recv()
# CLIMENU STARTS HERE
#**************************************
# Protocol starts here ****
ts=time.gmtime()
print(time.strftime("%c",ts))
port = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=14.0)
@climenu.menu()
def m_get_status():
'''Get STATUS'''
# TODO: Call the build scripts here!
print('FP 550 Status')
cmd_Get_Status()
port.close
@climenu.menu()
def m_get_date_time():
'''Get_Date_Time'''
# TODO: Call the build scripts here!
print('FP 550 DATE and Time')
cmd_Get_Date_Time()
port.close
@climenu.menu()
def m_get_Diag():
'''Get Diagnostic print'''
# TODO: Call the build scripts here!
print('FP 550 print Diagnostic data')
cmd_Get_Diag()
@climenu.menu()
def m_get_PIB():
'''Get PIB'''
# TODO: Call the build scripts here!
print('FP 550 PIB')
cmd_Get_PIB()
port.close
@climenu.menu()
def m_paper_Move():
'''Paper MOVE nn-redova'''
# TODO: Call the build scripts here!
print('FP 550 Paper move')
cmd_Paper_Move()
@climenu.menu()
def m_cmd_Get_Set_Tax():
'''Get all tax groups'''
# TODO: Call the build scripts here!
print('FP 550 Paper move')
cmd_Get_Set_Tax()
@climenu.menu()
def m_cmd_report_ART_All():
'''Print report All Articles from DB'''
# TODO: Call the build scripts here!
print('FP 550 cmd_Report All Articles')
cmd_report_ART_All()
# cmd_report_ART_All()
if __name__ == '__main__':
climenu.run()