Author Topic: How does windows accses serial port  (Read 3064 times)

0 Members and 1 Guest are viewing this topic.

Offline abdullahseba

  • Frequent Contributor
  • **
  • Posts: 333
  • Country: gb
How does windows accses serial port
« on: May 30, 2015, 06:47:02 am »
do programs access the com port directly or does windows have a DLL?
This is my right hand this is my wrong hand
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4221
  • Country: au
  • Question Everything... Except This Statement
Re: How does windows accses serial port
« Reply #1 on: May 30, 2015, 06:49:29 am »
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,
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 1960
  • Country: nz
Re: How does windows accses serial port
« Reply #2 on: May 30, 2015, 07:05:04 am »
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_Logger

And as displayed in the usage message... "Remember that COM ports above COM8 can be addressed with \\.\COMx"
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline Obin

  • Contributor
  • Posts: 33
  • Country: be
  • Hi
Re: How does windows accses serial port
« Reply #3 on: May 30, 2015, 07:50:29 am »
Completely off-topic: Are you the guy behind Hamsterworks? :D Thanks for your explonation about the ADAU1761, helped me out a lot with a schoolproject!
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 1960
  • Country: nz
Re: How does windows accses serial port
« Reply #4 on: May 30, 2015, 08:08:14 am »
Completely off-topic: Are you the guy behind Hamsterworks? :D Thanks for your explonation about the ADAU1761, helped me out a lot with a schoolproject!

Yeah... 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....
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 1992
  • Country: gb
Re: How does windows accses serial port
« Reply #5 on: May 30, 2015, 10:14:28 am »
do programs access the com port directly or does windows have a DLL?

Any 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.
 

Offline n9zl

  • Supporter
  • ****
  • Posts: 6
Re: How does windows accses serial port
« Reply #6 on: May 30, 2015, 06:49:52 pm »
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-win32

VB.net in Visual Studio gives you simple ways to access them, and is available free.
 

Offline abdullahseba

  • Frequent Contributor
  • **
  • Posts: 333
  • Country: gb
Re: How does windows accses serial port
« Reply #7 on: May 30, 2015, 06:52:06 pm »
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-win32

VB.net in Visual Studio gives you simple ways to access them, and is available free.
I do use visual studio ultimate but I just wounded if windows had a DLL
This is my right hand this is my wrong hand
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 9489
  • Country: us
Re: How does windows accses serial port
« Reply #8 on: May 30, 2015, 07:05:39 pm »
I do use visual studio ultimate but I just wounded if windows had a DLL

Windows 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).
I'm not an EE--what am I doing here?
 

Offline dom0

  • Super Contributor
  • ***
  • Posts: 1387
  • Country: de
Re: How does windows accses serial port
« Reply #9 on: May 31, 2015, 10:15:20 am »
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-digit n.

There are dedicated APIs for port setup (baud rate, start/stop bits etc.). See https://msdn.microsoft.com/en-us/library/ff802693.aspx
,
 

Offline mushroom

  • Regular Contributor
  • *
  • Posts: 60
  • Country: fr
Re: How does windows accses serial port
« Reply #10 on: May 31, 2015, 01:07:26 pm »
File I/O including serial belong to kernel32.dll :

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx

If 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-C

With 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.

« Last Edit: May 31, 2015, 01:09:57 pm by mushroom »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf