using System; using System.Threading; using AG.Comm; namespace PoloruTest { class Class1 { // ƒGƒ“ƒgƒŠ ƒ|ƒCƒ“ƒg [STAThread] static void Main(string[] args) { byte port = 1; AGComm myComm = new AGComm(); myComm.BaudRate = 9600; byte[] sndData; byte speed; if (myComm.OpenPort(port)) { Console.WriteLine("{0}”ΤƒI[ƒvƒ“" , port); // // ’΄¬Œ^DCƒ‚[ƒ^ƒRƒ“ƒgƒ[ƒ‰ƒRƒ}ƒ“ƒh // ‚O”Ԑ³“]@[0x80,0x00,0x05,speed]1 // ‚O”Τ‹t“]@[0x80,0x00,0x04,speed]0 // ‚P”Ԑ³“]@[0x80,0x00,0x07,speed]3 // ‚P”Τ‹t“]@[0x80,0x00,0x06,speed] // ¦’βŽ~‚̏ꍇ‚Νspeed=0 // ¦speed ‚Ν0x00-0x7F(10i”‚Ε0`127) // // ƒ_ƒ~[ƒf[ƒ^‘—M sndData = new byte[] {0x80,0x00,0x05,0x00}; MoveMotor(myComm,"ƒVƒ“ƒNƒƒf[ƒ^",sndData); // ‰Α‘¬ for (byte i = 0; i < 100; i++) { sndData = new byte[] {0x80,0x00,0x05,i}; MoveMotor(myComm,"‚O”Ԑ³“]",sndData); sndData = new byte[] {0x80,0x00,0x07,i}; MoveMotor(myComm,"‚P”Ԑ³“]",sndData); } // ’βŽ~ speed = 0; sndData = new byte[] {0x80,0x00,0x05,speed}; MoveMotor(myComm,"‚O”Τ’βŽ~",sndData); sndData = new byte[] {0x80,0x00,0x07,speed}; MoveMotor(myComm,"‚P”Τ’βŽ~",sndData); // ƒoƒbƒN speed = 40; sndData = new byte[] {0x80,0x00,0x04,speed}; MoveMotor(myComm,"‚O”Τ‹t“]",sndData); sndData = new byte[] {0x80,0x00,0x06,speed}; MoveMotor(myComm,"‚P”Τ‹t“]",sndData); Thread.Sleep(1500); // ’΄M’nω‰ρ sndData = new byte[] {0x80,0x00,0x05,speed}; MoveMotor(myComm,"‚O”Ԑ³“]",sndData); sndData = new byte[] {0x80,0x00,0x06,speed}; MoveMotor(myComm,"‚P”Τ‹t“]",sndData); Thread.Sleep(800); // M’nω‰ρ sndData = new byte[] {0x80,0x00,0x05,0x00}; MoveMotor(myComm,"‚O”Τ’βŽ~",sndData); sndData = new byte[] {0x80,0x00,0x07,speed}; MoveMotor(myComm,"‚P”Ԑ³“]",sndData); Thread.Sleep(2000); // ’βŽ~ speed = 0; sndData = new byte[] {0x80,0x00,0x05,speed}; MoveMotor(myComm,"‚O”Τ’βŽ~",sndData); sndData = new byte[] {0x80,0x00,0x07,speed}; MoveMotor(myComm,"‚P”Τ’βŽ~",sndData); Console.WriteLine("{0}”ΤƒNƒ[ƒY", port); myComm.ClosePort(); } else Console.WriteLine("{0}”ΤƒI[ƒvƒ“‚Ε‚«‚Θ‚’B", port); } // ƒf[ƒ^‘—Mƒƒ\ƒbƒh static void MoveMotor(AGComm mCom, string s,byte[] data) { if(mCom.ClearWriteBuffer()) Console.WriteLine("‘—MΚή―Μ§ƒNƒŠƒA¬Œχ"); else Console.WriteLine("‘—MΚή―Μ§ƒNƒŠƒAŽΈ”s"); if (mCom.SendData(data)) Console.WriteLine(s + ':' + "‘—M¬Œχ"); else Console.WriteLine(s + ':' + "‘—MŽΈ”s"); } } }