ANSI C on Windows 7 - Programmatically generating a Serial Event (RS232) - c

I am using a combination of hardware and virtual serial ports in a ANSI C Windows 7 environment. In this project, there will be two applications: The first application is being developed and will be connected both to a hardware COM port and to a virtual COM port. The second is a legacy application (has already been developed and cannot be changed) It will be connected only to the same virtual COM port via a virtual NULL modem.
In the first application, COM event handlers can be used for listening to and handling messages generated from a serial message generator connected to the hardware COM port. However, virtual COM ports do not generate COM events, and so I am limited to using timing loops to periodically check the simulated in and out queues of the virtual port. This is fine for controlling COM traffic in the first application, but the second application will need to see a COM event to enable it to process incoming serial traffic.
Is there a way to generate Windows COM (RS232) events programmatically in one application such that a legacy application that is expecting COM events, can see them?
By events, I am referring to those recognized by a typical comcallback, such as:
LWRS_RXCHAR, LWRS_RXFLAG, LWRS_TXEMPTY, LWRS_CTS, etc.

I don't know if this will work, but you can try to make a loopback on the legacy COM interface? Then you can write to it and it will trigger COM events.

Just closing the loop here (a little late), Thanks for the attempt #Evert.
The solution was to select the right vendor. We needed a good kernel mode driver to produce the right configuration of virtual com port. Eltima (www.eltima.com) provided a product that did just that. Great product with a usable API. Problem solved

Related

File access between mcu and PC through rs232 communication

I'm using a LPC178 development board and I want to read a file present on a Windows PC. My dev board only has a RS2323 interface to communicate with.
How can I go about transferring the file from my PC to my MCU using a RS232 (serial) link? I found a reference which explains how to transfer data between a MCU and PC but it isn't about file transfers.
Afaik there is no easy solution for this like calling something like "copy" or "fopen" over RS232. I would be happy to be proven wrong here.
The fastest solution might be to write a little programm running on your Windows Host, which listens to your RS232 communication and pipes your communication into/out of the file based on your communication protocol. This can be done with standard file operations in the language of your choice, for example C, C++ or Python.
Your problem is one of the oldest in the book. How do you transfer files without fancy operating system abstractions. For RS232 (or any other serial method) there exists many file transfer protocols.
One of them is kermit. This is a protocol from 1981 and can transfer binary and text files. It is able to be embedded in a micrcontroller and there exists programs to transfer/receive using kermit.
alternative old site for reference
In the simplest case you would use a file transfer protocol such as XMODEM, YMODEM, ZMODEM or Kermit - these protocols were designed in the days before networking and the Internet were ubiquitous and deal with simple point-to-point transfers between two computers. They are supported bu most terminal emulator tools such as TeraTerm Pro or PuTTY so no specific PC software need be written, just the microcontroller end.
A more complex but flexible solution is to implement a TCP/IP stack and a PPP driver, and an FTP application layer - probabaly only practical if using a third-party TCP/IP stack and application layer. You can then use any FTP client for the PC end, so again no PC software required. While this may be overkill if all you need to do is transfer files, it has the advantage of allowing you to use the the single serial port concurrently for other data streams and application protocols such as Telnet. The disadvantage perhaps is that while Windows does support PPP it is buried within the dial-up networking and to be frank a pain to get working.
Very first step you have to do is ensure serial communication is working fine.
Send a byte continuously from mcu to PC and display it on some io console (for example: HyperTerminal, Dock light )
Receive a byte to mcu from PC and echo it back to PC.
Once you are sure that serial communication is working fine then select some file transfer protocol and implement it.
While you can select any of the available protocols or write your own protocol and implement it.
For purpose of discussion i select Xmodem protocol.
If you consider some other protocol you may stop reading answer here.
XMODEM is a simple file transfer protocol.
Refer http://web.mit.edu/6.115/www/amulet/xmodem.htm for detailed information.
You may implement Xmodem mcu side by reading protocol. Or may consider using open source also ( if available )
PC side i prefer to use HyperTerminal io console as it is compatible with Xmodem.
In HyperTerminal all that i have to do is configure settings and select file for transfer to mcu.
Now transfer any file to mcu using Xmodem protocol from PC.
What you do with received file in mcu is up to you : )

Writing a Windows driver for Pro Micro

