Thread overview
SerialPort
Sep 20, 2018
braboar
Sep 22, 2018
Vladimir Panteleev
Sep 23, 2018
dangbinghoo
Jan 11, 2019
UlanReed
September 20, 2018
I am going to play with serial port read/write, so I fetched serial-port. After that, I wrote simple program:

    auto port_name = "/dev/ttyUSB1";
    auto reader = new SerialPort(port_name);
    reader.dataBits(DataBits.data8);
    reader.stopBits(StopBits.one);
    reader.parity(Parity.none);
    reader.speed(BaudRate.BR_230400);
    string[] income;
    reader.read(income);

and the result is
> serial.device.TimeoutException

Can anybody give me a guide of using serial port?

And one more question: how to outline code blocks? ''' or --- can't help me.
September 22, 2018
On Thursday, 20 September 2018 at 10:51:52 UTC, braboar wrote:
> Can anybody give me a guide of using serial port?

Here's a program I wrote (after lots of trial-and-error) to control my monitor through an USB serial-port adapter:

https://github.com/CyberShadow/misc/blob/master/pq321q.d

Hope this helps.

September 23, 2018
On Thursday, 20 September 2018 at 10:51:52 UTC, braboar wrote:
> I am going to play with serial port read/write, so I fetched serial-port. After that, I wrote simple program:
>
>     auto port_name = "/dev/ttyUSB1";
>     auto reader = new SerialPort(port_name);
>     reader.dataBits(DataBits.data8);
>     reader.stopBits(StopBits.one);
>     reader.parity(Parity.none);
>     reader.speed(BaudRate.BR_230400);
>     string[] income;
>     reader.read(income);
>
> and the result is
>> serial.device.TimeoutException
>
> Can anybody give me a guide of using serial port?
>
> And one more question: how to outline code blocks? ''' or --- can't help me.

here is my code really works:

com is `reader` object in your code.

```
    void writeBytes(ubyte[] arr)
    {
        com.write(arr);
    }

    void serialThread()
    {
        ubyte[500] buff;

        running = true;
        while (running)
        {
            string str;
            size_t readed;

            try
            {
                readed = com.read(buff);
                // if (readed > 0) {
                //writeln("com port readed " ~ std.conv.to!string(readed));
                str = cast(string)(buff[0 .. readed]).idup;
                // Don't use writeln for console or string serail application.
                write(str);
                // }
            }
            // must catch for continous reading, otherwize, com port will block.
            catch (TimeoutException e)
            {
            }
       }
    }
```

thanks!
January 11, 2019
For me https://www.virtual-serial-port.org/products/serialmonitor/ is an ideal way to track down problems that may occur during application or driver development, testing and optimization of serial devices and i use this soft all time.