www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SerialPort

reply braboar <braboar gmail.com> writes:
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.
Sep 20 2018
next sibling parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
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.
Sep 21 2018
prev sibling next sibling parent dangbinghoo <dangbinghoo gmail.com> writes:
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!
Sep 23 2018
prev sibling parent UlanReed <spencerkrit78 gmail.com> writes:
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.
Jan 11 2019