public unsafe void BuildCommDcb() { DeviceControlBlock dcb = Communications.BuildDeviceControlBlock(@"baud=1200 parity=N data=8 stop=1"); dcb.BaudRate.Should().Be(CommBaudRate.Baud_1200); dcb.Parity.Should().Be(Parity.None); dcb.ByteSize.Should().Be(8); dcb.StopBits.Should().Be(StopBits.One); }
public unsafe void DcbDtrControl(DtrControl dtrControl) { DeviceControlBlock dcb = new DeviceControlBlock() { DtrControl = dtrControl }; dcb.DtrControl.Should().Be(dtrControl); }
public static extern bool BuildCommDCBW( string lpDef, out DeviceControlBlock lpDCB);
public static extern bool SetCommState( SafeFileHandle hFile, ref DeviceControlBlock lpDCB);
protected void BackgroundThread(Object o) { LivePacketDevice dev = o as LivePacketDevice; DeviceControlBlock info = ExtraInfos[dev.Name]; while (!info.BackgroundThreadStop) { bool shouldSleep = true; lock (info.QueueLock) { if (info.PacketQueue.Count != 0) { shouldSleep = false; } } if (shouldSleep) { System.Threading.Thread.Sleep(1000); } else // should process the queue { List <Packet> ourQueue; lock (info.QueueLock) { // swap queues, giving the capture callback a new one ourQueue = info.PacketQueue; info.PacketQueue = new List <Packet>(); } StatisticsInfo ourStat = new StatisticsInfo(0, 0); double totbit = 0; DateTime earlist = DateTime.MaxValue; DateTime latest = DateTime.MinValue; foreach (var pk in ourQueue) { // Timestamp and length. if (pk.Timestamp < earlist) { earlist = pk.Timestamp; } if (pk.Timestamp > latest) { latest = pk.Timestamp; } totbit += pk.Length * 8; ourStat.CInfo += SingleAnalyzer.SortPacket(pk); } if (info.LastTimestamp != DateTime.MinValue) { double delay = (latest - info.LastTimestamp).TotalMilliseconds; ourStat.Bps = totbit * 1000 / delay; ourStat.Pps = ourQueue.Count * 1000 / delay; } else { ourStat.Bps = ourStat.Pps = 0; } info.LastTimestamp = latest; _Statistics[dev.Name] = ourStat; } } }