SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static bool OpenComunicationPort(ComPort_struct Port_struct, ref ACTxRxPorts Port)
  2.         {
  3.             bool status = false;
  4.  
  5.             if (String.Compare(Port_struct.Iface, "COM", true) == 0)
  6.             {
  7.                 if (Port_struct.Parity == null)
  8.                 {
  9.                     Port_struct.Parity = "None";
  10.                 }
  11.                 if (Port_struct.StopBits == null)
  12.                 {
  13.                     Port_struct.StopBits = "One";
  14.                 }
  15.                 Port = new ComPort(Port_struct.BaudRate, Port_struct.Parity, Port_struct.StopBits, 8, 1024, 1024);//
  16.                 var _Port = Port;
  17.                 //                Port = new ComPort(Port_struct.BaudRate, "None","One", 8, 1024, 1024);
  18.                 CTest.Log.Info(String.Format("Trying to open port {0}-{1}!", Port_struct.Iface, Port_struct.PortNum));
  19.                 //if (Port.Open(Port_struct.Iface, Port_struct.PortNum, false))
  20.                 if (SpinWait.SpinUntil(() => {
  21.                         return _Port.Open(Port_struct.Iface, Port_struct.PortNum, false);
  22.                     }
  23.                     ,TimeSpan.FromMinutes(1)))
  24.                 {
  25.                     Port = _Port;   //workaround for ref inside the SpinUntil()
  26.                     CTest.Log.Info(String.Format("Comunication port {0}-{1} is opened!", Port_struct.Iface, Port_struct.PortNum));
  27.                     status = true;
  28.                 }else
  29.                 {
  30.                     Port = _Port;   //workaround for ref inside the SpinUntil()
  31.                     CTest.Log.Error(String.Format("Can't open port {0}-{1}:\"{2}\"", Port_struct.Iface, Port_struct.PortNum, Port.LastError));
  32.                 }
  33.             }
  34.             else
  35.             {
  36.                 CTest.Log.Info(String.Format("Comunication iface:\"{0}\" is not supported!", Port_struct.Iface));
  37.             }
  38.  
  39.             return status;
  40.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top