Communicating with an Artema Hybrid CC Payment device is actually deceptively simple.
The documentation that I received was in German exclusively, so this took a bit of work to get going, but once you have it down it’s very easy. The device is connected via it’s POS connection Serial->RJ45 connection to a Serial->USB (FTDI chipset) converter that gets plugged into a usb port. You use the standard open, read, write and close functions.
The Artema Hybrid constantly communicates with your system, so you’ll need to create a QThread to run in the background reading from the device once every second. The Artema Hybrid will send you an ENQ (0×05) and you need to respond with either an ACK (0×06) or an STX (0×02).
I can’t put the source code for this up directly, but I can give you some basic pseudo code. But considering that all of this is really straighforward and small, the pseudo code is actually very close to the real code.
The member variable running is just there so we can control the reading of data, and we can easily shutdown the thread by setting that to false, and it will exit gracefully.
It’s not much more complex than that.
I am normally not much of an evangelist, but after working with Qt C++ on a few different apps, (my first experience was back when it was still trolltech and I was running KDE on Mandrake Linux, ahh the good ol days.) and all I can say is: This is C++?
Qt is the C++ framework of the future, and those who haven’t adopted it should, now, as soon as possible.
A little case study will suffice. I have been working on a project for a few months now and a few days ago it came up that there needed to be plugin architecture integrated into the software so that third party vendors could easily add functionality to the program. Sounds fun huh?
The answer was simple, Qt already has a signals and slots mechanism, asking third party vendors to use Qt isn’t unreasonable, its a dead easy framework to use, and no, it’s not that bloated.
Here were the steps:
- Create a standard message definition that can be used to communicate steps and program state
- Create a general purpose relay QObject (I called it Telegraph) with a send and receive. It sends, whatever it receives.
- Pass the relay object to the library allowing them to connect to the send/receive methods on the object
The entire plugin architecture was up and running in less than an hour, and tested, it hasn’t had an issue yet, though I am sure something might need some finaigling before it ships.
The great thing about it is, plugins can be made in pure Qt with only one header file, the message definitions! Since the hooking up of signals and slots is an abstract process, 3rd party devs just extern a register function that receives a QObject or void * object and the casts it to QObject* and connects the signals and slots. If we decide to change or add in some functionality to the telegrapher, it won’t affect old plugins, and new plugins can subscribe to new features without having to include any code.
Plugins can also connect to the Telegraphs receive slot, which relays whatever it receives to send signal, so any application objects that want to be exposed to plugins can define their own receive slot and connect it to the telegraphs send signal. Any interested party will be notified of an "event" and can choose what to do based on the message and the void * passed with it.
This has already been tested with two way communication, communicating from a Dialog box to the main window etc.
Working with Qt is sometimes like working in Flex/AS3, the signals and slots idea is exactly like event listeners, well more or less. The difference is, you get this functionality for free in a C++ app, and that in and of itself is tremendously useful.
People say that developing C/C++ apps takes along time and that's why things like RIAs and web based apps will overtake them, that's partially true, but when you get right down to it, C++ has never been this easy to use, and making an extremely cool app in C++ can take days in Qt whereas without it, it might take months, or even never happen.
So yeah, I feel pretty comfortable making with a little Qt evangelism right now, as it's really made my life a whole lot easier.
/jTags: C/C++, Programming, QT | Categories: c/C++, Qt, Topics, Tutorials | Comments (0) | Permalink
Having a problem with <insert problem in c++ here>, don’t fret, as I have written an awesome lib that will solve your problem in 1 line of code, here’s a tasty code sample:
MyLib::MySpecialValue solved = MyLib::solveYourProblem(ProblemData);
All you need to do is download my project, and use <insert obscure replacement for make here> then type: obscuremake all and you are done!
Don’t have obscuremake? No problem, just download and install and you’ll be off an running!
[While source is downloading...]
Welcome to ObscureMake.sourceforge.net
This page updated sufficiently long ago to make you think twice about using this tool.
ObscureMake is a new, improved form of make that is nothing even like make, using a special Fortran/COBOL hybrid language called Fortrol, you create your app in a ridiculously non-standard directory structure, and obscuremake does the rest, finding all of your randomly hidden include and inline files. ObscureMake is a complete waste of time, if you are about to download a project using obscuremake, please reconsider, by the time you download the project to compile and this tool, you’ll spend hours trying to figure out how to get it to run, once you do get it to run, it will spew out a bunch of nonsensical errors, which you will then spend 2 days tracking down trying to correct, finally, the project will compile, but once you include it in your current project, it won’t compile anymore because of some random error or collision. To be honest, you are better off writing it yourself.Categories: c/C++, Humor, Qt | Comments (0) | Permalink