The code below should establish an auto connection.
It cycles through all available serial comms and sees if it gets an connection and sends a handshake to see if it is the david laserscanner
Rewrote the code for the constructor and the handshake routine
Constructor
publicSync(){foreach(stringportNameinSerialPort.GetPortNames()){try{_sp=newSerialPort(portName,115200,Parity.None,8,StopBits.One);_sp.Open();}catch{_sp.Close();_sp.Dispose();}try{if(_sp.IsOpen&&_handShake()){break;}else{_sp.Close();_sp.Dispose();}}}if(!_sp.IsOpen){thrownewArgumentException("No Davidscanner connected");}if(_sp.IsOpen&&!_inSync){thrownewArgumentException("Could not enter SYNCMODE");}}
Private _handShake method
privatebool_handShake(){boolhandshakeEstablished=false;_sp.ReceivedBytesThreshold=14;try{_sp.WriteLine("ENTERSYNCMODE");System.Threading.Thread.Sleep(100);stringdavidHandshake;if(_sp.BytesToRead>0){davidHandshake=_sp.ReadTo("!");if(davidHandshake=="ENTERSYNCMODE"){handshakeEstablished=true;}}}catch(ArgumentException){thrownewArgumentException("Could not enter SYNCMODE");}_inSync=handshakeEstablished;_sp.ReceivedBytesThreshold=8;returnhandshakeEstablished;}
The code below should establish an auto connection.
It cycles through all available serial comms and sees if it gets an connection and sends a handshake to see if it is the david laserscanner
the code for the PC
the constructor for SYNC.dll
the code for the arduino in the main loop
Rewrote the code for the constructor and the handshake routine
Constructor
Private _handShake method
Arduino Code Main loop
Arduino Code SYNC.cpp