Advertisement
Guest User

Untitled

a guest
Jan 4th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.IO.Ports;
  3. namespace Robot
  4. {
  5.     enum CommandEnum{
  6.         Unknown = 0,
  7.         ReleaseAllServos = 1,
  8.         SetSerialMacro = 2,
  9.         SetI2CMacro = 3,
  10.         WriteConfiguration = 4,
  11.         ReadConfiguration = 5,
  12.         StatusLED = 6,
  13.         I2CStart = 7,
  14.         I2CRestart = 8,
  15.         I2CStop = 9,
  16.         I2CWrite = 10,
  17.         I2CRead = 11,
  18.         I2CReadAutoAck = 12,
  19.         I2CPoll = 13,
  20.         BootLoader = 14,
  21.         SetPWMSpeed = 15,
  22.         BV4113_Cmd = 35,
  23.         SetServoSpeed = 40,
  24.         Ping = 85,
  25.         SetDigitalPortOn = 100,
  26.         SetDigitalPortOff = 120,
  27.         GetDigitalPort = 140,
  28.         SetServoPosition = 160,
  29.         GetADCValue = 180,
  30.         SendSerial = 190,
  31.         HC_SR04 = 210,
  32.         PlayNote = 230,
  33.     };
  34.  
  35.     class MainClass
  36.     {
  37.         static SerialPort connection;
  38.  
  39.         public static void Main (string[] args)
  40.         {
  41.  
  42.             connection = new SerialPort ("COM3");
  43.             connection.Open ();
  44.             byte[] buffer = new byte[1];
  45.             buffer [0] = (byte)CommandEnum.Ping;
  46.        
  47.  
  48.             Console.WriteLine ("GOING TO WRITE");
  49.  
  50.             string writing = "";
  51.             while (!writing.Equals("quit")) {
  52.                 writing = Console.ReadLine();
  53.                 connection.Write(buffer, 0, 1);
  54.                 Console.WriteLine ("WROTE");
  55.                 byte[] readBuffer = new byte[1];
  56.                 connection.Read(readBuffer, 0, 1);
  57.  
  58.                 Console.WriteLine("READ " + readBuffer[0]);
  59.  
  60.             }
  61.  
  62.  
  63.  
  64.  
  65.             Console.Read();
  66.             Console.Read();
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement