How does windows accses serial port - Page 1
Forum section: electronics / beginners

author: abdullahseba
author_rank: Frequent Contributor
timestamp: May 30, 2015, 06:47:02 am
content: do programs access the com port directly or does windows have a DLL?

author: Rerouter
author_rank: Super Contributor
timestamp: May 30, 2015, 06:49:29 am
content: 95/98 had direct access, a number of old programs abused it, meaning they struggle to work in later versions of windows, i do not know about later ones,

author: hamster_nz
author_rank: Super Contributor
timestamp: May 30, 2015, 07:05:04 am
content: Depends on your meaning of "direct access"...Here's something that opens the port, reads data from an Arduino, timestamps it and then writes it to a file...You have to set the device properties in device manager (e.g. 9600 8-N-1, no flow control).http://hamsterworks.co.nz/mediawiki/index.php/Serial_LoggerAnd as displayed in the usage message... "Remember that COM ports above COM8 can be addressed with \\.\COMx"

author: Obin
author_rank: Contributor
timestamp: May 30, 2015, 07:50:29 am
content: Quote from: hamster_nz on May 30, 2015, 07:05:04 amCompletely off-topic: Are you the guy behind Hamsterworks?Thanks for your explonation about the ADAU1761, helped me out a lot with a schoolproject!

author: hamster_nz
author_rank: Super Contributor
timestamp: May 30, 2015, 08:08:14 am
content: Quote from: Obin on May 30, 2015, 07:50:29 amYeah... i guess that is me. (As long as you are saying good things.)The nick-name comes from having chubby cheeks and ginger hair when I was a lad....

author: mikerj
author_rank: Super Contributor
timestamp: May 30, 2015, 10:14:28 am
content: Quote from: abdullahseba on May 30, 2015, 06:47:02 amAny well written program would use the Windows API to access the serial ports, which has been available since Windows 95.Like many other operating systems, Windows treats a serial port as a kind of file, so you use the same CreateFile() function to open a COM port as you would a file on the storage device.

author: n9zl
author_rank: Unknown
timestamp: May 30, 2015, 06:49:52 pm
content: Modern versions of Windows do not allow any direct access to hardware such as serial ports. You can use API calls to do it, or you can use the com port file devices.This blog post talks about it:http://stackoverflow.com/questions/237487/basic-example-of-serial-communication-with-windows-xp-win32VB.net in Visual Studio gives you simple ways to access them, and is available free.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: May 30, 2015, 06:52:06 pm
content: Quote from: n9zl on May 30, 2015, 06:49:52 pmI do use visual studio ultimate but I just wounded if windows had a DLL

author: IanB
author_rank: Super Contributor
timestamp: May 30, 2015, 07:05:39 pm
content: Quote from: abdullahseba on May 30, 2015, 06:52:06 pmWindows has lots of DLLs. They are part of the Windows SDK and runtime environment.As with all modern operating systems, devices are accessed through device drivers. Device drivers are special privileged pieces of code that mediate access to hardware devices from running programs. You access device drivers through system API calls that you normally find in the system documentation. These system API calls are made available to your program by linking appropriate system libraries into the executable. The libraries are very often provided as DLLs (which simply means Dynamic Link Library).

author: dom0
author_rank: Super Contributor
timestamp: May 31, 2015, 10:15:20 am
content: Windows has the old DOS-style device files for serial ports (just "COMn") and the newer (as in 25 years old) NT-style device files ("\\.\COMn"). The former only support single-digitn.There are dedicated APIs for port setup (baud rate, start/stop bits etc.). Seehttps://msdn.microsoft.com/en-us/library/ff802693.aspx

author: mushroom
author_rank: Regular Contributor
timestamp: May 31, 2015, 01:07:26 pm
content: File I/O including serial belong to kernel32.dll :https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspxIf you are a Visual Studio user, and you code with C++/MFC, here's an excellent wrapper for serial ports :http://www.codeproject.com/Articles/992/Serial-library-for-CWith these classes, serial communications run in a separate thread, so the com ports polling cannot block the main process. This separate thread sends messages to the main thread when data are available. I'm using these classes for communications with Arduino, and they work really fine.