示例#1
0
        private byte[] CommandStruct_to_Bytes(CTP_packet command)
        {
            byte[] arr = new byte[Marshal.SizeOf(command)];
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(command));

            Marshal.StructureToPtr(command, ptr, true);
            Marshal.Copy(ptr, arr, 0, Marshal.SizeOf(command));
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }
示例#2
0
 private byte ReadByteAfterCommand(CTP_packet _command)
 {
     if (connection.IsOpen == false)
     {
         return(0);
     }
     connection.Write(CommandStruct_to_Bytes(command), 0, Marshal.SizeOf(command) - 1);
     byte[] buffer = new byte[1];
     connection.Read(buffer, 0, 1);
     Console.WriteLine($"Recieved after command: {Convert.ToInt32(buffer[0])}");
     return(buffer[0]);
 }
示例#3
0
 public Microcontroller()
 {
     connection             = new System.IO.Ports.SerialPort();
     connection.BaudRate    = 9600;
     connection.Parity      = System.IO.Ports.Parity.None;
     connection.StopBits    = System.IO.Ports.StopBits.One;
     connection.DataBits    = 8;
     connection.ReadTimeout = 300;
     command = new CTP_packet();
     //Check_phisically_connected();
     Console.WriteLine("Here building and connected Arduino");
     if (Check_phisically_connected() == false)
     {
         Console.WriteLine("Microcontroller device not found.");
         throw new Exception("Microcontroller device not found.");
     }
     else
     {
         Console.WriteLine("Arduino connection opened!!!");
     }
 }