Re: Reversing a string

2019-01-11 Thread Mike James via Digitalmars-d-learn

On Friday, 11 January 2019 at 09:41:30 UTC, bauss wrote:

On Friday, 11 January 2019 at 08:25:41 UTC, Seb wrote:
On Friday, 11 January 2019 at 08:05:39 UTC, AndreasDavour 
wrote:

Hi.

I've just started to learn some D, so maybe this question is 
extremely stupid, but please bear with me.


[...]


Use .retro - it is also lazy and won't allocate:

https://run.dlang.io/is/A6bjrC


What a terrible name.


Check out the origin :-)

https://forum.dlang.org/thread/hl8345$2b1q$1...@digitalmars.com?page=1


-=mike=-


Re: Hello World Example with Glade?

2015-09-11 Thread Mike James via Digitalmars-d-learn

On Friday, 11 September 2015 at 06:45:07 UTC, Mike McKee wrote:

On Friday, 11 September 2015 at 06:00:39 UTC, Mike McKee wrote:

[...]


I think the start of this probably looks like the following, 
but I'm not certain:


import gtk;
import gobject.Type;
import std.stdio;
import std.c.process;

int main (string[] args)
{
Main.init(args);
Builder b = new Builder();
b.addFromFile("test1.glade");
Window w = cast(Window)b.getObject("window1");
w.showAll();
Main.run();
return 0;
}


Hi Mike,

There's a Glade example in the demos/builder directory...

Regards, --



...so, this assumed that I had a test1.glade file, and that I 
had this line inside it:




So now I need to figure out how to get GtkD installed on Ubuntu 
Linux 14.04.




Re: Hello World Example with Glade?

2015-09-11 Thread Mike James via Digitalmars-d-learn

On Friday, 11 September 2015 at 07:13:22 UTC, Mike McKee wrote:

On Friday, 11 September 2015 at 06:53:07 UTC, Mike James wrote:

There's a Glade example in the demos/builder directory...


I'm having trouble installing GtkD on Ubuntu Linux 14.04. I did 
the apt steps from here:


http://d-apt.sourceforge.net/

$ sudo su
# wget 
http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list 
-O /etc/apt/sources.list.d/d-apt.list
# apt-get update && apt-get -y --allow-unauthenticated install 
--reinstall d-apt-keyring && apt-get update

# apt-get install libgtkd3-dev libgtkd3-doc

I then run the following and it fails:

# dmd test1.d
test1.d(1): Error: module gtk is in file 'gtk.d' which cannot 
be read

import path[0] = /usr/include/dmd/phobos
import path[1] = /usr/include/dmd/druntime/import



It looks last keep you're missing an import path 
(-Ipath_to_source). Check out 
http://dlang.org/dmd-linux.html#switches


Regards, --


Re: Hello World Example with Glade?

2015-09-11 Thread Mike James via Digitalmars-d-learn

On Friday, 11 September 2015 at 07:29:23 UTC, Mike McKee wrote:

On Friday, 11 September 2015 at 07:20:57 UTC, Mike James wrote:
It looks last keep you're missing an import path 
(-Ipath_to_source). Check out 
http://dlang.org/dmd-linux.html#switches


I tried this just now:

# dmd test1.d -I/usr/include/dmd/gtkd3/gtkc
/usr/include/dmd/gtkd3/gtkc/gtk.d(28): Error: module gtktypes 
is in file 'gtkc/gtktypes.d' which cannot be read

import path[0] = /usr/include/dmd/gtkd3/gtkc
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import

It's saying that it can't read gtkc/gtktypes.d, but there is a 
file in path /usr/include/dmd/gtkd3/gtkc/gtktypes.d



try # dmd test1.d -I/usr/include/dmd/gtkd3

I'm using GtkD on Windows so there is a .../src directory with 
all the source files in.


regards, --


Re: Hello World Example with Glade?

2015-09-11 Thread Mike James via Digitalmars-d-learn

On Friday, 11 September 2015 at 07:47:15 UTC, Mike McKee wrote:

[...]


The undefined references mean you haven't provided a linker path 
to the GtkD libs.

Have you built the GtkD libraries?
Check out https://github.com/gtkd-developers/GtkD



Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread Mike James via Digitalmars-d-learn

On Saturday, 29 August 2015 at 20:15:53 UTC, Marc Schütz wrote:

Just cast to `Crumbs[]` directly:

