public bool checkRtnMsg(m3piComm ctrl) { // check if there is return msg already if (!ctrl.m_bRtn) { float executeTime = Time.time - ctrl.m_runTime; // check if it is already too long then return and sync up them again if (executeTime < (ctrl.m_cmdTime + 0.5f)) { return(false); } Debug.Log("exe:\t" + executeTime + "\test:\t" + ctrl.m_cmdTime); Debug.Log("wait too long:\t" + executeTime); ctrl.m_exStop = true; return(true); } if (ctrl.m_returnMsg.Length > 0) { Debug.Log(ctrl.m_returnMsg); } ctrl.m_returnMsg = ""; if (StreamSingleton.getInst().getReceiveThread() != null) { //Debug.Log ("abort in checkRtnMsg and return true" + ctrl.receiveThread.ThreadState); StreamSingleton.getInst().getReceiveThread().Abort(); } return(true); }
//unused bool checkRtnMsg() { // check if there is return msg already float executeTime = Time.time - m3piCtrler.m_runTime; if (!m3piCtrler.m_bRtn) { // check if it is already too long then return and sync up them again if (executeTime < (m3piCtrler.m_cmdTime + 0.8f)) { return(false); } else { print("wait too long:\t" + executeTime); m3piCtrler.m_exStop = true; return(true); } } if (m3piCtrler.m_returnMsg.Length > 0) { print(m3piCtrler.m_returnMsg); } m3piCtrler.m_returnMsg = ""; if (StreamSingleton.getInst().getReceiveThread() != null) { StreamSingleton.getInst().getReceiveThread().Abort(); } return(true); }
static public StreamSingleton getInst() { if (stream_inst == null) { stream_inst = new StreamSingleton(); } return(stream_inst); }
public void forward(int step) { if (step > 20) { step = 20; } open(); StreamSingleton.getInst().getStream().Write(encode(step, step)); }
void stopReceivingThread() { foreach (m3piComm m3piCtrl in m3piCtrls) { if ((StreamSingleton.getInst().getReceiveThread().ThreadState == System.Threading.ThreadState.Running) // || (m3piCtrl.receiveThread.ThreadState == System.Threading.ThreadState.Stopped) ) { StreamSingleton.getInst().getReceiveThread().Abort(); print("Done with stopReceivingThread"); } } }
public void open() { if (stream == null) { stream = StreamSingleton.getInst(); } if (stream != null) { if (!stream.getStream().IsOpen) { stream.getStream().Open(); } } }
void OnDestroy() { // foreach (m3piComm mctrl in m3piCtrls) { // if (mctrl.receiveThread != null) { // mctrl.receiveThread.Abort (); // print ("destroy:\t" + mctrl.receiveThread.ThreadState); // } // } // if (StreamSingleton.getInst ().getReceiveThread () != null) { // StreamSingleton.getInst ().getReceiveThread ().Abort (); // print ("destroy:\t" + StreamSingleton.getInst ().getReceiveThread ().ThreadState); // } StreamSingleton.getInst().minusThread(); StreamSingleton.getInst().minusThread(true); }
public SerialCommunication() { stream = null; angleHelpArray = new AngleData[6]; angleHelpArray[0] = new AngleData(15, 2, 56.83f); angleHelpArray[1] = new AngleData(10, 2, 38.1f); angleHelpArray[2] = new AngleData(8, 2, 31.92f); angleHelpArray[3] = new AngleData(6, 2, 22.14f); angleHelpArray[4] = new AngleData(5, 2, 16.7f); angleHelpArray[5] = new AngleData(3, 2, 11.5f); //angleHelpArray[6] = new AngleData(3,1,5.7f); posHelpArray = new PosData[6]; posHelpArray[0] = new PosData(25, 3, 0.206f); posHelpArray[1] = new PosData(20, 3, 0.177f); posHelpArray[2] = new PosData(15, 3, 0.138f); posHelpArray[3] = new PosData(10, 3, 0.0975f); posHelpArray[4] = new PosData(6, 3, 0.064f); posHelpArray[5] = new PosData(3, 3, 0.039f); }
// new version for sharing thread public bool checkRtnMsg2(m3piComm ctrl) { //if (ctrl.m_runTime < 0.1f || ctrl.m_bRtn) if (ctrl.m_bRtn) { return(true); // just started } // check if the command is matched with one of the received msg and will discard unused msg int matchResult = StreamSingleton.getInst().match(ctrl.m_command); if (matchResult == 0) { // matched StreamSingleton.getInst().minusThread(); ctrl.m_bRtn = true; return(true); } // then check if it waits not too long else //(matchResult == 2) { float executeTime = Time.time - ctrl.m_runTime; if (executeTime < (ctrl.m_cmdTime + 0.8f)) { return(false); } else { // too long then stop one, if it is 0 for link count, kill the thread Debug.Log("wait too long:\t" + ctrl.m_cmdTime + "\t" + executeTime); //StreamSingleton.getInst ().setExstop (true); StreamSingleton.getInst().minusThread(); ctrl.m_bRtn = true; // do not need to wait for next return msg return(true); } } //return false; }
void OnDestroy() { // StreamSingleton.getInst().getReceiveThread().Abort (); // print ("destroy:\t" + StreamSingleton.getInst().getReceiveThread().ThreadState); StreamSingleton.getInst().minusThread(); }
void OnDestroy() { //StreamSingleton.getInst ().minusThread (); StreamSingleton.getInst().minusThread(true); }