io控制

机械臂底部Basic和末端Atom上都有引脚,可以通过io控制设置引脚的高低电平,控制系泵等工具(引脚号可以查看Basic和Atom引脚处贴的引脚标签,输入输出共用)。

1 basic io控制(m5)

1.1 设置输出io高低电平

SetBasicOut(byte pin_number, byte pin_signal)
返回值:无
参数说明:参数1:引脚号(basic输出引脚号),参数2:状态(0--低电平,1--高电平)
案例:

mc.SetBasicOut(2, 1);
Thread.Sleep(100);
mc.SetBasicOut(5, 1);
Thread.Sleep(100);

1.2 获取输入io状态

GetBasicIn(byte pin_number)
返回值:引脚状态(0--低电平,1--高电平)
参数说明:引脚号(basic输入引脚号)
案例:设置输出引脚2为高电平

Console.WriteLine(mc.GetBasicIn(35));
Thread.Sleep(100);
Console.WriteLine(mc.GetBasicIn(36));
Thread.Sleep(100);

2 Atom io控制

注意:320m5无atom io,所以不需要用到此模块API

2.1 设置输出io高低电平

SetDigitalOut(byte pin_number, byte pin_signal)
返回值:无
参数说明:参数1:引脚号(atom输出引脚号),参数2:状态(0--低电平,1--高电平)
案例:

mc.SetDigitalOut(23, 0);
Thread.Sleep(100);
mc.SetDigitalOut(33, 0);
Thread.Sleep(100);

2.2 获取输入io状态

GetDigitalIn(byte pin_number)
返回值:引脚状态(0--低电平,1--高电平)
参数说明:引脚号(atom输入引脚号)
案例:

Console.WriteLine(mc.GetDigitalIn(19));
Thread.Sleep(100);
Console.WriteLine(mc.GetDigitalIn(22));
Thread.Sleep(100);

3 完整使用案例

using System;
using System.Threading;

namespace Mycobot.csharp
{
    class Test
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("COM57");//树莓派机械臂串口名称:/dev/ttyAMA0
            mc.Open();
            Thread.Sleep(5000);//windows打开串口后,需要等待5s,Windows打开串口底部basic会重启

            //set basic output io
            /*mc.SetBasicOut(2, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(5, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(26, 1);
            Thread.Sleep(100);*/

            //get basic input io
            Console.WriteLine(mc.GetBasicIn(35));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetBasicIn(36));
            Thread.Sleep(100);

            //set atom output io
            /*mc.SetDigitalOut(23, 0);
            Thread.Sleep(100);
            mc.SetDigitalOut(33, 0);
            Thread.Sleep(100);*/

            //get m5 input io
            /*Console.WriteLine(mc.GetDigitalIn(19));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetDigitalIn(22));
            Thread.Sleep(100);*/

            mc.Close();
        }
    }
}

results matching ""

    No results matching ""