bluetooth device to windows API via com port - winapi

So I have a bluetooth device, this device uses SPP to transfer data between the PC and itself. It connects fine through Windows as a bluetooth device. I can find it, enter the paring code and assign it to a COM port. Now I want to be able to send data through the com port using Windows API but it is refusing to do so.
I suspect that I need to setup the COMMCONFIG Structure correctly (see below)
http://msdn.microsoft.com/en-us/library/aa363188(VS.85).aspx
Unfortunately I have no idea what is the proper setting. I know SPP is supposed to emulate the RS-232 communication... so maybe I have to study up on that to figure out the right setting? Or is there some automatic way to set the COMMCONFIG structure.

I seriously doubt it. If it would be used then you'll have no chance at guessing at the custom provider data without docs from the driver author. Pay attention to the handshake signals, serial port devices routinely ignore anything sent to them when the DTR signal is turned off. And not send anything back with DTR off. A driver would emulate that. Use EscapeCommFunction() to turn them on. Also try a serial comm program like HyperTerminal or Putty to test this so you can isolate the source of the problem.

Why not use the Bluetooth sockets API? No need for troublesome (virtual) COM ports then.
If you're using managed code then see my library 32feet.NET
If using native code, use SOCKADDR_BTH with Winsock connect etc, see e.g. Bluetooth and connect (Windows) Then you can use the standard Winsock send/recv API

Ok, I found that you can use the
GetCommConfig and GetCommState functions to figure out the settings.

Related

Route websocket data through USB link to PC client (Android)

