private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] buff = new byte[buffersize]; int len = port.BytesToRead; int offset; if (len > buffersize) { len = buffersize; } port.Read(buff, 0, len); port.Close(); offset = 0; SBLinkPackage sbp = new SBLinkPackage(); if (tryGetPackage(buff, len, offset, sbp)) { offset = sbp.PackageSize; if (tryGetPackage(buff, len, offset, sbp)) { state = PortScannerState.Available; protocol = LinkProtocol.SBLink; return; } } Debug.WriteLine("[port scanner]unavilable port(no link):" + name); state = PortScannerState.Unavailable; }
public PortData(string pn, int br, int md) { name = pn; port = new SerialPort(pn); port.BaudRate = br; port.DataBits = 8; port.StopBits = System.IO.Ports.StopBits.One; port.ReceivedBytesThreshold = md; port.DataReceived += Port_DataReceived; buffersize = md + 64; protocol = LinkProtocol.NoLink; state = PortScannerState.NewPort; }