public (string port, int count) Connect(int tentativaDeConexao) { var ports = SerialPort.GetPortNames().Where(x => x.Equals("COM6")).OrderByDescending(x => x).ToList();// Todo - testar as outras portas if (SerialPort?.IsOpen == true) { SerialPort.Close(); } Bytes.Clear(); if (ports.Count <= tentativaDeConexao) { tentativaDeConexao = 0; } var port = ports[tentativaDeConexao]; if (string.IsNullOrWhiteSpace(port)) { throw new InvalidOperationException("Nobreak não está conectado"); } SerialPort = new SerialPort(port, 2400, Parity.None, 8, StopBits.One); SerialPort.Open(); SerialPort.DataReceived += Rx; GetStatus(); return(port, tentativaDeConexao); }
// Set default values. public override void SetDefault() { Bytes.Clear(); Bytes.Add(1); startAddressPC = DefaultStartAddress; }
/// <summary> /// The final steps for preparing the NetworkingStream /// </summary> /// <param name="socket">The NetWorker socket to be used</param> /// <param name="identifierType">The type of Identifier it is going to prepare</param> /// <param name="behaviorNetworkId">NetworkedBehavior to use</param> /// <param name="extra">Extra parameters to prepare</param> /// <param name="receivers">Who shall be receiving this NetworkingStream</param> /// <param name="bufferedRPC">To know if this is a Buffered RPC</param> /// <param name="customidentifier">A custom Identifier to be passed through</param> /// <returns></returns> public NetworkingStream PrepareFinal(NetWorker socket, IdentifierType identifierType, ulong behaviorNetworkId, BMSByte extra = null, NetworkReceivers receivers = NetworkReceivers.All, bool bufferedRPC = false, uint customidentifier = 0, ulong senderId = 0) { lock (networkedObjectMutex) { if (senderId == 0) { senderId = socket.Me != null ? socket.Me.NetworkId : 0; } NetworkedBehaviorId = behaviorNetworkId; RealSenderId = senderId; Receivers = receivers; Customidentifier = customidentifier; BufferedRPC = Receivers == NetworkReceivers.AllBuffered || Receivers == NetworkReceivers.OthersBuffered; Bytes.Clear(); ObjectMapper.MapBytes(bytes, (int)ProtocolType); ObjectMapper.MapBytes(bytes, (int)receivers); ObjectMapper.MapBytes(bytes, socket.Uniqueidentifier); if (ProtocolType != Networking.ProtocolType.HTTP && ProtocolType != Networking.ProtocolType.QuickUDP && ProtocolType != Networking.ProtocolType.QuickTCP) { this.identifierType = identifierType; if (identifierType == IdentifierType.None) { Bytes.BlockCopy <byte>(((byte)identifier_NONE), 1); } else if (identifierType == IdentifierType.RPC) { Bytes.BlockCopy <byte>(((byte)identifier_RPC), 1); Bytes.BlockCopy <byte>(((byte)(bufferedRPC ? 1 : 0)), 1); } else if (identifierType == IdentifierType.Player) { Bytes.BlockCopy <byte>(((byte)identifier_PLAYER), 1); } else if (identifierType == IdentifierType.NetworkedBehavior) { Bytes.BlockCopy <byte>(((byte)identifier_NETWORKED_BEHAVIOR), 1); } else if (identifierType == IdentifierType.Disconnect) { Bytes.BlockCopy <byte>(((byte)identifier_DISCONNECT), 1); } else if (identifierType == IdentifierType.Custom) { Bytes.BlockCopy <byte>(((byte)identifier_CUSTOM), 1); } ObjectMapper.MapBytes(bytes, behaviorNetworkId); } if (identifierType == IdentifierType.Custom) { ObjectMapper.MapBytes(bytes, Customidentifier); } if (extra != null) { Bytes.BlockCopy(extra.byteArr, extra.StartIndex(), extra.Size); } if (!ReferenceEquals(NetworkingManager.Instance, null)) { ObjectMapper.MapBytes(Bytes, NetworkingManager.Instance.CurrentFrame); } else { ObjectMapper.MapBytes(Bytes, (byte)0); } if (ProtocolType == Networking.ProtocolType.TCP) { List <byte> head = new List <byte>(BitConverter.GetBytes(Bytes.Size + 1)); head.Add(0); Bytes.InsertRange(0, head.ToArray()); } Ready = true; return(this); } }
public void Reset() { Ready = false; Bytes.Clear(); QueuedRPC = false; }
public void Dispose() => buffer.Clear();
public void clear() { Postion = 0; Bytes.Clear(); }
public void Reset() { Ready = false; Bytes.Clear(); SkipReplication = false; }