First off I have very very little experience with how USB functions let alone writing a driver; essentially trying to make this project a learning experience.
My setup consists of the SparkFun Pro Micro board and a Windows machine. I have a potentiometer wired up to the Pro Micro and my end goal is to send the value of the potentiometer to the host machine and use the value to change things like system volume etc...
The Arduino library came with a Serial library and I can send things over USB using that. I currently have a working Arduino program that sends 1 byte every 1 second, and a C program on the windows machine that "connects" to the COM port and reads the byte coming through (this part I have working fine).
The issue is that when the Pro Micro is connected to the computer it appears on a randomly selected COM port and I don't think you can tell which COM ports hold which device (not sure about this bit).
My end goal is when the Pro Micro is connected to the PC the host program should automatically recognize the Pro Micro and start processing the data that is coming from it. Setting it up as a HID device and making it appear in Device Manager as my own custom device is something I'd be interested in doing, especially for the learning experience but I feel that it might overcomplicate things.
Can anyone point me in the right direction as to what I should do/look into?
maybe use windows internal tools like the COM port database (https://msdn.microsoft.com/en-us/library/ff546481.aspx) or re-assign COM ports using windows registry, see
How does windows map the virtual com port to a device
https://superuser.com/questions/851192/change-com-port-number-programmatically
http://www.ftdichip.com/Support/Documents/AppNotes/AN_132_Re-Assigning_COM_Port_Numbers_Using_Registry.pdf
if you want to know the backgrounds: the arduino implements the USB CDC ACM class (Communication Device Class - Abstract Control Model https://en.wikipedia.org/wiki/USB_communications_device_class) and emulates a COM port. Windows recognizes this class and loads the apropriate driver which is usbser.sys (https://msdn.microsoft.com/de-de/library/windows/hardware/dn707976%28v=vs.85%29.aspx) when the driver is loaded the new (virtual) COM port is accessible
the best sources are How does windows map the virtual com port to a device, https://superuser.com/questions/851192/change-com-port-number-programmatically and http://www.ftdichip.com/Support/Documents/AppNotes/AN_132_Re-Assigning_COM_Port_Numbers_Using_Registry.pdf
I would suggest using libusbp, a C library that can be used to find the name of a COM port, given the USB vendor ID and product ID. There is even an example in the "examples" folder that does just that:
https://github.com/pololu/libusbp

BLE Bridge Mode in Linux example

I want to use Bluetooth(4.0) on my board to transmit it's Name so any Mobile Application can see it's name and Mobile application initiates the pairing and connection with my Bluetooth.
I have seen some examples of Bluetooth(4.0) scanning nearby devices; For example:- It does scan for Bluetooth Mouser/Keyboard, but in this case Bluetooth(4.0) is in mode where it chooses the device it want to connect while I want it reverse so Any mobile application can see my Bluetooth and gets connect with it and does communication.
How can I put my Bluetooth(4.0) in such mode in Linux? Is there any C library using which I can put Bluetooth(4.0) is the mode where it goes in Bridge mode instead of scanning nearby devices?
You can set the name of your device like this:
hciconfig name "foo"
and check your name with:
hciconfig name
You also have to enable Low Energy advertising for your device to be found by others:
hciconfig leadv
You can configure your device to accept incoming connections like this (lm for link mode):
hciconfig lm MASTER,ACCEPT
This way the kernel will accept a connection, even if there are no listening sockets.
Considering you want to do actual communication, you would need to write a program, accepting the connection and sending/receiving data. Just putting your device in a mode where other devices can connect to it isn't really worth anything (because you can't communicate).
The basic principle is to open up an L2CAP socket, with the Channel ID of 4 (for Low Energy), then do standard bind/listen/accept. I suggest you look at the source code of Bluez and the examples.

windows: how to stop irda dongle periodic auto detecting

I'm writing some code in C for an IrDA project on one win7 32bit computer. I have another computer setup to display any data received via in infrared. This part works. However the as soon as I connect the IrDA dongle to the PC, it starts to send periodic data for searching other IrDA devices. I want to disable this behavior programmatically so I see only the data sends as a result of my code. Anyone know which command to use? Is it WSASetService? I didn't learn socket programming, not sure what "removes from the registry a service instance within one or more namespaces. " really means. http://msdn.microsoft.com/en-us/library/windows/desktop/ms742211%28v=vs.85%29.aspx
Have you disabled the Infrared Monitor Service manually?
I experienced problems with this functionality in win7 when using Windows to communicating with an embedded micro-controller based device that worked well with windows XP.
I disabled the Infrared Monitor Service manually and found that windows was still polling the IrDA periodically!
I have not found any documentation available that describes it or how to disable it, I will continue searching...

Communicating with peripherals and I/O ports from Silverlight?

Before moving towards silverlight.. I want to know if the latest version of Silverlight 5 is capable of communicating and interacting directly with I/O ports or any other USB HID devices/ peripherals?
I think the only way you could do is to run it in a browser and use pInvoke calls.

Resources