import std.bitmanip;
import std.stdio;
import std.file;

struct Crumbs {
mixin(bitfields!(
ubyte, one,   2,
ubyte, two,   2,
ubyte, three, 2,
ubyte, four,  2
));
}

void main(string[] argv)
{
auto raw = read(binaryfile);
auto buffer = cast(Crumbs[]) raw;

foreach (cmb; buffer) {
writefln(Crumb one:   %s, cmb.one);
writefln(Crumb two:   %s, cmb.two);
writefln(Crumb three: %s, cmb.three);
writefln(Crumb four:  %s, cmb.four);
}
}


I like that :-)



Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Mike James via Digitalmars-d-learn

On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote:

Hi,

I need to read a binary file, and then process it two bits at a 
time. But I'm a little stuck on the first step. So far I have:


import std.file;
import std.stdio;

void main(){
  auto f = std.file.read(binaryfile);
  auto g = cast(bool[]) f;
  writeln(g);
}

but all the values of g then are just true, could you tell me 
what I'm doing wrong? I've also looked at the bitmanip module, 
I couldn't get it to help, but is that the direction I should 
be looking?


Thanks very much

Andrew


How about...

module main;

import std.bitmanip;
import std.stdio;

struct Crumbs {
@property ref ubyte whole() {
return m_whole;
}

union {
private ubyte m_whole;
mixin(bitfields!(
ubyte, one,   2,
ubyte, two,   2,
ubyte, three, 2,
ubyte, four,  2
));
}
}

void main(string[] argv)
{
ubyte[] buffer = [123, 12, 126, 244, 35];
Crumbs cmb;

foreach (octet; buffer) {
cmb.whole = octet;

writefln(Crumb:   %08b, octet);
writefln(Crumb one:   %s, cmb.one);
writefln(Crumb two:   %s, cmb.two);
writefln(Crumb three: %s, cmb.three);
writefln(Crumb four:  %s, cmb.four);
}
}


Regards, Mike.


Converting Java code to D

2015-04-20 Thread Mike James via Digitalmars-d-learn

Here is a fragment of Java code from an SWT program...

public enum LineStyle {
NONE(None),
SOLID(Solid),
DASH(Dash),
DOT(Dot),
DASHDOT(Dash Dot),
DASHDOTDOT(Dash Dot Dot);

public final String label;

private LineStyle(String label) {
this.label = label;
}
}

What would be the best ('canonical') way of translating it to D?

Regards,

-=mike=-


Re: Converting Java code to D

2015-04-20 Thread Mike James via Digitalmars-d-learn

On Monday, 20 April 2015 at 17:28:27 UTC, John Colvin wrote:

On Monday, 20 April 2015 at 17:24:30 UTC, bearophile wrote:

John Colvin:


struct LineStyle
{
  enum NONE = None;
  enum SOLID = Solid;
  enum DASH = Dash;
  enum DOT = Dot;
  enum DASHDOT = Dash Dot;
  enum DASHDOTDOT = Dash Dot Dot;

  string label;

  private this(string label)
  {
  this.label = label;
  }
}


The constructor doesn't look very useful.

Perhaps a named enum is safer.

Bye,
bearophile


True, the constructor doesn't really add anything here.

To be honest, the combination of enumeration and runtime 
variables in the Java code seems like a rubbish design, but 
perhaps there's a good reason for it that I'm not aware of.


Maybe they extended enum to get over the lack of structs.

Looking at the spec for java enums it appears that you can return
an enumeration or the associated string using the original code.

Regards, -=mike=-


Re: Beginner ?. Why does D suggest to learn java

2014-10-18 Thread Mike James via Digitalmars-d-learn

On Friday, 17 October 2014 at 08:44:00 UTC, Paulo  Pinto wrote:
On Friday, 17 October 2014 at 01:05:37 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

I don't understand. If at least it were C but java? why not D 
itself?
C is *awful* as beginner's language. never ever let people 
start with

C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, 
really! i
believe that it must be featured on the front dlang.org page!) 
but java

has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller 
userbase. and
all that things with classes are reference types and structs 
are not,
empty array is not empty array but is empty array and so on 
D may be
confusing a little. it's good to have some CS background to 
understood

that things.

just my cent and cent.



Better, go with FreePascal http://www.freepascal.org/ and 
discover all that those features that many C advocates spread 
as being close to the machine and other C only features, aren't 
exclusive of it.


Alongside support for real modules, OO and genericity.

