Network driver over ethernet IOKit Cocoa - c++

I have writen an objective-c POS that needs to interact with many ethernet devices like barcode scanner, fuel pump, cash drawer, etc. I know i'll probably have to write drivers in c++ for each device. The problem is I have no idea of how to write ethernet devices drivers. Is there anybody who can help me?
Btw, I haven't seen any code sample for ethernet drivers on the Apple dev site.
Thanks in advance!

If the platform your working with is running iOS or MacOS, then it already has an Ethernet driver and a TCP/IP stack. What you probably need to write are modules/classes that communicate with the various devices using a socket API. These modules/classes are written at the application level, and are not OS device drivers.
To use sockets on iOS/MacOS, you can work with either the CFNetwork framework, or more directly with BSD sockets. There is lots of literature and examples on socket programming. There is not as much litterature on CFNetwork, but CFNetwork has the advantage of being easier to integrate with your app's run loops.
Check out this answer that lists resources for learning sockets network programming.
A third option would be to use the Boost.Asio library, which is "a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach". This documentation page shows several examples on how to use asio. You can use Objective-C++ (with *.mm files) to mix Objective-C with C++.

Related

How would I reproduce the functionality of the Windows winusb driver on Linux? Do I even need to?

I need to implement an application on Linux that drives a USB connected device (a medical instrument). The application will be written in C++ (2011 standard).
The current application is written for Windows 10 in C# and uses the standard Winusb driver enumerated for the device. I have a complete protocol specification for the commands and the events/interrupts coming back. Unfortunately, I'm not sure how I can pass these to the USB layer in Linux. If it was a simple serial device, there would be no problem but I'm guessing the command responses and the interrupt events are multiplexed by the driver using the functionality in the Winusb driver.
Where's the best place to start in terms of documentation? Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
Any help appreciated. Thanks
Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
One way is using directly the generic kernel API for USB (see the Asynchronous I/O parts to get the interrupts):
https://www.kernel.org/doc/html/v4.15/driver-api/usb/usb.html
This is the strict Linux equivalent of WinUSB.
The potentially less hard way is using libusb, which also get you cross-platform features.
(I am assuming your device is recognized correctly by the kernel, and doesn't need a custom driver)
Is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
Yes. libusb is a popular USB abstraction library that supports Linux, macOS, and Windows. I also wrote a similar library called libusbp with a different set of features that were more useful for my applications. These are C libraries so it will take some work to interoperate with them from C#, but once you do that, you can probably use the same code on either Windows or Linux (so you wouldn't have to maintain your code for calling WinUSB).

LabVIEW Linux C++ development - beginner questions

Background
In our company we cooperate with manufacturer of machinery, we are developing C++/Qt crossplatform control applications for devices that they produce. In the past, we used to communicate with their devices through USB (virtual COM port). Now we were informed that this manufacturer plans to switch to LabVIEW (USB Data acquisition). Of cause we will receive relevant information in the future, nevertheless I would like to get some information about it and ask you question which i could not find on internet easily.
I am sorry for noob questions.
Questions
1) What is LabVIEW? Am I right that it is not a single piece of device, but bunch of hardware components, drivers and standards?
2) Who is LabVIEW developer? I have read How much time do I need to learn LabVIEW, but I am not sure. Is it a person who puts LabVIEW components together and makes firmware for them. Or a person who develops toplevel user applications that communicate with LabVIEW?
3) I assume that first part from Question2 would be done by our partner company. Second part will be upon us. But who creates communication protocol? Is there any standard way how DAQ communicates with its PC drivers, or is it upon programmer to develop communication protocol?
4) I have found there is driver for linux at National Instruments. Contains this driver some API/libraries that can be included in C++ code in a standard way and utilized to communicate with DAQ?
LabVIEW is a development environment for creating custom applications that interact with real-world data or signals in fields such as science and engineering. LabVIEW itself is a software development environment that contains numerous components:
G Programming: flowchart-like dataflow programming model
Hardware support: Support for thousands of hardware devices like scientific instruments, data acquisition devices, sensors, cameras, ...
Analysis and technical code libraries: Libraries for signal processing, communication, file I/O, control algorithms, ...
UI components and reporting tools: controls such as graphs, gauges, and tables to view your acquired data and tools to save data to file or databases, or automatically generate reports
Technology abstraction: Using technologies such as FPGAs, multicore CPUs, ...
Models of computation: When G is not appropriate simulation syntax, textual math, statecharts, component-level IP (CLIP) nodes, DLL calls, ... are available
LabVIEW is developed and maintained by National Instruments. It stands behind LabVIEW with comprehensive support, training, and certification options.
LabVIEW makes the process of integrating hardware much easier by using a consistent programming approach no matter what hardware you are using. LabVIEW has freely available drivers for thousands of NI and third-party hardware. In the rare case that a LabVIEW driver does not already exist, you have tools to create your own, reuse a DLL or other driver not related to LabVIEW, or use low-level communication mechanisms to operate hardware without a driver.
LabVIEW is also cross-platform and allows you to deploy your code to many different computing platforms like popular desktop OSs (Windows, Mac, and Linux), embedded real-time controllers, ARM microprocessors, and field-programmable gate arrays (FPGAs).
By the sounds of it you don't need to learn LabVIEW (which is a pity), but you need to learn daq-mx the hardware driver suite by National Instruments. I have no experience with the Linux version (which is a trimmed down or base version of the Windows one), but it basically is a set of dll's or so's that allow you to communicate with their hardware. Try to find out what hardware they are going to use and see if daq-mx base supports simulated devices.

Access USB hardware (pressure sensor matrix with native C++ API) using Python

I am working with a pressure-sensing mattress having a USB interface. The maker provides USB device drivers for Windows, and an API written in C++ which has functions to request data and set some parameters.
Currently, I cannot use this sensor for testing some Python data-visualization scripts directly, having had to ask my coworkers to write a text-logger for me, and then I read this information offline with Python.
Also, I cannot use Linux at all with the sensor, because there are not drivers for Linux, and I do not know where to start to "hack" the sensor, and that is why I am asking:
"If I were to try to read data from this sensor directly with Python and perhaps in Linux, what should I do first, or read first?"
EDIT: the device has an FTDI driver (FTD2XX.dll) if it helps.
Any help would be very welcome
Odds are fairly good it's a HID device, in which case you can probably start to write a userspace linux driver for it using libhid. First place to start with that would be enumerating the tree that gives you information about its capabilities. (lsusb -vvv or Example)
Failing that you can use libusb on linux (and other platforms too these days) to write a userspace driver still. You'll want to use something like usbsnoop or a real hardware equivalent to see what the official driver does when it's talking to the device and mimic it from there.
From the python side you can probably generate a decent wrapper to the existing C++ API using SWIG for relatively little effort, especially compared to developing an entirely custom driver.
Update:
If it's an FTDI device then it's might be a lot simpler to work with. Depending on what the vendor and product ID are showing it might automatically work with the FTDI driver in Linux, giving you as USB serial port. Failing that there are parameters to the module - vendor and product that I believe you can use to make it claim other devices besides the pid/vid combinations it knows about already. From there you can try opening the serial port device with different settings. With luck it might be sending state info regularly already.
If it's not you want to try and discover what the official software sends to make it start playing. You're back into the realm of sniffing again, but I think there might well be things that do it at the serial layer instead of the USB layer for windows (although I can't name any). You might also learn something by trying to make their library use a software emulated serial port instead of the FTDI device and seeing what it writes.
The FTDI chips have a linux driver. Just go to the FTDI website and download it. The driver creates a virtual serial port. You can use PySerial to interface with it.
Too bad I didn't see the post sooner!

Cross Platform MIDI library supporting iOS CoreMIDI

I'm looking for a cross-platform C or C++ MIDI library. Just to send/receive MIDI note events, control codes and timing, not to generate sound.
The main target is iOS/iPad so it has to support CoreMIDI on iOS, which I know is fairly recent. I can use CoreMidi directly but if there's something lightweight out there it would be nice to use something portable so I could easily port the project to PC's.
Failing that, please mention if there's a good, lightweight one that's open source it might be easier for me to add CoreMIDI support than to roll my own.
Clarification: I'm looking for something similar to MidiIO or PortMIDI that has good iOS support.
You might want to take a look at RtMidi.
It provides a cross-platform API for realtime MIDI input/output, and makes use of the native API's for each platform (winmm, ALSA, CoreMidi).
I haven't used it with CoreAudio/CoreMidi, but it's worked flawlessly for me on Windows and Linux.
I don't know MIDI thing in iOS dev. To my understanding, sending/receiving MIDI note events to/from MIDI devices should be a pure OS API problem. And parsing/generating MIDI messages is about MIDI spec. I suppose neither leads to a need of a library.

USB and a personal-created device interfacing in Windows using C/C++

I know how to interface using the parallel port and also have a little idea on serial port interfacing. But is there a way to interface using the USB port in Windows? Or any links that would give tutorials on how to do this?
Specifically, I wanted to know the programming side of it.
I don't know how to start. I have searched into google but I have not seen any code samples.
Thanks in advance and Happy New Year.
USB programming is considerably more complex than serial or parallel port programming. For writing USB drivers for Windows, you'll probably need the Windows WDK. However, for a device you build yourself you can start with implementing a serial port class driver in your device, so that it shows up as a new serial port in Windows. The HID is another potentially useful driver class, generally used for some kind of input device.
I would recommend a good book if you want to do USB programming, for example Jan Axelson's USB Complete. And a real hardware protocol analyser is indispensable.
Found an interesting blog post http://yeohhs.blogspot.com/2006/08/programming-usb-port.html
it mentions a library 'libusb' and a wrapper for the same. The library is a GNU project. The library and documentation of the same may prove useful. The API documentation of libusb is here: http://libusb.sourceforge.net/api-1.0/