October 28, 2005
> 
> Did you compile with -version=M_ELF?
> tcgetattr works for me, it was tcsetattr that was failing.
> The TCGets value I am using is from the DMC headers (not the ubuntu ones).

No. I just compiled it without any -version stuff...
What does M_ELF stand for should it be compiled like this on Linux?

> How do you use strace. I have tried using it on my D executable and all it doesn't seem to show anything of my own code, i.e. I cannot see the ioctl calls. I see some open calls (I assume this is the code DMD adds to the start of every executable).
> 
I dont know what is your problem there!
strace outputs many lines of information and you have to search for the IOCTLs.
For example, the lines I get while executing (as root) the D code for testing com.d are the following:

licoslp0:/home/gasiba/downloads/D/Utils # strace ./test_com
execve("./test_com", ["./test_com"], [/* 75 vars */]) = 0
uname({sys="Linux", node="licoslp0", ...}) = 0
brk(0)                                  = 0x806a000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/tls/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/tls/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/tls/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/tls/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/tls/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/tls/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/tls/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/tls", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/root/GNUstep/Library/Libraries/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/root/GNUstep/Library/Libraries", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/tls/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/tls/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/tls/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/tls/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/tls/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/tls/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/tls/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/tls", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/Local/Library/Libraries/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/Local/Library/Libraries", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/tls/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/tls/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/tls/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/tls/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/tls/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/tls/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/tls/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/tls", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/i686/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/i686/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/i686/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/i686", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/sse2/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries/sse2", 0xbff2950c) = -1 ENOENT (No such file or directory)
open("/usr/GNUstep/System/Library/Libraries/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/GNUstep/System/Library/Libraries", {st_mode=S_IFDIR|0755, st_size=328, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=131025, ...}) = 0
old_mmap(NULL, 131025, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40017000
close(3)                                = 0
open("/lib/tls/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0pH\0\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=93266, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40037000
old_mmap(NULL, 70104, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40038000
madvise(0x40038000, 70104, MADV_SEQUENTIAL|0x1) = 0
old_mmap(0x40046000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xd000) = 0x40046000
old_mmap(0x40048000, 4568, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40048000
close(3)                                = 0
open("/usr/GNUstep/System/Library/Libraries/libm.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/libm.so.6", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\2203\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=191109, ...}) = 0
old_mmap(NULL, 151712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x4004a000
madvise(0x4004a000, 151712, MADV_SEQUENTIAL|0x1) = 0
old_mmap(0x4006e000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x23000) = 0x4006e000
close(3)                                = 0
open("/usr/GNUstep/System/Library/Libraries/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/libc.so.6", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`O\1\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1417063, ...}) = 0
old_mmap(NULL, 1174492, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40070000
madvise(0x40070000, 1174492, MADV_SEQUENTIAL|0x1) = 0
old_mmap(0x40189000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x119000) = 0x40189000
old_mmap(0x4018d000, 7132, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4018d000
close(3)                                = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4018f000
mprotect(0x40189000, 4096, PROT_READ)   = 0
set_thread_area({entry_number:-1 -> 6, base_addr:0x4018f6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0x40017000, 131025)              = 0
set_tid_address(0x4018f708)             = 6267
rt_sigaction(SIGRTMIN, {0x4003c3c0, [], SA_SIGINFO}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x4003c440, [], SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=RLIM_INFINITY, rlim_max=RLIM_INFINITY}) = 0
_sysctl({{CTL_KERN, KERN_VERSION, 0, 20d91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2, 0xbff29c30, 30, (nil), 0}) = 0
brk(0)                                  = 0x806a000
brk(0x808b000)                          = 0x808b000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40190000
rt_sigaction(SIGUSR1, {0x8057c50, ~[RTMIN RT_1], 0}, NULL, 8) = 0
rt_sigaction(SIGUSR2, {0x8057cf0, ~[RTMIN RT_1], 0}, NULL, 8) = 0
open("/dev/ttyS0", O_RDWR|O_NONBLOCK)   = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(3, 0x7802, 0x40191fa4)            = -1 EINVAL (Invalid argument)
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40017000
write(1, "Error: Failed to set attributes "..., 51Error: Failed to set attributes {Invalid argument}
) = 51
munmap(0x40017000, 4096)                = 0
exit_group(1)

Notice the IOCTLs in the last lines... ;)
In this case, the last IOCTL, namely ioctl(3, 0x7802, 0x40191fa4) is not recognized by the OS! (it results Invalid argument)

Best,
Tiago

PS: I'm using a SuSE 10.0 with kernel 2.6.13-8-default, but this does not make any difference for the strace!

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 28, 2005
> 
> No. In order to make it a cross-platform we have to use the same definitions, that is why BaudRate was created. There should be a way to make it error when you fail to pass a BaudRate enum value.

Not really - You can use a construct similar to this:

<snip>
import std.c.stdlib;

version(linux){
  const int A = 0;
}

version(windows){
  const int A = 1;
}

int main( ){
  printf("%d\n",A);
  return 0;
}
<snip>

If you compile it under Linux you see a "0", in Windows you see a "1" ;)
The, in your routines you can just simply pass the argument transparently without the need of a translating array!

Best,
Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 28, 2005
On Fri, 28 Oct 2005 10:53:42 +0200, Tiago Gasiba <tiago.gasiba@gmail.com> wrote:
>> No. In order to make it a cross-platform we have to use the same
>> definitions, that is why BaudRate was created. There should be a way to
>> make it error when you fail to pass a BaudRate enum value.
>
> Not really - You can use a construct similar to this:
>
> <snip>
> import std.c.stdlib;
>
> version(linux){
>   const int A = 0;
> }
>
> version(windows){
>   const int A = 1;
> }
>
> int main( ){
>   printf("%d\n",A);
>   return 0;
> }
> <snip>
>
> If you compile it under Linux you see a "0", in Windows you see a "1" ;)
> The, in your routines you can just simply pass the argument transparently without the need of a translating array!

You still have to choose either:
 - use the windows names
 - use the linux names
 - use new names

Either way you're going to get someone (as you yourself did) typing the wrong thing.

It would be better if you could catch the error at compile time. I was hoping something like this would work:

typedef uint baud_t;

version(Windows) {
	enum BaudRate : baud_t {
		B110 = 110,
		B300 = 300
	}
}

version(linux) {
	enum BaudRate : baud_t {
		B110 = 0x3,
		B300 = 0x7
	}
}

void foo(BaudRate b) {}

void main()
{
	uint a = 5;
	int b = 5;
	foo(5); //no error!
	foo(a); //error
	foo(b); //error
	foo(BaudRate.B110); //no error
}

But it seems that an integer literal is implicitly converted to a baud_t and is thus acceptable as a BaudRate.

So, then I tried:

version(Windows) {
	enum BaudRate : uint {
		B110 = 110,
		B300 = 300
	}
}

version(linux) {
	enum BaudRate : uint {
		B110 = 0x3,
		B300 = 0x7
	}
}

typedef BaudRate baud_t;


void foo(baud_t b) {}

and got the same results.

Does anyone know how to do this? (restrict the input of a function to one of a bunch of defined values i.e. an Enum or similar)

Regan
October 28, 2005
On Fri, 28 Oct 2005 10:47:50 +0200, Tiago Gasiba <tiago.gasiba@gmail.com> wrote:
>> Did you compile with -version=M_ELF?
>> tcgetattr works for me, it was tcsetattr that was failing.
>> The TCGets value I am using is from the DMC headers (not the ubuntu ones).
>
> No. I just compiled it without any -version stuff...
> What does M_ELF stand for should it be compiled like this on Linux?

No idea. All I know is that on ubuntu the tcgetattr in the M_ELF block works whereas the other does not.

>> How do you use strace. I have tried using it on my D executable and all it
>> doesn't seem to show anything of my own code, i.e. I cannot see the ioctl
>> calls. I see some open calls (I assume this is the code DMD adds to the
>> start of every executable).
>>
> I dont know what is your problem there!
> strace outputs many lines of information and you have to search for the IOCTLs.

I realise this. I didn't get these lines:

> open("/dev/ttyS0", O_RDWR|O_NONBLOCK)   = 3
> ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
> ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
> ioctl(3, 0x7802, 0x40191fa4)            = -1 EINVAL (Invalid argument)

I was looking for them, especially the open containing "/dev/ttyS0".
I didn't get anywhere near as many lines as you did, mine was much shorter.

Can anyone tell me whether DMD on linux links with it's own C library (as it does on windows) or whether it links with the system libraries. If it's linking with the system libraries then I'll use the system headers to define the com stuff (as opposed to using the DMC ones).

Regan

October 28, 2005
New version. This one works for me on ubuntu linux. However, the timeout on read isn't as instant as I'd like, each call to read takes approx 1 sec to timeout.

Regan

October 28, 2005
Sean Kelly wrote:
> 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
> 
> 
Sorry, Sean:

COM ports are very common on industrial environments actually and in the future.
I agree that Office/playing machines can forget this technology... but there is other worlds in this world... and industrial environments and instrumentation is one of this worlds...

Antonio




1 2 3
Next ›   Last »