Jump to page: 1 2 3
Thread overview
Access to serial ports in Windows
Oct 24, 2005
Don Clugston
Oct 24, 2005
Don Clugston
Oct 24, 2005
Sean Kelly
Oct 28, 2005
antonio
Oct 24, 2005
Kris
Oct 25, 2005
Kris
Oct 24, 2005
Regan Heath
Oct 26, 2005
Tiago Gasiba
Oct 26, 2005
Regan Heath
Oct 26, 2005
Tiago Gasiba
Oct 27, 2005
Regan Heath
Oct 27, 2005
Regan Heath
Oct 27, 2005
Tiago Gasiba
Oct 27, 2005
Tiago Gasiba
Oct 27, 2005
Regan Heath
Oct 28, 2005
Tiago Gasiba
Oct 28, 2005
Regan Heath
Oct 27, 2005
Regan Heath
Oct 28, 2005
Tiago Gasiba
Oct 28, 2005
Regan Heath
Oct 28, 2005
Regan Heath
Oct 27, 2005
Don Clugston
Oct 27, 2005
Regan Heath
Oct 27, 2005
Don Clugston
October 24, 2005
Has anyone accessed serial (COM) ports using D (under Windows)?
Does Mango support them?

If there is currently nothing in D, does anyone know of a candidate that could be ported to D?
It ought to be possible to create something that would work on both Windows and Linux PCs, since the hardware is the same.
October 24, 2005
Don Clugston wrote:
> Has anyone accessed serial (COM) ports using D (under Windows)?
> Does Mango support them?

Windows and Linux behave a bit differently here. On Win9x/DOS you can access hardware ports directly. On WinNT+ and Linux you have to use system calls. I think D is able to call these system API functions directly, you just need correct header files.

> If there is currently nothing in D, does anyone know of a candidate that could be ported to D?
> It ought to be possible to create something that would work on both Windows and Linux PCs, since the hardware is the same.

I'm not really sure this interoperability will be of much motivation - nowadays serial ports are pretty ancient technology.
October 24, 2005
Jari-Matti Mäkelä wrote:
> Don Clugston wrote:
> 
>> Has anyone accessed serial (COM) ports using D (under Windows)?
>> Does Mango support them?
> 
> Windows and Linux behave a bit differently here. On Win9x/DOS you can access hardware ports directly. On WinNT+ and Linux you have to use system calls. I think D is able to call these system API functions directly, you just need correct header files.

Yes, it is, but serial ports aren't quite that simple. There are subtle handshaking and concurrency issues, it's extremely easy to get it wrong.
It's actually quite similar to a slow internet connection. You have to consider the possibility that the connection is lost in mid-transmission; you cannot freeze the machine while you wait for the next bytes to arrive; etc. The Windows API gives you very little help with this; I'm not sure what the situation is for Linux.

>> If there is currently nothing in D, does anyone know of a candidate that could be ported to D?
>> It ought to be possible to create something that would work on both Windows and Linux PCs, since the hardware is the same.
> 
> I'm not really sure this interoperability will be of much motivation - nowadays serial ports are pretty ancient technology.

It's ancient, but very common for engineering tools, where a cheap, simple interface is required. COM ports probably won't die for another decade. An ancient library would be adequate.

If I could switch my code between Windows + Linux machines, it would be
a real bonus for me.
October 24, 2005
Don Clugston schrieb:
> Has anyone accessed serial (COM) ports using D (under Windows)?
> Does Mango support them?
> 
> If there is currently nothing in D, does anyone know of a candidate that could be ported to D?
> It ought to be possible to create something that would work on both Windows and Linux PCs, since the hardware is the same.

http://sourceforge.net/projects/dframework/

There is a file called "serialstream.d".
I don't know if this is what you want, I haven't looked at it yet.
But I think, it's Windows-only.

Florian
October 24, 2005
In article <djikpt$q52$1@digitaldaemon.com>, Don Clugston says...
>
>Jari-Matti Mäkelä wrote:
>> 
>> I'm not really sure this interoperability will be of much motivation - nowadays serial ports are pretty ancient technology.
>
>It's ancient, but very common for engineering tools, where a cheap, simple interface is required. COM ports probably won't die for another decade. An ancient library would be adequate.

So long as you're using an old PC at any rate.  If I remember correctly, the latest mainboard format does away with serial ports.


Sean


October 24, 2005
Mango does not currently support serial or parallel port I/O. Part of the reasoning behind this is that user-level code does not have access to the hardware: on Win32 you need a kernel-mode device driver to jump across the ring barrier. I don't know what the scoop is on Linux, but I imagine it's somewhat similar (the hardware ports are not likely to be exposed at the user-mode level).

In the past I've used 'UserPort' on Win32 to gain access to the hardware (via Java, actually). It's easy to apply, but would really need interrupt-callback support added for serious usage (currently you have to poll incoming data: a big no-no, IMO).

If it were deemed generally useful to treat the 'legacy' ports as a non-sharable entity, and a (interrupt supporting) driver were made available for both Win32 and Linux, I'd be happy to see wrappers for that within Mango :-)