I have an issue where WiFi is not available on an Android device. We want to stream image data from the device using a websocket server (written using WebSocket++) through to the PC. However, I'm not sure if this is possible without operational WiFi. So, the position we are in is that we may only have the USB link available.
Someone today suggested we might be able to get Websockets working using adb port forwarding (see https://developer.android.com/studio/command-line/adb#forwardports), but I'm not sure if that's correct. Could this work, and what would that solution look like?
Are there any other reasonable options. I'm not certain if tethering is available on the device and if that could be another solution?

Developing a Mac OSX Network Driver for a Serial Port AT Command Based Modem

First allow me to say that I don't have any experience developing drivers for OSX, nor drivers for Windows. So, there are a lot of things that I don't understand about how drivers work; I'm sure it'll be evident in my question.
I have a modem that is able to open and close TCP/UDP sockets using AT commands. I would like to create some kind of program (kernel extension? driver?) that implements a network driver, converting the network interface calls into AT command serial messages.
That's the basic jist of it. I'm essentially asking if anybody can point me in the right direction / give me a high level overview of how they would approach it and what Apple guides to focus on.
The XNU networking stack -- like most network stacks -- expects network devices to send and receive IP packets directly. It isn't tooled to work with network devices that handle part of the network stack (like TCP or UDP) internally -- it won't be possible to implement a network driver which uses this device.
You might have more luck exposing this device as a SOCKS proxy. You will need to write a userspace daemon which listens on a TCP port on localhost (on the computer) and relays traffic to the serial device; once that's done, you can set the computer to use that device as a SOCKS proxy in the Networking control panel.
(As an aside: most devices that implement this type of interface have a very low limit on the number of open sockets -- often fewer than 10. They're unlikely to be able to handle the network load generated by a desktop OS.)

Mac - Virtual Serial Port

I need to create a Cocoa app that will create a virtual serial port available to other apps, meaning registered in the IO Kit Registry.
Gist of the app:
Create a virtual serial port (listed in /dev and registered with the IOKit Registry)
Initiate a tcp connection out to another computer
Proxy everything received on the virtual serial port out to the
network and vice versa.
This app will be used by third party apps that talk to serial ports on the computer, allowing for the particular serial device to be located across the network. The Cocoa and network part is no problem, I've written several apps that talk over the network. My hangup is the serial port.
I've done the test with socat/netcat/minicom to verify that it all works to proxy pty/tty traffic over the network but the tty I use doesn't show up as usable by random applications because it's not registered in the IO Kit Registry.
While I can use a pty/tty master/slave for the communication, I need this slave tty to show up to Mac applications. What would be very handy is a way to register a tty in the IO Kit Registry.
Do I really need to create a custom IOKit kext driver that gets registered at Cocoa app runtime? If so, I have a big learning curve ahead of me. Where should I start reading? Or, can I use IOKit to create a virtual serial port and register it as a usable serial port for applications without having to load any kernel extensions?
Thank you for any help you can provide,
Stateful
First of all, have you checked if you can borrow a solution from this app? It's not obvious from the website if they've managed to get their virtual serial ports fully integrated into the system.
If there is a way to do it from user space, I'm not aware of it. The user-space IOKit API generally doesn't let you create class instances, let alone new device driver classes. Maybe you can somehow otherwise persuade the Cocoa libraries to find it despite not being registered in the kernel.
I don't know if you could get away with creating a "dummy" serial port in the kernel and then move your tty into its place in /dev from your userspace daemon. Maybe that's an option.
In case you do have to do it all in the kernel:
The virtual driver itself shouldn't be too much work, at least, though it will require some time to get up to speed with kernel dev. Unfortunately, the documentation is pretty thin for serial port drivers - the key is subclassing the IOSerialDriverSync abstract class. Just about the only description I've seen is in Ole Henry Halvorsen's OSX and iOS Kernel Programming book. It also has a fragment of an example for the reading & writing operations. (disclosure: I was one of the tech reviewers for this book; I don't receive any incentives for recommending it - in this case it's literally the only documentation I know of) You can find the source for a complete serial port driver in Apple's USBCDC driver, AppleUSBCDCDMM is the class that actually represents the serial port node.
It's relatively straightforward to open a so-called "kernel control" socket in the kernel, the individual APIs are documented here; from user space you use the normal BSD socket send/recv APIs. (this is also described in the aforementioned book) Your daemon can then connect to that, and all you'd need to do is push the data between the socket and the virtual serial port device. You'll need to handle disconnect events and such correctly of course.
Still, I think this is achievable as a first kernel project for an experienced C programmer (with some C++).
I hope that helps!

Looking for a GSM modem advice

My application communicates with several GSM electric controllers, that means that I have to send anywhere between one to twenty messages every few hours. right now I'm working with HUAWEI Mobile Connect - 3G. it is a USB device that uses a comm port for the pc communication and I'm using GSMComm to send messages and read/delete messages from the device.
Every two seconds I'm checking the device's storage, and if there is any message, I will then read it and store it locally and then clear the device's storage. I'm not sure if I'm working correctly, but it seems to me as if it is a very unreliable device:
Every time I boot my machine, I must remove the device from the USB or my machine will get stuck at the BIOS start up screen (or whatever the name is).
Very frequently the comm port can become unavailable for some reason. I have to close and re open the port, and at times that may not even help.
In the production machine of my client, when he uses one of his software's that utilize the first comm port, he will get a warning message from the software about problems in the port if the device is plugged in (the device port is around 28 or something).
If you've been using a device which you consider reliable, or have been working with the same device as I work with, or you just think that I'm doing it wrong, I'd like to get an advice from you.
Thanks.
This sounds like an issue with your modem. Have you tried any other models? Consumer USB models tend to be unreliable. The preferred method, though slightly more expensive, is using a commercial grade modem in situations where you need the reliability.
Some modems to look at:
Wavecom Fastrack
Sierra Wireless Airlink
These use a serial port or ethernet to communicate with the host which is far more reliable. Serial ports may not be available in your particular situation but even a USB to RS232 adapter will be more reliable.
One further option is to use a smartphone, there are several applications that you can act as a gateway through HTTP.
SMS Gateway for Android:
https://market.android.com/details?id=eu.apksoft.android.smsgateway&hl=en
i have not used this method, but it seems like some people are having luck with it. it may not be any more reliable then your USB modem though.
Hope that answers your question.
I have used WaveCom's modem for sending messages in bulks and found it to be reliable. One difference though, in my implementation was i used Kannel as an SMSC, so my queues were automatically handled by Kannel. But sending multiple requests like 40+ per minute didnt pose any problems for me.
Hope this helps.

Can I access the Parallel Port normally when using USB to Parallel Port adapter?

Preliminary story
There is this program which uses the Parallel Port to synchronize with other hardware. It will set the Parallel Port output to a specified (byte) value. This works without problems when using the built-in Parallel Port of a PC. The target platforms are Windows XP to 7, all worked fine so far. Source code is in Delphi, accessible and can be modified.
How it works
In Delphi I can use the io.dll to set the value of the Parallel Port, but there are also other solutions available, like inpout32.dll or port.dll. I call something like PortOut, specify a port number and the byte value and the port is set.
What I now want to do - and where I need help
Now the change: this needs to work on a machine which has no Parallel Port built-in (not even on the mainboard). There are several options available:
use a USB to Parallel Port adapter to add a LPT port to the PC
use a PCI card which adds a LPT port to the PC
use a PCI Express card which adds a LPT port to the PC
I am currently heading for and concentrating on the easiest and cheapest possibility: a USB to Parallel Port adapter.
Main question
There seem to be differences between Parallel Port adapters which are made to connect just a printer and other adapters which seem to be more powerful. Is there really a difference? Or can I just use one of these 5$ printer-adapters, plug in my own hardware and access the port from Delphi code? Or do I need a special adapter? Has anyone experience with this? There is a related question here, but the different adapter types (if existent) are not mentioned there. This page suggests that there are indeed differences:
Contrary to all other USB parallel ports which can connect to printers only, this makes connection to most hardware.
I hope there exists a solution via USB because for this you don't have to open the PC, which means the adapter can be added on demand.
Sub-question
Do you have experience with PCI (Express) solution? I have to use one if the USB approach is not successful.
Since I've been wrestling with this very thing recently here's what I've discovered; If you mean by using IO port addressing (indicated by your reference to inpout32.dll), no. Unless your USB-parallel port driver supports full port emulation or virtualization, which most do not, this is generally not possible. If you need to directly access the port to do normal "bit-twiddling", you should get a separate Parallel port PCI-card. Most of them present themselves as normal IO at the standard address(es). I am presuming you're not planning on using the parallel port to actually communicate with a printer, right?
What is interesting is that USB-Serial adapters are much easier to use since they appear as simple virtual devices where you can merely "open" them using a simple stream; TFileStream.Create("COM1", fmOpenRead) or Windows.CreateFile("COM2", ...);
Here is some devices that purport to do full emulation of a parallel port through USB:
https://www-user.tu-chemnitz.de/~ygu/bastelecke/PC/USB2LPT/index.en.htm

Resources