B4J Question Socket and asynstreams with ATM Terminal

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
i am writing an application (B4J) to send payment to a Ingenico atm Terminal (PinPAD)
I send the comand to pay, for instance 2.80 € and the ATM respondes by placing that value in the visor and asking for the card.
STRING TO SEND TO The ATM : S00000028000000000000000000000000
so far so good, then I cancel ou finish the operation in the PinPAD and I receive the propper data in B4J
But if I try to do another payment, i get a wrong amount size in the pinpad's reply and cancels the operation.
I talked to the uys in the ATM factory and they say that i have to clear the buffer beetween comms. or to send a byte with 0 at the end of the comms.
It is clearly a buffer problem, because if i close the App and restart it the ATM works well again.
Any suggestions ?

how can i clear the Outputstream ? or how can i send the byte with 0 in the data to send.

B4X:
FirstChar="S"
Service="0"
Dim Amount2Pay As String = NumberFormat2(TotalPayment,1,2,2,False)
Dim Line2Send As String =$"${FirstChar}${Service}${Amount2Pay}${DummyString}"$
Log("MB:" & Line2Send)
Dim Data() As Byte
Data = Line2Send.GetBytes("UTF8") 

If MB_Status = True Then
    MB_InOut.Write(Data) ' MB_InOut is the AsynStreams object
End If

Thanks
 

Daestrum

Expert
Licensed User
Longtime User
You could probably add Chr(0) to the end of the Line2Send
B4X:
Dim Line2Send As String =$"${FirstChar}${Service}${Amount2Pay}${DummyString}"$ & Chr(0)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Thanks Erel,
my bad.
But still doesn't work.
If restart the Application and send the purchase it works, but one purchase after the other, I get the error, either with the BytesBuilder or the added Chr(0) solutions. :(
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Could try to send the 0 separately.
B4X:
If MB_Status = True Then
    MB_InOut.Write(Data) ' MB_InOut is the AsynStreams object
    MB_InOut.Write(Array As Byte(0))
End If
Or
B4X:
If MB_Status = True Then
    MB_InOut.Write(Array As Byte(0))
    MB_InOut.Write(Data) ' MB_InOut is the AsynStreams object
End If
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Could try to send the 0 separately.
B4X:
If MB_Status = True Then
    MB_InOut.Write(Data) ' MB_InOut is the AsynStreams object
    MB_InOut.Write(Array As Byte(0))
End If
Or
B4X:
If MB_Status = True Then
    MB_InOut.Write(Array As Byte(0))
    MB_InOut.Write(Data) ' MB_InOut is the AsynStreams object
End If

Already did. nothing works
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
now, they say that I have to append a buffer of 500 bytes initialized with zeroes. How can I do that ?

B4X:
bb.Initialize
bb.Append(Line2Send.GetBytes("UTF8")).Append(Array As Byte(0)) ' but with 500 bytes
Dim Data() As Byte = bb.ToArray
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
now, they say that i have to append a buffer of 500 bytes initialized with zeroes. How can I do that ?
B4X:
bb.Initialize
bb.Append(Line2Send.GetBytes("UTF8"))
for i = 1 to 500
bb.Append(Array As Byte(0))
next
Dim Data() As Byte = bb.ToArray
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Should also work
B4X:
Dim bytes(500) As Byte ' byte array initializes to zeroes
bb.Initialize
bb.Append(Line2Send.GetBytes("UTF8")).Append(bytes)
Dim Data() As Byte = bb.ToArray
 
Upvote 0
Top