dcb.cs
来自「zwave 无线通讯协议 PC controller 控制器源码」· CS 代码 · 共 218 行
CS
218 行
////////////////////////////////////////////////////////////////////////////////////////////////
//
// #######
// # ## #### ##### ##### ## ## #####
// ## ## ## ## ## ## ## ## ##
// ## # ###### ## ## #### ## ## ####
// ## ## ## ## ## ## ##### ##
// ####### #### ## ## ##### ## #####
// #####
// Z-Wave, the wireless language.
//
// Copyright Zensys A/S, 2005
//
// All Rights Reserved
//
// Description:
//
// Author: Morten Damsgaard, Linkage A/S
//
// Last Changed By: $Author: jrm $
// Revision: $Revision: 1.2 $
// Last Changed: $Date: 2007/01/24 10:24:41 $
//
//////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
namespace Zensys.ZWave.Communication
{
//
// The Win32 DCB structure is implemented below in a C# class.
//
[StructLayout(LayoutKind.Sequential)]
internal class DCB
{
private UInt32 DCBlength = 0;
public UInt32 BaudRate = 0;
BitVector32 Control;
internal UInt16 wReserved;
public UInt16 XonLim = 0;
public UInt16 XoffLim = 0;
public byte ByteSize = 0;
public byte Parity = 0;
public byte StopBits = 0;
public sbyte XonChar = 0;
public sbyte XoffChar = 0;
public sbyte ErrorChar = 0;
public sbyte EofChar = 0;
public sbyte EvtChar = 0;
internal UInt16 wReserved1 = 0;
private readonly BitVector32.Section sect1;
private readonly BitVector32.Section DTRsect;
private readonly BitVector32.Section sect2;
private readonly BitVector32.Section RTSsect;
public DCB()
{
//
// Initialize the length of the structure. Marshal.SizeOf returns
// the size of the unmanaged object (basically the object that
// gets marshalled).
//
this.DCBlength = (uint)Marshal.SizeOf(this);
// initialize BitVector32
Control=new BitVector32(0);
// of the following 4 sections only 2 are needed
sect1=BitVector32.CreateSection(0x0f);
DTRsect=BitVector32.CreateSection(3,sect1); // this is where the DTR setting is stored
sect2=BitVector32.CreateSection(0x3f,DTRsect);
RTSsect=BitVector32.CreateSection(3,sect2); // this is where the RTS setting is stored
}
//
// We need to have to define reserved fields in the DCB class definition
// to preserve the size of the
// underlying structure to match the Win32 structure when it is
// marshaled. Use these fields to suppress compiler warnings.
internal void _SuppressCompilerWarnings()
{
wReserved +=0;
wReserved1 +=0;
}
//
// Enumeration for fDtrControl bit field.
//
public enum DtrControlFlags
{
Disable = 0,
Enable =1 ,
Handshake = 2
}
//
// Enumeration for fRtsControl bit field.
//
public enum RtsControlFlags
{
Disable = 0,
Enable = 1,
Handshake = 2,
Toggle = 3
}
// Helper constants for manipulating the bit fields.
// these are defined as an enum in order to preserve memory
[Flags]
enum ctrlBit
{
fBinaryMask = 0x001,
fParityMask = 0x0002,
fOutxCtsFlowMask = 0x0004,
fOutxDsrFlowMask = 0x0008,
fDtrControlMask = 0x0030,
fDsrSensitivityMask = 0x0040,
fTXContinueOnXoffMask = 0x0080,
fOutXMask = 0x0100,
fInXMask = 0x0200,
fErrorCharMask = 0x0400,
fNullMask = 0x0800,
fRtsControlMask = 0x3000,
fAbortOnErrorMask = 0x4000
}
// get and set of bool works with the underlying BitVector32
// by using a mask for each bit field we can let the compiler
// and JIT do the work
//
public bool fBinary
{
get { return (Control[(int)ctrlBit.fBinaryMask]); }
set { Control[(int)ctrlBit.fBinaryMask]=value; }
}
public bool fParity
{
get { return (Control[(int)ctrlBit.fParityMask]); }
set { Control[(int)ctrlBit.fParityMask]=value; }
}
public bool fOutxCtsFlow
{
get { return (Control[(int)ctrlBit.fOutxCtsFlowMask]); }
set { Control[(int)ctrlBit.fOutxCtsFlowMask] = value; }
}
public bool fOutxDsrFlow
{
get { return (Control[(int)ctrlBit.fOutxDsrFlowMask]); }
set { Control[(int)ctrlBit.fOutxDsrFlowMask]=value; }
}
// we have to use a segment because the width of the underlying information
// is wider than just one bit
public byte fDtrControl
{
get {return (byte)Control[DTRsect]; }
set { Control[DTRsect]=(int)value; }
}
public bool fDsrSensitivity
{
get { return Control[(int)ctrlBit.fDsrSensitivityMask];}
set { Control[(int)ctrlBit.fDsrSensitivityMask] = value; }
}
public bool fTXContinueOnXoff
{
get { return Control[(int)ctrlBit.fTXContinueOnXoffMask]; }
set { Control[(int)ctrlBit.fTXContinueOnXoffMask]=value; }
}
public bool fOutX
{
get { return Control [(int)ctrlBit.fOutXMask]; }
set { Control[(int)ctrlBit.fOutXMask]=value; }
}
public bool fInX
{
get { return Control[(int)ctrlBit.fInXMask]; }
set { Control[(int)ctrlBit.fInXMask]=value; }
}
public bool fErrorChar
{
get { return Control[(int)ctrlBit.fErrorCharMask]; }
set { Control[(int)ctrlBit.fErrorCharMask]=value; }
}
public bool fNull
{
get { return Control[(int)ctrlBit.fNullMask]; }
set { Control[(int)ctrlBit.fNullMask]=value; }
}
// we have to use a segment because the width of the underlying information
// is wider than just one bit
public byte fRtsControl
{
get { return (byte)Control[RTSsect]; }
set { Control[RTSsect]=(int)value; }
}
public bool fAbortOnError
{
get { return Control[(int)ctrlBit.fAbortOnErrorMask]; }
set { Control[(int)ctrlBit.fAbortOnErrorMask]=value; }
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?