gnetplus Module

Module for interfacing with the PROMAG card reader using the GNetPlus® Protocol.

Usage:

>>> from gnetplus import Handle
>>> handle = Handle("/dev/ttyUSB0")
>>> print "S/N: " + hex(handle.get_sn())
exception gnetplus.GNetPlusError[source]

Bases: exceptions.Exception

Exception thrown when receiving a ResponseMessage with function = ResponseMessage.NAK

class gnetplus.Handle(port, baudrate=19200, deviceaddr=0)[source]

Bases: object

Main class used for interfacing with the card reader.

Parameters:
  • port – String containing name of serial port, e.g. /dev/ttyUSB0
  • baudrate – Baudrate for interfacing with the device. Don’t change this unless you know what you’re doing.
  • deviceaddr – Integer containing the device address. Defaults to 0.
get_sn()[source]

Get serial number of the card currently scanned.

Returns:16-bit integer containing serial number of the scanned card.
get_version()[source]

Get product version string. May contain null bytes, so be careful when using it.

Returns:Product version string of the device connected to this handle.
readmsg(sink_events=False)[source]

Reads a message, optionally ignoring event (EVN) messages which are device-driven.

Parameters:sink_events – Boolean dictating whether or not events should be ignored.
sendmsg(function, data='')[source]

Constructs and sends a QueryMessage to the device

Parameters:
  • function (int) – message function (0-255, see Message.function)
  • data (str) – message data
set_auto_mode(enabled=True)[source]

Toggle auto mode, i.e. whether the device emits events when a card comes close.

Parameters:enabled – Whether to enable or disable auto mode.
wait_for_card()[source]

Block until card is present at the device. Does not check if a card is already present before entering the function.

exception gnetplus.InvalidMessage[source]

Bases: exceptions.Exception

class gnetplus.Message(address=0, function=None, data='')[source]

Bases: object

Base message class for representing a message

Parameters:
  • address (int) – Device Address (0-255, default 0)
  • function (int) – Function of this message
  • data (str) – Payload of this message
SOH = 1
static gencrc(msgstr)[source]

Generate CRC for the string msgstr

Parameters:msgstr – string containing data to be checksummed
Returns:16-bit integer containing CRC checksum
classmethod readfrom(serial)[source]

Constructs one message from serial

Parameters:serial – serial.Serial interface to read message from
Return type:Message instance
sendto(serial)[source]

Sends this message to serial

Parameters:serial (serial.Serial) – Serial interface to send this message to
class gnetplus.QueryMessage(address=0, function=None, data='')[source]

Bases: gnetplus.Message

A query message to be sent from host machine to card reader device. Magical constants taken from protocol documentation.

ACCESS_CONDITION = 41
ADD_RECORD = 15
ANALOG_INPUT = 19
ANTI_COLLISION = 33
AUTHENTICATE = 35
AUTHENTICATE_KEY = 46
AUTO_MODE = 63
CLASSNAME = 6
CREATE_VALUE_BLOCK = 40
DEBUG = 29
DI = 18
DO = 17
ECHO = 24
ENABLE_AUTO_MODE = 25
ERASE_ALL_RECORDS = 14
GET_ACCESS_CONDITION = 45
GET_DATETIME = 8
GET_FIRST_RECORD = 12
GET_NEXT_RECORD = 13
GET_NODE = 21
GET_REGISTER = 9
GET_SECOND_SN = 44
GET_SECTOR = 61
GET_SN = 22
GET_TIME_ADJUST = 26
GET_VERSION = 1
GO_TO_ISP = 31
HALT = 42
LOGOFF = 4
LOGON = 3
POLLING = 0
READ_BLOCK = 36
READ_VALUE = 39
RECORD_COUNT = 11
RECOVER_ALL_RECORDS = 16
REQUEST = 32
REQUEST_ALL = 47
RESERVE = 24
RESET = 30
RESTORE = 52
RF_POWER_ONOFF = 62
SAVE_KEY = 43
SELECT_CARD = 34
SET_DATETIME = 7
SET_PASSWORD = 5
SET_REGISTER = 10
SET_SLAVE_ADDR = 2
SET_TIME_ADJUST = 28
SET_VALUE = 38
SET_VALUEEX = 50
SILENT_MODE = 23
THERMOMETER = 20
TRANSFER = 51
WRITE_BLOCk = 37
class gnetplus.ResponseMessage(address=0, function=None, data='')[source]

Bases: gnetplus.Message

Message received from card reader

ACK = 6
EVN = 18
NAK = 21
to_error()[source]

Construct a GNetPlusError for NAK response.

Returns:Constructed instance of GNetPlusError for this response

Project Versions

Previous topic

Welcome to gnetplus’s documentation!

This Page