dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 66 of 66

Thread: Bill Acceptor Integration

  1. #61
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Quote Originally Posted by 2kaud View Post
    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.



    How we set the data1,data2,data3 values?

  2. #62
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,877

    Re: Bill Acceptor Integration

    How we set the data1,data2,data3 values?
    Within your code as required. The datan values are determined by the message and documented. My example was just one easy way of doing this there are others. You now have all the info you need to interface with the Bill Acceptor. If you have issues with your Java code, then post it here and some Java Guru will provide advice/guidance.
    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++17 Compiler: Microsoft VS2019 (16.3.6)

  3. #63
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Quote Originally Posted by 2kaud View Post
    Within your code as required. The datan values are determined by the message and documented. My example was just one easy way of doing this there are others. You now have all the info you need to interface with the Bill Acceptor. If you have issues with your Java code, then post it here and some Java Guru will provide advice/guidance.
    Below is the java code :-

    Could any one can confirm is it the right way of setting the message format.


    // Message type
    BitSet messageType = new BitSet();
    messageType.set(1);//messageType.set(1);messageType.set(2);
    messageType.set(4);messageType.set(5);messageType.set(6);

    BitSet data;

    // first byte
    data = new BitSet();
    data.set(0); data.set(1);
    data.set(2); data.set(3);
    data.set(4); data.set(5);
    data.set(6);

    // second byte
    data.set(8); data.set(9);
    data.set(10); data.set(11);
    data.set(12); data.set(13);
    data.set(14);

    // thhird byte
    data.set(16);// bits.set(17);
    data.set(18); data.set(19);


    System.out.println("first bitset ="+data.toByteArray()[0]);
    System.out.println("second bitset ="+data.toByteArray()[1]);
    System.out.println("third bitset ="+data.toByteArray()[2]);


    byte[] bmsg = new byte[4096];


    // bmsg[0] = (byte) TwoWaySerialComm.STX;

    bmsg[1] = (byte) 5;

    bmsg[2] = messageType.toByteArray()[0];

    bmsg[3] = data.toByteArray()[0];

    bmsg[4] = data.toByteArray()[1];

    bmsg[5] = data.toByteArray()[2];

    // bmsg[6] =(byte) TwoWaySerialComm.ETX;

    System.out.println("array length== "+bmsg.toString().length());


    LRC = Calculation.calculateLRC(bmsg.toString());
    String toSendCommand = TwoWaySerialComm.STX+ bmsg.toString() + TwoWaySerialComm.ETX +(char) LRC;

  4. #64
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,855

    Re: Bill Acceptor Integration

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    It would help anyone looking at the code if the message's layout were included as a comment:
    Code:
    /*  Output message layout:
    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
    */
    Last edited by Norm; February 14th, 2019 at 06:42 AM.
    Norm

  5. #65
    Join Date
    Feb 2019
    Posts
    34

    Re: Bill Acceptor Integration

    Quote Originally Posted by Norm View Post
    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    Code:
      // Message type
                      BitSet messageType = new BitSet();
                      messageType.set(1);//messageType.set(1);messageType.set(2);
                      messageType.set(4);messageType.set(5);messageType.set(6);
                     
                      BitSet data;
                      
                 // first byte
                      data  = new BitSet();
                      data.set(0); data.set(1);
                      data.set(2); data.set(3);
                      data.set(4); data.set(5);
                      data.set(6); 
                      
              // second byte
                      data.set(8); data.set(9);
                      data.set(10); data.set(11);
                      data.set(12); data.set(13);
                      data.set(14); 
                   	 
                // thhird byte
                      data.set(16);// bits.set(17);
                      data.set(18); data.set(19);
                      
                      
                      System.out.println("first bitset ="+data.toByteArray()[0]);
                      System.out.println("second bitset ="+data.toByteArray()[1]);
                      System.out.println("third bitset ="+data.toByteArray()[2]);
    
                      
                      byte[] bmsg = new byte[4096];
                      
    
                    //  bmsg[0] = (byte) TwoWaySerialComm.STX;
                  
                      bmsg[1] = (byte) 5;
                      
                      bmsg[2] = messageType.toByteArray()[0];
                      
                      bmsg[3] =  data.toByteArray()[0];
                      
                      bmsg[4] = data.toByteArray()[1];
                      
                      bmsg[5] = data.toByteArray()[2];
                      
                   //   bmsg[6] =(byte) TwoWaySerialComm.ETX;
                    
                      System.out.println("array length== "+bmsg.toString().length());				   
                      
                      
                        LRC = Calculation.calculateLRC(bmsg.toString());
                        String toSendCommand = TwoWaySerialComm.STX+ bmsg.toString() + TwoWaySerialComm.ETX +(char) LRC;

  6. #66
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,855

    Re: Bill Acceptor Integration

    Having more than one statement on a line makes the code harder to read and understand.
    messageType.set(4);messageType.set(5);messageType.set(6);

    Why are you using the BitSet class? When setting bits past the size of a byte that makes more confusion. A byte has 8 bits: 0-7
    Also BitSet stores values little-endian which is reversed for me. For example the decimal number 12 (normally high-endian) would have a value of twentyone as little-endian.

    Can you add the comments showing the desired message format as shown in post#64?

    Why is bmsg size set to 4096? Isn't the message 11 bytes?
    Last edited by Norm; February 14th, 2019 at 09:23 AM.
    Norm

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)