private void autoDetect(ChronopicAuto caNormal) { LogB.Information("starting port detection"); string [] usbSerial = ChronopicPorts.GetPorts(); bool first = true; foreach (string port in usbSerial) { if (configAutoDetect == Config.AutodetectPortEnum.DISCARDFIRST && first) { first = false; LogB.Warning("Discarded port = ", port); continue; } SerialPort sp = new SerialPort(port); LogB.Information("searching normal Chronopic at port: ", port); string readed = caNormal.Read(sp); if (caNormal.Found == ChronopicType.NORMAL) //We found a normal Chronopic { if (searched == ChronopicType.NORMAL) //normal Chronopic is what we are searching { Detected = port; return; } else { /* * else: * means that we are searching for an encoder chronopic and found a normal * so don't try to search for an encoder on that port, because 115200 bauds will saturate it */ LogB.Information("our goal is to search encoder but found normal Chronopic at port: ", port); } } else if (searched == ChronopicType.ENCODER) { /* * we are searching an encoder * if we arrived here, we know is not a normal chronopic * then wecan search safely for an encoder here */ ChronopicAuto caEncoder = new ChronopicAutoCheckEncoder(); caEncoder.IsEncoder = true; //for the bauds. LogB.Information("searching encoder Chronopic at port: ", port); readed = caEncoder.Read(sp); if (caEncoder.Found == ChronopicType.ENCODER) { Detected = port; return; } } } Detected = ""; }
protected override void select() { l_types = new List <object>(); string [] strArray = ChronopicPorts.GetPorts(); foreach (string str in strArray) { l_types.Add(str); } }
private void setEncoderPort(string myEncoderPort) { if (Util.FoundInStringArray(ChronopicPorts.GetPorts(), myEncoderPort)) { encoderPort = myEncoderPort; } else { encoderPort = Util.GetDefaultPort(); } }
private List <string> getPorts(bool debug) { //TODO: move that method here List <string> l = new List <string>(ChronopicPorts.GetPorts()); //usb-serial ports if (debug) { foreach (string p in l) { LogB.Information(string.Format("port: " + p)); } } return(l); }
ArrayList detectPorts() { //detect ports string [] ports = ChronopicPorts.GetPorts(); //get only new ports ArrayList portsNew = new ArrayList(0); foreach (string pNew in ports) { if (!Util.FoundInArrayList(portsAlreadyDetected, pNew)) { portsAlreadyDetected.Add(pNew); portsNew.Add(pNew); } } return(portsNew); }