Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static bool OpenComunicationPort(ComPort_struct Port_struct, ref ACTxRxPorts Port)
- {
- bool status = false;
- if (String.Compare(Port_struct.Iface, "COM", true) == 0)
- {
- if (Port_struct.Parity == null)
- {
- Port_struct.Parity = "None";
- }
- if (Port_struct.StopBits == null)
- {
- Port_struct.StopBits = "One";
- }
- Port = new ComPort(Port_struct.BaudRate, Port_struct.Parity, Port_struct.StopBits, 8, 1024, 1024);//
- var _Port = Port;
- // Port = new ComPort(Port_struct.BaudRate, "None","One", 8, 1024, 1024);
- CTest.Log.Info(String.Format("Trying to open port {0}-{1}!", Port_struct.Iface, Port_struct.PortNum));
- //if (Port.Open(Port_struct.Iface, Port_struct.PortNum, false))
- if (SpinWait.SpinUntil(() => {
- return _Port.Open(Port_struct.Iface, Port_struct.PortNum, false);
- }
- ,TimeSpan.FromMinutes(1)))
- {
- Port = _Port; //workaround for ref inside the SpinUntil()
- CTest.Log.Info(String.Format("Comunication port {0}-{1} is opened!", Port_struct.Iface, Port_struct.PortNum));
- status = true;
- }else
- {
- Port = _Port; //workaround for ref inside the SpinUntil()
- CTest.Log.Error(String.Format("Can't open port {0}-{1}:\"{2}\"", Port_struct.Iface, Port_struct.PortNum, Port.LastError));
- }
- }
- else
- {
- CTest.Log.Info(String.Format("Comunication iface:\"{0}\" is not supported!", Port_struct.Iface));
- }
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement