1

How can I send data to a listening Terminal ?!?! (see task)

Szenario is:

I have a terminal that is listening on a IP:PORT e.g. 192.168.1.100:12345

I create a socket and connect like

$socket = socket_create(AF_INET, SOCK_STREAM, 0);
$result = socket_connect($socket, $host, $port);

Now I want to write data to the socket. The data i have looks like:

0x06 0x01 0x07 0x04 0x00 0x00 0x00 0x00 0x00 0x69

actually the terminal should show up 0.69 cent in the display. But i need to send the data infront of the 0x69 too.

I'm sending the Data like

socket_write($socket, $data, strlen($data));

I have read some about a php pack() function and tried this...

$data = pack( "C", "\x06\x01\x07\x04\x00\x00\x00\x00\x00\x69" );

what i have also tried is

$data = pack("c","\x06\x01\x07\x04\x00\x00\x00\x00\x00\x69");//nothing happens
$data = "0x06 0x01 0x07 0x04 0x00 0x00 0x00 0x00 0x00 0x69";//nothing happens

but this doesn't do the thing.

I friend of mine worte a programm in c++ and it works easy.

TASK

Task is to send data in 8bit format and as hex.

EDIT

C++ Code

Dwza
  • 6,494
  • 6
  • 41
  • 73
  • I would try `pack("c");` (lowercased) – hek2mgl Aug 06 '14 at 10:47
  • I have seen applications which expect the data to be sent as a hex string, not binary. meaning you send the string(!) `"0x06 0x01 0x07 0x04 0x00 0x00 0x00 0x00 0x00 0x69"`.. Have you tried this? – hek2mgl Aug 06 '14 at 12:36
  • @hek2mgl yes, this was my first try but the terminal just does nothing :) should i provide you with the c++ code ? – Dwza Aug 06 '14 at 13:25
  • Can you debug the other end? Meaning the target computer? Can you show the C++ program from your friend? – hek2mgl Aug 06 '14 at 13:31
  • @hek2mgl i added the c++ code at the bottom of my post – Dwza Aug 06 '14 at 14:16
  • Having the C++ code, `pack('C')` should work. I would debug the traffic between the C++ program and the target device and compare it to the traffic between PHP and the target – hek2mgl Aug 07 '14 at 17:11
  • @hek2mgl so you mean a big `C` ? – Dwza Aug 07 '14 at 18:59
  • Yes, unsigned char -> `C` – hek2mgl Aug 07 '14 at 20:36
  • I suggested: `I would debug the traffic between the C++ program and the target device and compare it to the traffic between PHP and the target` .. Did you followed this? – hek2mgl Aug 08 '14 at 19:21
  • actually not. i dont have time at the moment for this. is a task on my work and now its weekend. ill check this next week as soon as i have time for this :) – Dwza Aug 08 '14 at 19:44
  • I'm with you! now it is weekend :) .. – hek2mgl Aug 08 '14 at 19:46

4 Answers4

2

Your authorization command (06 01): 0x06 0x01 0x07 0x04 0x00 0x00 0x00 0x00 0x00 0x69

is totally correct, your message is 7 bytes long (0x07) and the amount (data block field: 0x04) is 6 byte BCD-packed in Euro-cents with leading zeros (0x00 0x00 0x00 0x00 0x00 0x69). One byte is represented with two HEX characters, so the transmitted amount is: 69 Cent. Everything which has to do with the amount display format, is a configuration issue of the terminal itself.

See here for a free version of the zvt protocol

https://www.terminalhersteller.de/pdf/PA00P015_13.08_en.pdf

You can use a lot of programming languages to create a socket connection to a terminal but there are not so many 'full' implementations of the ZVT protocol... which you will need to make the communication complete. I recommend C#, Java or Node.js. It's also common sense to call the registration command (06 00) when you begin a communication, this includes the config-byte!

Uwe Köhler
  • 123
  • 1
  • 7
  • Little late, im do not work there anymore :D but thank you for your answere... may ill need it some day. May ill code a new interface... never know :D – Dwza Feb 11 '20 at 15:55
1

A little late, but maybe it helps somebody:

You can use hex2bin:

$data = "06010704000000000069";
socket_write($socket, hex2bin($data));

As mentioned in the answer above, you maybe need to send the REGISTRATION command (0600) first (once).

clic
  • 365
  • 1
  • 13
  • 1
    2 years later, still working in the same Company, still having the same problem. So actually it's never to late if there is no solution. :) i do have to rebuild this Szenario and will try this one... Thank you :D – Dwza Sep 14 '16 at 21:20
  • still havent tried this. Atm im very busy at work and the priority of some projects are higher so this has to wait :) but be sure, if its tested and it works, of course ill accept this answere :D – Dwza Nov 03 '16 at 09:34
0

Maybe you should sent command 06 00 first, before 06 01?

mobiledev Alex
  • 2,228
  • 2
  • 28
  • 30
0

In my case, it worked well with the following: $data = "\x06\x01\x0f\x04\x00\x00\x00\x00\x00\x69\x19\x40\x06\x04\x40\x02\xff\x00";