public override void StationProcess() { WaitTimeDelay(10); Leftdgv = Form_MidiParser.LeftDgv; if (true == SystemMgr.GetInstance().GetRegBit((int)SysBitReg.LeftRobotReady) && true == SystemMgr.GetInstance().GetRegBit((int)SysBitReg.RightRobotReady)) { RobotMove(); WaitTimeDelay(2000); } }
public override void StationInit() { ShowLog("打开左机器人网口"); m_tcpRobotCtl.Open(); Thread.Sleep(200); if (m_tcpRobotCtl.IsOpen()) { m_tcpRobotCtl.WriteLine("Home"); wait_recevie_cmd(m_tcpRobotCtl, "BackHomeOK", 20000, true, false); } else { throw new Exception("左机器人网口打开失败!"); } SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.LeftRobotReady, true); }
/// <summary> /// 机器人动作 /// </summary> public void RobotMove() { if (Leftdgv != null) { try { int count = Leftdgv.Rows.Count - 2; string ten_str = ""; int ten_count = 0; m_tcpRobotCtl.WriteLine("Move"); //开始执行动作,返回Goon WaitTimeDelay(int.Parse(Leftdgv.Rows[0].Cells[2].Value.ToString()) * Pos.minTickTime); //等第一个时间差 wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); for (int i = 0; i < count; i++) { CheckContinue(); int data1 = int.Parse(Leftdgv.Rows[i].Cells[6].Value.ToString()); //循环获取每一行的mid键位 int data2 = int.Parse(Leftdgv.Rows[i].Cells[7].Value.ToString()); //获取乐器类型 int time = int.Parse(Leftdgv.Rows[i + 1].Cells[2].Value.ToString()); //获取下一行的时间差(Dlt Ticks) int key = KeyReplace(ChangeBlackKeyToWhite(data1)); //转换成机器人的点位 string note = Leftdgv.Rows[i].Cells[5].Value.ToString(); //获取note值 if (key == 0) { continue; //throw new Exception("按键为0,不在范围之内。错误"); } if (note == "NoteOn" || note == "noteon") { currentPos_L = key; if (ConfirmSafe(StationLeftRobot.currentPos_L, StationRightRobot.currentPos_R)) { //一次发送10组数 //wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); string str = string.Format("{0},{1},", key, DelayTimes(time)); ten_str = ten_str + str; ten_count++; if (ten_count % 10 == 0) { wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); m_tcpRobotCtl.WriteLine(ten_str + "\r\n"); //wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); ten_str = ""; } else if (i == count - 1) { int m = ten_count % 10; for (int k = 0; k < 10 - m; k++) { ten_str += "0,0,"; } wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); m_tcpRobotCtl.WriteLine(ten_str + "\r\n"); //wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); } //一次发送一点 //wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); //string strs = string.Format("{0},{1},{2}", key, DelayTimes(time), "\r\n"); //m_tcpRobotCtl.WriteLine(strs); } else { throw new Exception("位置错误,运动会碰撞!"); } } else if (note == "NoteOff" || note == "noteoff") { //正常情况不弹 WaitTimeDelay(time * Pos.minTickTime); } } } catch (Exception e) { throw e; } //歌曲演奏完毕,回原,等待另一只手结束 wait_recevie_cmd(m_tcpRobotCtl, "Goon", 20000, true, false); m_tcpRobotCtl.WriteLine("Home"); currentPos_L = 0; SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.LeftHandlePlayOver, true); while (true) { if (true == SystemMgr.GetInstance().GetRegBit((int)SysBitReg.RightHandlePlayOver)) { SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.RightHandlePlayOver, false); break; } WaitTimeDelay(SystemMgr.GetInstance().ScanTime); CheckContinue(); } } else { //单音轨时,回原,不操作 m_tcpRobotCtl.WriteLine("Home"); currentPos_L = 0; SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.LeftHandlePlayOver, true); WaitTimeDelay(2000); CheckContinue(); } }
public override void InitSecurityState() { SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.LeftRobotReady, false); SystemMgr.GetInstance().WriteRegBit((int)SysBitReg.LeftHandlePlayOver, false); }