In the meantime, if you're on Win32 and can put up with polling (or don't need to read data; just send it), then UserPort will be your friend. Let us know how you get on?

- Kris


"Don Clugston" <dac@nospam.com.au> wrote in message news:djif1s$lfr$1@digitaldaemon.com...
> Has anyone accessed serial (COM) ports using D (under Windows)?
> Does Mango support them?
>
> If there is currently nothing in D, does anyone know of a candidate that
> could be ported to D?
> It ought to be possible to create something that would work on both
> Windows and Linux PCs, since the hardware is the same.


October 24, 2005
On Mon, 24 Oct 2005 13:03:16 +0200, Don Clugston <dac@nospam.com.au> wrote:
> Has anyone accessed serial (COM) ports using D (under Windows)?

Yes.

> Does Mango support them?
> If there is currently nothing in D, does anyone know of a candidate that
> could be ported to D?
> It ought to be possible to create something that would work on both
> Windows and Linux PCs, since the hardware is the same.

The attached source is a COM stream for windows only.

I have also written COM code on linux and freebsd and could probably add support for these two to the attached source, let me know if you're interested.

Regan

October 25, 2005
Well I'll be. Win32 does expose access to the com ports, and supports asynchronous reading of them also: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/monitoring_communications_events.asp

WaitCommEvent
If the overlapped operation cannot be completed immediately, the function
returns FALSE and the GetLastError function returns ERROR_IO_PENDING,
indicating that the operation is executing in the background. When this
happens, the system sets the hEvent member of the OVERLAPPED structure to
the not-signaled state before WaitCommEvent returns, and then it sets it to
the signaled state when one of the specified events or an error occurs. The
calling process can use one of the wait functions to determine the event
object's state and then use the GetOverlappedResult function to determine
the results of the WaitCommEvent operation.


My apologies for the earlier misguidance.

- Kris



"Kris" <fu@bar.com> wrote in message news:djj7e7$196e$1@digitaldaemon.com...
> Mango does not currently support serial or parallel port I/O. Part of the reasoning behind this is that user-level code does not have access to the hardware: on Win32 you need a kernel-mode device driver to jump across the ring barrier. I don't know what the scoop is on Linux, but I imagine it's somewhat similar (the hardware ports are not likely to be exposed at the user-mode level).
>
> In the past I've used 'UserPort' on Win32 to gain access to the hardware (via Java, actually). It's easy to apply, but would really need interrupt-callback support added for serious usage (currently you have to poll incoming data: a big no-no, IMO).
>
> If it were deemed generally useful to treat the 'legacy' ports as a non-sharable entity, and a (interrupt supporting) driver were made available for both Win32 and Linux, I'd be happy to see wrappers for that within Mango :-)
>
> In the meantime, if you're on Win32 and can put up with polling (or don't need to read data; just send it), then UserPort will be your friend. Let us know how you get on?
>
> - Kris
>
>
> "Don Clugston" <dac@nospam.com.au> wrote in message news:djif1s$lfr$1@digitaldaemon.com...
>> Has anyone accessed serial (COM) ports using D (under Windows)?
>> Does Mango support them?
>>
>> If there is currently nothing in D, does anyone know of a candidate that
>> could be ported to D?
>> It ought to be possible to create something that would work on both
>> Windows and Linux PCs, since the hardware is the same.
>
> 


October 26, 2005
Hi Regan,


Regan Heath schrieb:

> I have also written COM code on linux and freebsd and could probably add support for these two to the attached source, let me know if you're interested.

  I'm following this thread and, although I'm not imidiatly interested in COM support for Linux, maybe in the future it will come in handy...
  Could you post the code for Linux also?
  Thanks!

Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 26, 2005
On Wed, 26 Oct 2005 09:30:19 +0200, Tiago Gasiba <tiago.gasiba@gmail.com> wrote:
>> I have also written COM code on linux and freebsd and could probably add support for these two to the attached source, let me know if you're interested.
>
>   I'm following this thread and, although I'm not imidiatly interested
> in COM support for Linux, maybe in the future it will come in handy...
>   Could you post the code for Linux also?
>   Thanks!

All right, here goes!

I have modified the previously posted com.d file, it now contains an 'else' block which should hopefully work for linux, freebsd, and even macosx (maybe, not sure if I ever got it working there).

I haven't got any of those machines to compile upon and chances are I have missed some symbol or import that is required.

I wasn't really sure what to do with "#if defined(M_ELF)" so I just put it in a version block.

Same with "#if defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)" (note: this is a pain to translate into D version blocks, when are we going to get version statements that allow || ?!?)

I added a 'canRead' function to both implementations, the linux (etc) one may need some error checking added for the 'select' call.

The basic idea with read/write in this class is that it will block until it completes, but the underlying device is placed in a non-blocking mode. What this means is that the 'read' and 'ReadFile' functions return immediately whether they read or not, thus the 'while' loop to keep trying till you get something.

This source is intended for public domain.

Regan

« First   ‹ Prev
1 2 3