"the safe door must be open to call command WFS_CMD_CDM_DISPENSE!" - xfs

This is the message i got when i tried to dispense money from Wincr Nixdorf ATM by using CDM320.exe which is a built-in tool of the ATM. In general, the safe door of an ATM must be closed for dispense to be done successfully. I don't know where this message has come from!
I wrote a source code for dispensing via XFS 3.00 API. It works on GSS ATM, but it doesn't work on the Wincor ATM.
How can i make sure that everything in the Wincor ATM is properly configured and working, like SPI, MSXFS.DLL file is good-versioned and properly works and everythings are compatible to work together? Since the CDM tester tool is not working, i doubt in the ATM itself instead of my program.

First you should check the Wincor manual(s) how to configure the CDM device to your expected behavior model.
This particular instance could indicate that the dispenser/ATM is in test mode and thus doesn't allow dispense unless the safe door is open (and possibly even the dispenser should be out of the safe).
Or maybe the error message is missing a work 'NOT' and your safe is not properly locked.
Even in this case the CDM configuration should do the trick.
PS. I don't have experience from Wincor HW so this might be totally off the mark as my experience come's from NCR HW.

Related

What happens when you call a test using HttpCalloutMock?

This is not a code/case specific question.
I am new to Apex, and I'm trying to test methods that do Callouts to external APIs. I understand that in order to test this method, I have to create a class that implements HttpCalloutMock and use it in my test.
However, I want to know: in the Test, when I call the actual method I'm testing, does a call go out to the API behind the scenes? Or is the data I'm putting in the mock the only data that gets passed around?
(I'm asking because, if the latter, wouldn't that mean these tests are extremely counterproductive and unnecessary?)
The dummy data you provided in the mock class will be dutifully returned. And yes, it's annoying, double work.
But how else could it be done? Really calling an external API might have bad consequences (sending "My Awesome Test Order!!!1one!eleven" to production fulfilment system would be a disaster, especially if you do it few times because deployment kept failing). And when such API would be down and you really, really need to deploy something to production - you shouldn't be a hostage of 3rd party server, even test one.
Instead of grumbling try to embrace it. Yes, it's rubbish. But this is your opportunity to test how your code handles different outputs. How it reacts when the API response is "HTTP 500 Internal Server Error", HTML instead of JSON or even there's no response, just timeout. The more solid you make it, the more confident you'll be.
Is it really that hard? Capture couple real messages & errors, remove sensitive data, implement some switch statement "if account number = 123 return this else return that" and you're done.
And yes, it essentially means implementing 3rd party's logic yourself. But well, with test-driven development you ideally would start with a dummy representation of their service anyway, something that's close enough to the API "contract" you have. And as a bonus - you get to shout at them when something suddenly breaks and you can prove it wasn't a change on your end.
In the end it's not too different from splitting work with another SF developer. "OK, I'll do the UI bit, you do the apex bit, here's the data interface we promise to use, see you in 1 week's time". How far can you trust the guy, eh? ;)

Is there a way to simulate the lack of internet connection in an Elixir test?

