Files
storage_fresco/SCLS_tel.py
2019-05-23 13:36:01 +00:00

126 lines
5.1 KiB
Python
Executable File

#!/usr/bin/python
"""
Scanner (SCLS) - Telegram
.. module:: SCLS
.. _scls-content:
Scanner
=======
=============== ======== ======== ============================= ========================================================
ID Byte-Pos Type Value Description
=============== ======== ======== ============================= ========================================================
Sequence-Nr 0:2 SINT16 0..32767 Telegramcounter
Tel-Source 2:4 CHAR[2] ['TP','LV'] Source of Telegram (to be removed in next versions)
Tel-Destination 4:6 CHAR[2] ['TP','LV'] Destination of Telegram (to be removed in next versions)
Tel-Type 6:10 CHAR[4] 'SCLS' Ident of Telegram (prepared to multiplex Channels)
BoxNr 10:14 UINT32 '2147483647' BoxNr - PLC uses UINT32 by now so Max=2147483647
Positon 14:18 CHAR[4] '0001', 'RFZ1' Position of Scanner
Destination 18:20 SINT16 0..32767 Destination (e.g. to tell state / content of box)
=============== ======== ======== ============================= ========================================================
Positions
=========
A Scanner telegram leads to different actions according to the Position. So the positions are in several Domains.
Valid Positiondomains are. (every Position may have higher Numbers)
======== ==================== ===========================================================
Position Pos-Type Action
======== ==================== ===========================================================
'I001' I-Point No Action - just logging - future Usage
'RFZ1' Shelf access equ. | Depending on Destination (Beta State: ToDo declare dests)
| 0: Box from Pickuppostiion --> generate Transport
| 1: Box from Reefedslot (will be changed)
| 2: just logging
'C001' Commisioning Shelf | PLC generated BCL - Read for storages with virtual BoxNrs
| Dest contains slotNr and indicates box removal
'B001' Scanner at conveyors Just a Scanner read anywhere log or do special funcitons
'H001' Handheld Reader Delete from Storage, and further fuctions
just for PLC hosted Handheld readers.
======== ==================== ===========================================================
"""
__date__ = "2006/02/15"
__email__ = "michi@rosstein.de"
__version__ = "$Revision: 1.1 $"[11:-2]
from telegram import TELEGRAM, TEL_SCLS
# String representation for a DT TPDU
DT_STRING = \
"""\
Length: %d
Number: 0x%02x
Contained Data: %s
"""
def fromstring (data):
"""
Decode the binary representation of a SCLS_tel from the given
parameter and note the data in the instance of the object.
Parameters:
data: The binary form of the TELEGRAM
"""
tel = TEL_SCLS ()
tel.attrib['nr'] = (ord (data [0]) << 8) + ord (data [1])
tel.attrib['src'] = data [2:4]
tel.attrib['dst'] = data [4:6]
tel.attrib['type'] = data [6:10]
#tel.attrib['box_nr'] = (ord (data [10]) << 24) + (ord (data [11]) << 16) + (ord (data [12]) << 8) + ord (data [13]) #data [10:14].strip ()
tel.attrib['box_nr'] = data [12:12 + ord (data [11])]
tel.attrib['location'] = data [22:26].strip ().lstrip ('0')
tel.attrib['destination'] = (ord (data [26]) << 8) + ord (data [27])
return tel
class TEL_SCLS (TELEGRAM):
def __init__ (self, nr = 0, src = 'LV', dst = 'TP', loc = 123, box = 123, dest=123 , *args, **args2):
TELEGRAM.__init__(self)
self.code = TEL_SCLS
self.attrib['nr'] = nr
self.attrib['src'] = src
self.attrib['dst'] = dst
self.attrib['type'] = 'SCLS'
self.attrib['location'] = loc
self.attrib['box_nr'] = box
self.attrib['destination'] = dest
self.__recalclen ()
return
def identify (self):
"""
This method can be used to identify a TELEGRAM by string.
"""
return "LEBE TELEGRAM\n"
def __recalclen (self):
"""
Return the length of the TPDU. This function is for
internal use only!
"""
self.len = 2 + 4l
def __repr__ (self):
"""
Print a representation of the TPDU. Use this method via
`-pair to transfer it over the wire. This will just return
the header data and not the real data!
"""
# Note that the data is not included in the length
return "%c%c%c" % (2, self.code << 4, self.number) + self.data
def __str__ (self):
"""
Return a readable and quite verbose overview of the TPDU instance.
Use this for debugging purposes or if you're just curious.
"""
print self.attrib
string = self.identify () #+ DT_STRING % (self.len, self.number, self.data)
return string