Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.cpp not work #1

Open
alfredopons opened this issue Aug 25, 2018 · 12 comments
Open

test.cpp not work #1

alfredopons opened this issue Aug 25, 2018 · 12 comments

Comments

@alfredopons
Copy link

Hello,

I tried your test and read the coin acceptor perfectly. Read the currency table:

added EU-5-A with id 1
added EU-10-A with id 2
added EU-20-A with id 3
added EU-50-A with id 4
added EU-100-A with id 5
added EU-200-A with id 6

It also activates the coins:

checking: EU-5-A
EU-5-A is Wanted coin
checking: EU-10-A
EU-10-A is Wanted coin
checking: EU-20-A
EU-20-A is Wanted coin
checking: EU-50-A
EU-50-A is Wanted coin
checking: EU-100-A
EU-100-A is Wanted coin
checking: EU-200-A
EU-200-A is Wanted coin

But he doesn't really accept any coins. They're all rejected.

I've tried it with the devices: NRI G-13 and Eagle V2

Can you help me?
Thanks

@VJSchneid
Copy link
Owner

Hi alfredopons,
thanks for your issue.

Currently this program is only a work in progress and I couldn't test it with a variety of devices. But for now it works fine with the RM5-HD.

Maybe the issue lies in the poll loop to read the coin data. Because without polling, the coin acceptor wont accept any coins (that's at least the case with the RM5-HD).

At first you can replace the test with the following code, that should accept all coins in theory:

#include <cctalk.hpp>
#include <iostream>

cctalk::Bus::Command  makePollCommand() {
    cctalk::Bus::Command pollCommand;
    pollCommand.destination = 2;
    pollCommand.source = 1;
    pollCommand.header = cctalk::Bus::READ_BUFFERED_CREDIT_OR_ERROR_CODES;
    return pollCommand;
}

typedef std::function<void (std::optional<cctalk::Bus::DataCommand>)> Callback;

int main() {
    boost::asio::io_context ioContext;
    cctalk::Bus bus(ioContext);

    if (!bus.open("/dev/ttyUSB0")) {
        return 1;
    }

    Callback pollCallback, modifyStatusCallback, modifyMasterStatusCallback;

    unsigned char requestData[] = {255, 255};
    cctalk::Bus::DataCommand command;
    command.destination = 2;
    command.source = 1;
    command.header = cctalk::Bus::MODIFY_INHIBIT_STATUS;
    command.data = requestData;
    command.length = 2;

    bus.send(command);
    bus.receive(1, modifyStatusCallback);

    modifyStatusCallback = [modifyMasterStatusCallback, &bus, &command] (std::optional<cctalk::Bus::DataCommand> response) {
        command.header = cctalk::Bus::MODIFY_MASTER_INHIBIT_STATE;
        bus.send(command);
        bus.receive(1, modifyMasterStatusCallback);
    };

    modifyMasterStatusCallback = [pollCallback, &bus] (std::optional<cctalk::Bus::DataCommand> response) {
        auto pollCommand = makePollCommand();
        bus.send(pollCommand);
        bus.receive(1, pollCallback);
    };

    pollCallback = [pollCallback, &bus] (std::optional<cctalk::Bus::DataCommand> response) {
        auto pollCommand = makePollCommand();
        bus.send(pollCommand);
        bus.receive(1, pollCallback);
    };

    ioContext.run();
}

Unfortunately I could not test the code, but I hope it works!

I'm looking forward hearing from you.

@alfredopons
Copy link
Author

Hello,

In execution:

terminate called after throwing an instance of 'std::logic_error'
what(): invalid callback passed

@VJSchneid
Copy link
Owner

Oh that was my fault.

bus.receive(1, modifyStatusCallback);
needs to be called after modifyStatusCallback was assigned.

@alfredopons
Copy link
Author

If I reverse the order, it's still the same thing.

    modifyStatusCallback = [modifyMasterStatusCallback, &bus, &command] (std::optional<cctalk::Bus::DataCommand> response) {
        command.header = cctalk::Bus::MODIFY_MASTER_INHIBIT_STATE;
        bus.send(command);
        bus.receive(1, modifyMasterStatusCallback);
    };


    bus.receive(1, modifyStatusCallback);

terminate called after throwing an instance of 'std::logic_error'
what(): invalid callback passed

@VJSchneid
Copy link
Owner

Can you try to capture the captured callback in the three lambdas by reference?

@alfredopons
Copy link
Author

It doesn't work either. Does it work for you?

@VJSchneid
Copy link
Owner

I can not test it right now but the last commit worked fine for me.
Does it still raise the same std::logic_error exception or does the coin acceptor reject the coins?

@alfredopons
Copy link
Author

Hello,

I've tried it with the devices: NRI G-13 and Eagle V2 and Jofemar.
Reads the coins on all of them but does not enable the coins. All coins are rejected.

Can you test it with any peripherals other than RM5-HD?

I would like to test my acceptors in C++, but no Github project works, and there are many of them.

Thanks VJSchneid

@VJSchneid
Copy link
Owner

VJSchneid commented Aug 27, 2018

Unfortunately I am not in office for two weeks. Therefor I can not test any peripheral for now.

But maybe the error code from your CoinAcceptors can help.

To print the error code out you need to add the follwing line:

diff --git a/src/coinAcceptor.cpp b/src/coinAcceptor.cpp
index fd441cd..3f4ce27 100644
--- a/src/coinAcceptor.cpp
+++ b/src/coinAcceptor.cpp
@@ -250,6 +250,7 @@ namespace cctalk {
     void CoinAcceptor::handlePollLoop(std::optional<Bus::DataCommand> command) {
         if (command && command->length >= 3) {
             if (command->data[0] != lastCounter) {
+                std::cout << "buffered error-code: " << (int)(command->data[2]) << std::endl;
                 lastCounter = command->data[0];
                 unsigned char lastCoinId = command->data[1];
                 if (lastCoinId > 0 && lastCoinId <= supportedCoins.size()) {

That should at least print sth. when a coin is inserted.

@alfredopons
Copy link
Author

Thanks Viktor.

You enjoy your vacation now and we'll talk about it later.
Thank you very much.

@alfredopons
Copy link
Author

Hello Viktor,

have you been able to solve the problem?

Thanks

@VJSchneid
Copy link
Owner

Hello Alfredo,

unfortunately some other projects had priority at work. Therefor I didn't looked more closely into this since last time.
But can you test the current dev branch. There it should at least output some information on what is going on in the poll loop.

Maybe it's a timing problem, because the program does currently not delay its poll requests.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants