CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 5 FirstFirst 12345 LastLast
Results 46 to 60 of 66
  1. #46
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    This is not another site. Its only pdf document location.

  2. #47
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    not another site
    Sorry, I see .ru in the URL. That is another site.


    Can you post here the parts of the doc that answers my questions?
    Norm

  3. #48
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Here is format,

    Message Format
    From the Host
    STX
    (02)
    Length
    (08H)
    Msg type
    and Ack#
    Data
    Byte 0
    Data
    Byte 1
    Data
    Byte 2
    ETX
    (03)
    Check
    Sum
    From the



    Format is changes thats why am asking you to check with url.
    Last edited by Manish009; February 13th, 2019 at 09:55 AM.

  4. #49
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    From the Host
    Is the PC considered the host?

    Does the contents of the list you posed consist of Strings?
    Does a String have a terminating character like \n or \r?
    Is there a response for each String the PC sends to the device?
    For example, if the PC sends: "STX\n" is the device expected to send a response?
    What would the response be?

    What does (02) mean?


    Here is format,
    What is that the format of?
    Norm

  5. #50
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Thats why am posting the EBDS document. I dont have knowledge of this.

  6. #51
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    I dont have knowledge of this.
    It should be discussed in the document.
    Have you read the document and considered my questions?

    If you have any specific questions about text in the document, post the text from the document with your questions.

    My experience with devices (GPS receivers) connected to a PC via a serial connection used protocols where the PC sent a request to the device and the device sent a response. Is that the way the device you are working with is supposed to work?
    Norm

  7. #52
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Bill Acceptor Integration

    The data sent/received is in the form of messages which have a defined format . There are 2 formats - from the PC (the host) to the device (the Acceptor) and one from the device to the PC.

    From the PC each message is 8 bytes

    1 byte STX (binary 2)
    1 byte binary 8 (length)
    1 byte message type
    3 bytes of data
    1 byte ETX (binary 3)
    1 byte checksum - XOR of the 5 bytes between the ATX and the ETX bytes

    From the device:
    1 byte STX (binary 2)
    1 byte binary for 11 (length)
    1 byte message type
    6 bytes of data
    1 byte ETX (binary 3)
    1 byte checksum - XOR of the 8 bytes between the ATX and the ETX bytes

    Sorry, but I can't help you with Java as I only use c/c++.
    Last edited by 2kaud; February 13th, 2019 at 01:26 PM. Reason: Corected layout
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #53
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    The From the device message contents shows 10 bytes but the length is supposed to be 11?

    8 bytes between the ATX and the ETX bytes
    Is ATX same as STX? Is there a byte missing?
    Last edited by Norm; February 13th, 2019 at 12:12 PM.
    Norm

  9. #54
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Hi 2Kaud,


    Could you please send me the communication code in c/c++. so that i can translate into java or test the device.

  10. #55
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Bill Acceptor Integration

    Quote Originally Posted by Norm View Post
    The From the device message contents shows 10 bytes but the length is supposed to be 11?


    Is ATX same as STX? Is there a byte missing?
    Sorry, my bad. There are 6 bytes of data and not 5!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #56
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    Thanks for that.
    Norm

  12. #57
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Bill Acceptor Integration

    From previous post, the java code for read was
    Code:
    {
                    int len = 0;
                    while ( ( data = in.read()) > -1 )
                    {
                        if ( data == '\n' ) {
                            break;
                        }
                        buffer[len++] = (byte) data;
                    }
                    System.out.print(new String(buffer,0,len));
                }
    I suggest in c++ something like this (NOT tried)

    Code:
    if (in.read() != 2)  // STX
       cout << "No start STX\n";
    else
        if (in.read() != 8)   // Length
            cout << "Bad length\n";
        else {
            int check = 8; // Length
            byte mess = in.read();  // Message code
            check ^= mess;
            for (int l = 0; l < 3; ++l) {
                buffer[l] = in.read(); // Read the data bytes
                check ^= buffer[l];// Computer check sum
            }
    
            if (in.read() != 3) // ETX
                cout << "No end ETX\n";
            else
                if (in.read() != check) // Checksum
                    cout << "Invalid checksum\n";
                else {
                   // Process mess/buffer as needed
                }
        }
    The code for sending would be something similar, but writing bytes rather than reading them.

    Another approach rather than indicting an error if first byte is not STX, is to read the input until a STX byte is received.

    Code:
    while (in.read() != 2);  // Loop until STX received
    Last edited by 2kaud; February 13th, 2019 at 02:47 PM. Reason: Tidied up code
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  13. #58
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Bill Acceptor Integration

    I write the code to do aread as a method that reads the message and returns an instance of a class that contains the message type and the 3 bytes of data. It would throw an InvalidMessageException if any of the checks failed.
    For the write there would be a method that would take the message type and the data to be written, build the message to send and write it.
    Norm

  14. #59
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Thanks 2krod

    But here am not seen the message format to be write on port.

  15. #60
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Bill Acceptor Integration

    Quote Originally Posted by Manish009 View Post
    Thanks 2krod

    But here am not seen the message format to be write on port.
    Output is somewhat easier. Consider (NOT tried)

    Code:
    byte arr[11] = {2, 11};
    arr[2] = mess;  // Set message byte
    arr[3] = data1;
    arr[4] = data2;
    arr[5] = data3;
    arr[6] = data4;
    arr[7] = data5;
    arr[8] = data6;
    arr[9] = 3;
    for (int i = 1; i < 9; ++i)
           arr[10] ^= arr[i];
    
    for (int i = 0; i < 11; ++i)
          out.write(arr[i]);
    This assumes that mess is the message and data1...data6 are the 6 data bytes.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 4 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured