c# - How do you read the serial port with windows 10 core -
using python on raspberry pi use similar code shown below read data serial port:
baud = 9600 # baud rate port = '/dev/ttyacm0' # serial urf port on computer ser = serial.serial(port, baud) ser.timeout = 0 var message = ser.read(9);
essentially want able read message off serial port , perform action based on message.
how can achieved using windows 10 core , c#, can point me in right direction or provide code sample?
thanks in advance received.
it turns out serial port on pi not supported yet, frustrating: https://www.raspberrypi.org/forums/viewtopic.php?t=109047&p=751638
here supported way:
serialport = await serialdevice.fromidasync(comportid); serialport.writetimeout = timespan.frommilliseconds(1000); serialport.readtimeout = timespan.frommilliseconds(1000); serialport.baudrate = 115200; serialport.parity = serialparity.none; serialport.stopbits = serialstopbitcount.one; serialport.databits = 7; serialport.handshake = serialhandshake.none; serialport.isrequesttosendenabled = true; datareaderobject = new datareader(serialport.inputstream); // set inputstreamoptions complete asynchronous read operation when 1 or more bytes available datareaderobject.inputstreamoptions = inputstreamoptions.partial; // create task object wait data on serialport.inputstream loadasynctask = datareaderobject.loadasync(readbufferlength).astask(cancellationtoken); // launch task , wait uint32 bytesread = await loadasynctask; if (bytesread > 0) { try { var msg = datareaderobject.readstring(bytesread); } catch (exception ex ) { } }
Comments
Post a Comment