I am dealing with a coverage test of an command-line interface application developed in Elixir. The application is a client for tldr-pages and its functioning consists in a script built with escript. To perform the actions I use a case structure over an HTTPoison.get/1 function, in which I introduce the formatted url. In this case I compare the response to different kind of values, such as if the page exists, it shows the information; if the not, it report it to the user and then continue in another case to evaluate to others possibilities. At the end, the first case finish with two pattern to match errors, one for the lack of internet connection and another one for unexpected errors. The described structure is the next one:
case HTTPoison.get(process_url(os, term)) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
IO.puts(body)
{:ok, %HTTPoison.Response{status_code: 404}} ->
IO.puts(
"Term \"#{term}\" not found on \"#{os}\" pages\nExTldr is looking on \"common\" pages."
)
case HTTPoison.get(process_url("common", term)) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
IO.puts(body)
{:ok, %HTTPoison.Response{status_code: 404}} ->
IO.puts("Term not found on \"common\" pages.")
end
{:error, %HTTPoison.Error{reason: reason}} when reason == :nxdomain ->
raise NoInternetConnectionError
{:error, %HTTPoison.Error{reason: reason}} when reason != :nxdomain ->
raise UnexpectedError, reason
end
NoInternetConnectionError and UnexpectedError are exceptions defined in another file. Both patterns at the end works apparently nice, at least the first one:
{:error, %HTTPoison.Error{reason: reason}} when reason == :nxdomain ->
raise NoInternetConnectionError
However, as I said at the beginning of the question, I am dealing with a coverage test performed automatically with GitHub Actions and Coveralls with ExCoveralls in the dependencies. In this test I am receiving a warning for both raise/1 statements. Although I could be wrong understanding what means that, I understand this "missed lines" or uncovered lines are reported by Coveralls because I am not performing a test to cover this case. Thus I started to research how I could write a test to cover both conditions.
The most important issue is how to simulate the lack of internet connection in a test to cover this. I though about to develop a mock, but I do not find something useful for this case in some of the mocking packages for Elixir, like Mox. Then I found bypass, a very interesting package that I think it might be useful because it has down/1 and up/1 to close and start a TCP socket, so it makes possible to test what happens when HTTP server is down. But with this I have two issues:
A server down is not the same that the lack of internet connection by the user part.
I tried to applied this "down and up" mechanism and I did not accomplish it. I am not going to share it because I think it would not be the final solution by the first issue described.
I am not pretending an answer with the code that solves this problem, I am just trying to understand how this test should work and the logic I should follow to develop it. I am even researching Erlang documentation, because it is possible Erlang provides native functions to address it (for example, I am now reading the Erlang's Common Test Reference Manual, because may be there is something useful there).
Edit. What I commented I tried with bypass was to install the dependency, write a setup with bypass.open/0 and then write a test like the next one, in which I try to assert the capture output with capture_io/1:
test "lack of internet connection", %{bypass: bypass} do
Bypass.down(bypass)
execute_main = fn ->
ExTldr.main([])
end
assert capture_io(execute_main) =~ "There is not internet connection"
end
However, as I thought, it does not cover the possible situation of lack of internet, just the possibility to check when a server goes down.
Sidenote: I personally was always against being a slave of tools that are supposed to help the development. Coverage is a somewhat good metric, but the recommendations should not be treated as a must. Anyway.
I am not sure why you ruled Mox out. The rule of thumb would be: tests should not involve cross-boundary calls unless absolutely unavoidable. The tests going over the internet are nevertheless flaky: coverage would not tell you that, I would. What if the testing environment has no permanent internet access at all? Temporary connection issues? The remote is down?
So that is exactly why Mox was born. And, luckily enough, HTTPoison is perfectly ready to use Mox as a mocking library because it declares a behaviour for the main operation module, HTTPoison.Base.
All you need would be to make your actual HTTP client an injected dependency. Somewhat along these lines:
#http_client Application.get_env(:my_app, :http_client, HTTPoison)
...
case #http_client.get(process_url(os, term)) do
...
end
In config/test.exs you specify your own :http_client, and voilà—the nifty mocked testing environment is all yours.
Or, you might declare the mock straight ahead:
Mox.defmock(MyApp.HC, for: HTTPoison.Base)
I am also adept of boundaries on the application level calling 3rd-parties. That said, you might define your own behaviour for external HTTP calls you need and your own wrapper implementing this behaviour. That way mocking would be even easier, and you’ll get a benefit of easy changing the real client. HTTPoison is far from being the best client nowadays (it barely supports HTTP2 etc,) and tomorrow you might decide to switch to, say, Mint. It would be drastically easier to accomplish if all the code would be located in the wrapper.

Serial communication with Xtralien potentiostat not working?

I am trying to set up a potentiostat Xtralien by Ossila with LabView.
The way the instrument works in a string-in, string-out, so far so good.
The built-in code examples that are provided by the manufacturer contain firstly a string-in, string-out LabView program and secondly a preliminary console to record an I-V sweep (https://www.ossila.com/pages/basic-xtralien-commands-in-labview, https://www.ossila.com/pages/xtralien-x100-command-list). In the string interface, I can enter 'CLOI hello' and the device responds 'hello world', so far so good. If I proceed any further and send i.e. a 'smu1 measurev' command connecting to some photodiode, I just receive a near-zero value back, setting 'smu1 set voltage 0.5' or similar does not lead to an output voltage either. Running the sweep program over said photodiode gives noise in the µA range.
EDIT: All involved hardware components were double-checked.
Where am I doing something wrong? Is the error arising from communication errors or...? Has someone experienced this so far?
Received the answer from the Ossila support. The Xtralien X200 drivers were recently updated (http://files.ossila.com/source-measure-unit/Ossila-X200-SMU-Instr.zip), and you need to switch on each SMU channel sperately. This was implemented in a subVI in the Instrumentation -> X200.
Hope I helped all who get a similar problem in the future!

Can I use a USB pen drive with libusbdotnet

I have just started on libusbdotnet. I have downloaded the sample code from http://libusbdotnet.sourceforge.net/V2/Index.html.
I am using a JetFlash 4GB Flash drive (a libusb-win32 filter driver was added for this drive).
The ShowInfo code works perfectly, and I can see my device info with two endpoints. Following is the device info from pastebin
http://pastebin.com/2Jdph6bY
However, the ReadOnly sample code does not work.
http://pastebin.com/hNZaEt8N
My code is almost same as that from the libsubdotnet website. I have only changed the endpoint that UsbEndpointReader uses. I have changed it from Ep01 to Ep02, because I read that the first endpoint is a control endpoint used for configuration, access control and similar stuff.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
I always get the message "No more bytes!".
I thought that this is because of the absence of data, so I used the ReadWrite sample code.
http://pastebin.com/NiN5w9Jt
But here I also get "No more bytes!" message.
Interestly, the line
ec = writer.Write(Encoding.Default.GetBytes(cmdLine), 2000, out bytesWritten);
executes without errors.
Can pen drives be used for read write operations? Or is something wrong with the code?
A USB thumb drive implements the USB mass storage device class, which is a subset of SCSI. The specification is here.
You're not going to get anything sensible by just reading from an endpoint - you have to send the appropriate commands to get any response.
You have not chosen an easy device class to begin your exploration of USB - you may be better starting with something easier - a HID class device, perhaps (Mouse/Keyboard) though Windows does have enhanced security around mice and keyboards which may prevent you installing a filter.
If you meddle with the filesystem on the USB stick while it's mounted as a drive by Windows, you'll almost certainly run into cache-consistency problems, unless you're extremely careful about what kind of access you allow Windows to do.

GET or PUT to reboot a remote resource?

I am struggling (in some sense) to determine which HTTP method is more appropriate for rebooting a remote resource: GET or PUT?
On one hand, it seems more semantic to call http://tools.serviceprovider.net/canopies/d34db33fc4f3?reboot=true because one might want to GET a representation of a freshly rebooted canopy.
On the other hand, a reboot is not 'safe' (nor is it necessarily idempotent, but then a canopy or modem is not just a row in a database) so it might seem more semantic to PUT the canopy into a state of rebooting, then have the server return a 202 to indicate that the reboot was initiated and is processing.
I have been reading up on HTTP/1.1, REST, HATEOAS, and other related concepts over the last week, so I am still putting the pieces together. Could a more seasoned developer please weigh in and confirm or dispel my hunch?
A GET doesn't seem appropriate because a GET is expected, like you said, to be "safe". i.e. no action other than retrieval.
A PUT doesn't seem appropriate because a PUT is expected to be idempotent. i.e. multiple identical operations cause same side-effects as as a single operation. Moreover, a PUT is usually used to replace the content at the request URI with the request body.
A POST appears most appropriate here. Because:
A POST need not be safe
A POST need not be idempotent
It also appears meaningful in that you are POSTing a request for a reboot (much like submitting a form, which also happens via POST), which can then be processed, possibly leading to a new URI containing reboot logs/results returned along with a 303 See Other status code.
Interestingly, Tim Bray wrote a blog post on this exact topic (which method to use to tell a resource representing a virtual machine to reboot itself), in which he also argued for POST. At the bottom of that post there are links to follow-ups on that topic, including one from none other than Roy Fielding himself, who concurs.
Rest is definitely not HTTP. But HTTP definitely does not have only four (or eight) methods. Any method is technically valid (even if as an extension method) and any method is RESTful when it is self describing — such as ‘LOCK’, ‘REBOOT’, ‘DELETE’, etc. Something like ‘MUSHROOM’, while valid as an HTTP extension, has no clear meaning or easily anticipated behavior, thus it would not be RESTful.
Fielding has stated that “The REST style doesn’t suggest that limiting the set of methods is a desirable goal. [..] In particular, REST encourages the creation of new methods for obscure operations” and that “it is more efficient in a true REST-based architecture for there to be a hundred different methods with distinct (non-duplicating), universal semantics.”
Sources:
http://xent.com/pipermail/fork/2001-August/003191.html
http://tech.groups.yahoo.com/group/rest-discuss/message/4732
With this all in mind I am going to be 'self descriptive' and use the REBOOT method.
Yes, you could effectively create a new command, REBOOT, using POST. But there is a perfectly idempotent way to do reboots using PUT.
Have a last_reboot field that contains the time at which the server was last rebooted. Make a PUT to that field with the current time cause a reboot if the incoming time is newer than the current time. If an intermediate server resends the PUT, no problem -- it has the same value as the first command, so it's a no-op.
You might want to get the current time from the server you're rebooting, unless you know that everyone is reasonably time-synced.
Or you could just use a times_rebooted count, eliminating the need for a clock. A PUT times_rebooted: 4 request will cause a reboot if times_rebooted is currently 3, but not if it's 4 or 5. If the current value is 2 and you PUT a 4, that's an error.
The only advantage to using time, if you have a clock, is that sometimes you care about when it happened. You could of course have BOTH a times_rebooted and a last_reboot_time, letting times_rebooted be the trigger.