Then with a head clean of bad C influences, jump into D.


--
Paulo


Don't tell him that - he may discover Freepascal/Lazarus is the 
holy grail of GUI programming and may never try D...  ;-)


-=mike=-


Re: Initialising multidimensional dynamic arrays

2014-10-01 Thread Mike James via Digitalmars-d-learn
On Tuesday, 30 September 2014 at 17:22:32 UTC, Steven 
Schveighoffer wrote:

On 9/30/14 12:40 PM, Mike James wrote:

On Tuesday, 30 September 2014 at 16:07:28 UTC, ketmar via
Digitalmars-d-learn wrote:



 auto a = new int[][](42, 69);


...



You'll notice that it's actually a dynamic array of structs 
containing

dynamic arrays - does this change your initializing?


That is what his code does.

-Steve


Hi Steve,

It's true that his code initialises an array of arrays - but my 
array is an array of structs containing a dynamic array.


Regards, -=mike=-


Re: Initialising multidimensional dynamic arrays

2014-10-01 Thread Mike James via Digitalmars-d-learn

On Tuesday, 30 September 2014 at 15:57:58 UTC, Mike James wrote:

Hi,

How do I initialise a dynamic array of dynamic arrays?

struct MyData {
  SysTime stamp;
  short[] data;

  this(size_t size) {
data = new short[size];
  }
}

MyDataArray mda;

how to initialise mda?

mda = new MyDataArray ?

Thanks.

Regards, -=mike=-


I think I've found a way...

struct MyData {
  SysTime stamp;
  short[] data;

  this(size_t size) {
data = new short[size];
  }
}

MyDataArray[] mda; --- sorry, missing the []s in the original 
question...


so in the constructor...

this(size_t x, size_t y) {
  mda = new MyDataArray[](x);
foreach(n, _; mda) mda[n].data.length = y;
}

Is there a simpler way?

Regards, -=mike=-


Re: Initialising multidimensional dynamic arrays

2014-10-01 Thread Mike James via Digitalmars-d-learn
On Wednesday, 1 October 2014 at 08:08:06 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Wed, 01 Oct 2014 07:45:48 +
Mike James via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


so in the constructor...

this(size_t x, size_t y) {
   mda = new MyDataArray[](x);
 foreach(n, _; mda) mda[n].data.length = y;
}

Is there a simpler way?
sorry, but no. btw, if MyDataArray is struct, you should do 
this:


  foreach (ref m; mda) m.data.length = y;

or even this:

  foreach (ref m; mda = new MyDataArray[](x)) m.data.length = x;


the thing is that without 'ref' you operates on the local copy, 
not on

the real array element.


Thanks ketmar, that did the trick.

Regards, -=mike=-


Initialising multidimensional dynamic arrays

2014-09-30 Thread Mike James via Digitalmars-d-learn

Hi,

How do I initialise a dynamic array of dynamic arrays?

struct MyData {
  SysTime stamp;
  short[] data;

  this(size_t size) {
data = new short[size];
  }
}

MyDataArray mda;

how to initialise mda?

mda = new MyDataArray ?

Thanks.

Regards, -=mike=-


Re: Initialising multidimensional dynamic arrays

2014-09-30 Thread Mike James via Digitalmars-d-learn
On Tuesday, 30 September 2014 at 16:07:28 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Tue, 30 Sep 2014 15:57:57 +
Mike James via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


How do I initialise a dynamic array of dynamic arrays?

do you mean something like this: `int[][] a`? if yes, do this:

  auto a = new int[][](42, 69);

and you'll get `int[42][69] a`.

heh, people again confused by `new Type[amount]` syntax. that is
concrete sign that this syntax will live forever.


Thanks ketmar,

You'll notice that it's actually a dynamic array of structs 
containing dynamic arrays - does this change your initializing?


Regards, -=mike=-


Re: dgui - Button continually repainting

2014-09-15 Thread Mike James via Digitalmars-d-learn

Hi Andre,

I've found a solution to the repainting problem. If you tick the 
Disable visual themes in the compatibility tab of the program 
properties (associated with the program icon) the button is only 
repainted when the mouse cursor enters and exits the button area.


Regards, -=mike=-

On Wednesday, 10 September 2014 at 19:46:06 UTC, andre wrote:

Hi,
Just noticed there is an event drawItem whichs is called on 
WM_DRAWITEM. Class core.controls.ownerdrawcontrol.d is very 
interesting.

