Send Data to POS from PC through rs232

Question:

I have a point of sale and I try send to POS the amount to be collected with the card through rs232. But don’t work and i not understand the documentation.

I tried to send exactly from documentation example , but POS stay in PROCESSING and return 02 = error . If i send good POS show amount and wait to touch with card , but in my case POS return to menu.

My script :

import serial
import crc16
import time

port =serial.Serial("COM7")
port.close()
port.open()

print(port.isOpen())

print("Port opened...")

if True:
    port.write(b'x05')
    response = port.read()
    print(ord(response))
    if response is not None:
        fdata = b'x02 00 04 a0 00 01 01 03 06 35'
        port.write(fdata)
        print(ord(port.read()))

Documentation :

enter image description here

Example Documentation :

enter image description here

In my case POS answer:

SEND : 05
RECEIVE : 06
SEND : 02 00 04 a0 00 01 01 03 06 35
RECEIVE : 02
Asked By: Viorel Vornicu

||

Answers:

Your problem is in this line:

fdata = b'x02 00 04 a0 00 01 01 03 06 35'

The right way to write a stream of bytes is:

fdataok = b'x02x00x04xa0x00x01x01x03x06x35'

As you can verify yourself:

>>> fdata == fdataok
False

An additional problem you might be running into is that you are probably reading data before you finish sending it. By default, you should be getting blocking writes but you might want to add a writeTimeout when you define your port to be completely sure.

And there is a last fundamental flaw in your code: you are reading just one byte with port.read(), you need to replace it that with port.read(port.inWaiting()) or port.read(x) with x the expected number of bytes (you don’t need to be precise, just aim to a higher number than what you expect). A read timeout might be also a good idea.

Answered By: Marcos G.
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.