This event seems more suitable.

Kind regards
André


On Wednesday, 10 September 2014 at 07:19:53 UTC, Mike James 
wrote:

//
Please file this issue also on the dgui

bibucket home page.

Kind regards
Andre


//

Done.

Regards, -=mike=-




Re: dgui - Button continually repainting

2014-09-10 Thread Mike James via Digitalmars-d-learn

//
Please file this issue also on the dgui

bibucket home page.

Kind regards
Andre


//

Done.

Regards, -=mike=-


dgui - Button continually repainting

2014-09-09 Thread Mike James via Digitalmars-d-learn

Hi.

I've created a graphic button as per this example on the dgui 
website:


import dgui.all;

class MyForm: Form
{
this()
{
text = An Exception was thrown...;
size = Size(130, 100);

// Or use `Bitmap.fromFile`:
auto img = new Bitmap(90, 15, SystemColors.yellow);
auto pen = SystemPens.blackPen;

with(new Button())
{
bounds = Rect(10, 10, 100, 25);
parent = this;
paint.attach((s, e)
{
e.canvas.drawImage(img, 5, 5);
e.canvas.drawLine(pen, 5, 10, 95, 10);
e.canvas.drawLine(pen, 10, 5, 10, 20);
});
}
}
}

int main()
{
return Application.run(new MyForm());
}

and added a writeln(paint) in the paint.attach to show when the 
button is repainting. When the form with the button is visible 
the button is being continually repainted. Is this a 'feature' of 
dgui or is there a flag to set to only re-paint when the button 
is invalidated?


Regards, -=mike=-.


DMD Compiler - lexer

2014-08-29 Thread Mike James via Digitalmars-d-learn

Hi,

Looking at the DMD Source Guide it says The lexer transforms the 
file into an array of tokens.


Why is this step taken instead of, say, just calling a function 
that returns the next token (or however many required for the 
look-ahead)?


Regards,
  -=mike=-


Re: Command Line Application in D

2014-08-05 Thread Mike James via Digitalmars-d-learn

On Monday, 4 August 2014 at 22:03:24 UTC, TJB wrote:
On Monday, 4 August 2014 at 21:58:09 UTC, maarten van damme via 
Digitalmars-d-learn wrote:

I am a little bit confused as to what you want.
There is a command line example at dlang.org, and there exists 
a program

(rdmd) that compiles several D files and runs them.
http://dlang.org/rdmd.html


Sorry. I wasn't very clear. Say I want to find all of the files 
that have a certain extension within a directory and process 
them somehow at the command line. How could I do that?


Have a look at the function dirEntries in std.file.

regards,

-mike-


DGUI: Using scroll bars

2014-03-25 Thread Mike James
I'm using DGUI (the one on bitbucket) and I can't work out how to 
use the scrollbars. I've got them enabled but I can't work out 
from the library files how to set the scale and read the 
position. Also is there a way of turning off the vertical 
scrollbar - the 'enable' turns them both on.


Any help would be appreciated...

regards,

-=mike=-


Re: Dynamically calling external libraries.

2014-02-26 Thread Mike James
On Wednesday, 26 February 2014 at 14:41:02 UTC, Adam D. Ruppe 
wrote:
You'd do it the same way you do in C. On Windows, call 
LoadLibrary, FreeLibrary, and GetProcAddress or the COM 
functions. On Linux, the family of functions is dlopen, dlsym, 
and dlclose.


Knowing the types to pass the functions is gonna be tricky and 
this needs to be right to avoid crashes. On Windows with 
scripting language, this is often done through COM automation: 
the IDispatch interface. With regular C functions, you really 
just have to know the prototypes ahead of time... it won't be 
fully dynamic, you load the library at run time but know how to 
use it at compile time.


That's the way I do it but I was wondering. Is it better to load 
all the functions from the DLL at the start of the program or 
load them when required and keep having to check if they're 
loaded before each use?


-Mike-


String mixins with string arrays

2013-12-13 Thread Mike James

Hi,

Is it possible to pass a string array to a string mixin e.g

template GenSomething(string foo, string[] bar){
  some_kind_of_foreach(br: bar) {
const char[] foo ~ br ~ ;\n;
  }
}

and call:

mixin(GenSomething!(A, [B, C, D]));

would generate:

A.B;
A.C;
A.D;

Regards,

-=mike=-


Re: String mixins with string arrays

2013-12-13 Thread Mike James

On Friday, 13 December 2013 at 12:09:59 UTC, John Colvin wrote:

On Friday, 13 December 2013 at 11:40:35 UTC, Mike James wrote:

Hi,

Is it possible to pass a string array to a string mixin e.g

template GenSomething(string foo, string[] bar){
 some_kind_of_foreach(br: bar) {
   const char[] foo ~ br ~ ;\n;
 }
}

and call:

mixin(GenSomething!(A, [B, C, D]));

would generate:

A.B;
A.C;
A.D;

Regards,

-=mike=-


CTFE is your friend here.

string genSomething(string foo, string[] bar) {
  string result;
  foreach(br: bar) {
result ~= foo ~ '.' ~ br ~ ;\n;
  }
}

mixin(genSomething(A, [B, C, D]));


Thanks - that worked a treat (just needed a 'return result;').

Regards,

-=mike=-


Re: Overflow-safe use of unsigned integral types

2013-11-10 Thread mike james
On Sunday, 10 November 2013 at 12:05:45 UTC, Joseph Rushton 
Wakeling wrote:
One of the challenges when working with unsigned types is that 
automatic wraparound and implicit conversion can combine to 
unpleasant effect.


Consider e.g.:

void foo(ulong n)
{
writeln(n);
}

void main()
{
foo(-3);
}

... which will output: 18446744073709551613 (or, ulong.max + 1 
- 3).


Is there a recommended way to handle this kind of potential 
wraparound where it is absolutely unacceptable?  I've 
considered the following trick:


void bar(T : ulong)(T n)
{
static if (isSigned!T)
{
enforce(n = 0);// or assert, depending on your 
priorities

}
writeln(n);
}

... but it would be nice if there was some kind of syntax sugar 
in place that would avoid such a verbose solution.


I know that there have been requests for runtime overflow 
detection that is on by default (bearophile?), but it could be 
good to have some simple way to indicate really, no overflow 
even where by default it's not provided.


(Motivation: suppose that you have some kind of function that 
takes a size_t and uses that to determine an allocation.  If a 
negative number gets passed by accident, the function will thus 
try to allocate 2^64 - n elements, and your computer will have 
a very happy time...:-)


When writing software for embedded micros you can always check an 
overflow flag - is the no such mechanism on PC software?



-=mike=-


Re: Tricky code with exceptions

2013-05-09 Thread Mike James


bearophile bearophileh...@lycos.com wrote in message 
news:pnwldlckpgrjvvuje...@forum.dlang.org...


SNIP


My D translation:

import std.stdio;

void main() {
foreach (i; 0 .. 6) {
writeln(Loop: , i);

try {
try {
if (i == 3)
break;
} finally {
if (i % 2 != 0)
throw new Exception();
}
} catch (Exception e) {
writeln(Caught);
}
}
}


It prints:

Loop: 0
Loop: 1
Caught
Loop: 2
Loop: 3

And then it crashes.

Bye,
bearophile


Strangely, if you replace the break instruction with continue (I know 
it's pointless code), it also crashes...


Regards, Mike. 



GtkD - Changing the default windows font

2013-05-03 Thread Mike James
Running on Windows 7, the default font is very thin and indistinct on my 
machine - is there a system setting to change the default font?


regards, Mike. 



Re: goto (outer) case

2013-02-19 Thread Mike James

I'm feeling the wind from Edsger Dijkstra spinning in his grave...

-=mike=-

Nick Sabalausky seewebsitetocontac...@semitwist.com wrote in message 
news:20130218205937.0768@unknown...

Consider these nested switches:

---
enum Foo {a, b}
enum Bar {bar}

auto foo = Foo.a;
auto bar = Bar.bar;

final switch(foo)
{
case Foo.a:
   final switch(bar)
   {
   case Bar.bar:
   XX
   break;
   }
   break;

case Foo.b:
   break;
}
---

Without adding extra code anywhere else, is there anything I can stick
in for XX to get execution to jump to case Foo.b:?

Doing goto case Foo.b; doesn't work. It just gives a compile error
that a Foo can't be implicitly converted to Bar.

This ability isn't critical, of course, but it would help clean up some
code I have.





Re: [beginner] Why nothing is printed to stdout ?

2011-10-30 Thread Mike James
Nick Sabalausky a@a.a wrote in message 
news:j8kd11$25v1$1...@digitalmars.com...
 Frédéric Galusik fr...@salixosnospam.org wrote in message 
 news:j8j77l$pfv$1...@digitalmars.com...
 Hi,

 Can someone give me a clue on why nothing is printed to stdout ?

 I wish a list of files with their size.

 code:
 //
 import std.stdio;
 import std.file;

 void main(string[] args)
 {
foreach (DirEntry e; dirEntries(., SpanMode.shallow))
{
writeln(e.name, \t, e.size);
}
 }
 //
 Build with (dmd2):
 dmd -w test.d


 My aplogies it you already know this, It's not my intention to be 
 patronizing: You did run the resulting executable, right ( ./test )? And 
 there are files in the dir its beng run from?



And you did run it in a DOS window or from a batch file with a PAUSE to 
allow you to read the output ;-)




Re: Compiling Windows GUI-application

2010-08-28 Thread Mike James
Fab fab.cod...@ymail.com wrote in message 
news:i59i02$9...@digitalmars.com...
 Thank you. I am using
 my mobile phone to
 answer so it's pretty
 hard. I will try your
 tips later.

 ps: i wanted to say
 that delphi is slow
 and it seems to be
 old. in addition the
 bindings for sdl,
 allegro and so on are
 bad and there are't
 any free delphi
 versions.

Have you checked out Lazarus/FreePascal?

http://www.lazarus.freepascal.org/index.php?topic=8406.0

-=mike=- 




spawning a thread in a class

2010-07-21 Thread Mike James
I have some old serial comms code written in D1 + Tango and I'm going 
through the process of re-writing it for D2 + Phobos. The old code used 
Thread from the Tango library...


private Thread rxThread;
...
open() {
  ...
   rxThread = new Thread(rxHandler);
   rxThread.start();
   ...
}

private rxHandler() {
   ...
}

The comms class worked fine (although I only ever used as 1 instance :-) )

I'm using the std.concurrency in Phobos to do the threading in the new 
version but I'm having problems passing the address of the receive handler. 
Are there any solutions to this - without making the receive handler static 
or outside the class :-)


Thanks.

-=mike=-



Re: RS232 / USB read/write?

2010-02-01 Thread Mike James
Brian Hay Wrote:

 I'm a bit green with D. I've done some basic D1 + Tango + Derelict stuff 
 but am keen to learn more about D2 + Phobos.
 
 As a learning project I thought I'd like to try reading/writing data 
 streams from/to RS232 and/or USB devices, something I've never done 
 before in any language.
 
 Can anyone give me some pointers and online references? Are there any D 
 libraries for this?

This something I wrote a while ago for D1 + Tango, it will probably need a bit 
of tweeking to get it to the latest compiler version. Sorry for having to 
include it in the body text...

==
module comms;

private import  tango.sys.Common,
tango.time.Time,
tango.stdc.stdint,
tango.io.Stdout,
StdC= tango.stdc.String,
Integer = tango.text.convert.Integer,
Float   = tango.text.convert.Float,
tango.text.Util,
tango.stdc.Stringz,
tango.core.Thread,
tango.io.device.ThreadConduit;
private import  ascii;


public class Comms {
/*
 *  Constants
 */
private const uint  RX_CHAR_COUNT   = 1;
private const char[]ALT_NAME_PREFIX = r\\.\;
private const char[]PORT_NOT_OPEN_EXCEPTION = Serial Port not Open;
public  const uint  INFINITE_TIMEOUT= uint.max;

/*
 *  Enumerations
 */
public enum Parity : ubyte {
None= cast(ubyte)PARITY_NONE,
Odd = cast(ubyte)PARITY_ODD,
Even= cast(ubyte)PARITY_EVEN,
Mark= cast(ubyte)PARITY_MARK,
Space   = cast(ubyte)PARITY_SPACE
}

public enum StopBits : ubyte {
One = cast(ubyte)ONESTOPBIT,
OnePointFive= cast(ubyte)ONE5STOPBITS,
Two = cast(ubyte)TWOSTOPBITS
}

public enum Handshake : int {
None,
Hardware,
Software
}

private enum SigState : int {
Low,
High,
NotUsed
}

private enum WaitFor {
ThreadTerminate,
Event,
MaxSize
}

private HANDLE  hComm   = null;
private HANDLE  hRxThreadStarted= null;
private HANDLE  hRxThreadDone   = null;
private HANDLE  hReadLine   = null;

private Thread  receiveThread;
private ThreadConduit   tcRxConduit;

private boolisOpen_ = false;
private char[]  portName_   = COM1;
private uintbaudrate_   = 9600;
private int dataBits_   = 8;
private StopBitsstopBits_   = StopBits.One;
private Parity  parity_ = Parity.None;
private Handshake   handshake_  = Handshake.None;
private charxonChar_= ASCII.DC1;
private charxoffChar_   = ASCII.DC3;
private charerrorChar_  = ASCII.NUL;
private uintrxQueue_= 0;
private uinttxQueue_= 0;
private SigStatertsState_   = SigState.NotUsed;
private SigStatedtrState_   = SigState.NotUsed;
private SigStatebreakState_ = SigState.NotUsed;
private uintrxTimeout_  = INFINITE_TIMEOUT;
private uinttxTimeoutConst_ = 0;
private uinttxTimeoutMult_  = 0;
private short   xonLowLevel_= 0;
private short   xoffHighLevel_  = 0;
private booldiscardNull_= false;

/*
 *  Delegates
 */
private void delegate(uint, char[]) dgDataEvent;
private void delegate() dgTxEmptyEvent;
private void delegate() dgBreakEvent;
private void delegate(ModemStatus, ModemStatus) dgStatusChangeEvent;
private void delegate(ErrorStatus) dgErrorEvent;

this() {
commonInit();
}

this(char[] portName, uint baudrate, int dataBits, StopBits stopBits, 
Parity parity) {
portName_   = portName;
baudrate_   = baudrate;
dataBits_   = dataBits;
stopBits_   = stopBits;
parity_ = parity;

commonInit();
}

this(char[] portName, uint baudrate) {
portName_   = portName;
baudrate_   = baudrate;

commonInit();
}

~this() {
close();
}

private void commonInit() {
tcRxConduit = new ThreadConduit();
}

/*
 *  Read property
 *  Returns:
 *  Current state of the serial port.
 */
public bool isOpen() {
return isOpen_;
}

/*
 *  Write property
 *  Params:
 *  value = 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 
57600, 115200, 128000, 256000, default 9600.
 *  Returns:
 *  Current Baudrate setting.
 */
public uint baudrate(uint value) {
return baudrate_ = value;
}

   

Pagesize

2009-03-27 Thread Mike James
Is there an optimum size for pagesize? What does the pagesize refer to?

I built DWT-Win and had to increase the pagesize to 4096 before it would build 
successfully. I have just built Tango 0.99.8 with the same pagesize settings 
and I got a warning that the pagesize was  512. I reduced it to 512 and that 
built ok.

Regards, mike.



Re: LPT

2009-03-26 Thread Mike James
Zarathustra Wrote:

 I found a WinIO library. Have you got any expreriance with that in Windows XP?
 By the way of course in the newer computers haven't got LPT but it is not a 
 problem. I want to use LPT to control a machine. 
 
 Mike James Wrote:
 
  Zarathustra Wrote:
  
   Have you got any idea how to manipulate LPT port in Windows XP with D?
  
  Hi,
  
  Try the dlportio driver. I've used it in the past with XP - PIC 
  programmers, etc. :-)
  
  Regards, mike.
 

I've never used WinIO but you can get dlportio from  
http://www.driverlinx.com/DownLoad/DlPortIO.htm

Regards, mike.


Re: LPT

2009-03-25 Thread Mike James
Zarathustra Wrote:

 Have you got any idea how to manipulate LPT port in Windows XP with D?

Hi,

Try the dlportio driver. I've used it in the past with XP - PIC programmers, 
etc. :-)

Regards, mike.


expected array behaviour

2009-01-01 Thread Mike James
I have a function that uses 2 array strings defined similar to this...

const char[] array1 = ABCDEFGHIJKLMNOPQRSTUVWXYZ;
char[]  array2 = ABCDEFGHIJKLMNOPQRSTUVWXYZ;

If I make a change to a char in array1 it also changes the same in array2.
But if I define the arrays as follows...

const char[26] array1 = ABCDEFGHIJKLMNOPQRSTUVWXYZ;
char[26]  array2 = ABCDEFGHIJKLMNOPQRSTUVWXYZ;

It doesn't occur. Is this expected behaviour?

Regards,
-=mike=-


Re: expected array behaviour

2009-01-01 Thread Mike James
Forgot to mention - Windows XP.

Regards,

-=mike=-