static void sendMovementFrame(IntPtr device, byte channel, int position) { var frame = new NativeFunctions.candle_frame_t(); { frame.can_id = (deviceID << 19) | (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED; frame.can_dlc = 7; frame.flags = 0; frame.data = new byte[8]; var binaryWriter = new BinaryWriter(new MemoryStream(frame.data)); // Write to TargetPosition register (for Muscle Memory test) binaryWriter.Write((byte)1); binaryWriter.Write((UInt16)12); binaryWriter.Write((Int32)position * 1000); } if (!NativeFunctions.candle_frame_send(device, channel, ref frame)) { Console.Write("Failed to send CAN frame"); } if (NativeFunctions.candle_frame_read(device, out frame, 0)) { Console.Write('R'); } }
static void sendFrames(IntPtr device, byte channel) { var frame = new NativeFunctions.candle_frame_t(); { frame.can_id = (deviceID << 19) | (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED; frame.can_dlc = 7; frame.flags = 0; frame.data = new byte[] { 1, 1, 0, 1, 0, 0, 0, 0, }; } Console.WriteLine("Sending init frame : "); if (!NativeFunctions.candle_frame_send(device, channel, ref frame)) { Console.WriteLine("Failed to send CAN frame"); } Console.WriteLine("Sending moves : "); for (int i = 0; i < 100; i++) { sendMovementFrame(device, channel, i); Console.Write("."); Thread.Sleep(1); } for (int i = 100; i >= 0; i--) { sendMovementFrame(device, channel, i); Console.Write("."); Thread.Sleep(1); } // Send a registry request { frame.data = new byte[] { 0, 1, 0, 0, 0, 0, 0, 0, }; frame.can_dlc = 3; if (!NativeFunctions.candle_frame_send(device, channel, ref frame)) { Console.Write("Failed to send CAN frame"); } } Console.WriteLine("Receiving all : "); int count = 0; while (NativeFunctions.candle_frame_read(device, out frame, 100)) { var id = frame.can_id; if ((id & (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED) > 0) { Console.Write("E, "); } if ((id & (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_RTR) > 0) { Console.Write("R, "); } if ((id & (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_ERR) > 0) { Console.Write("ERR, "); } Console.WriteLine("ID : {0}, DLC : {1}, Data : {2:X},{3:X},{4:X},{5:X},{6:X},{7:X},{8:X},{9:X}, Time : {10}" , id , frame.can_dlc , frame.data[0] , frame.data[1] , frame.data[2] , frame.data[3] , frame.data[4] , frame.data[5] , frame.data[6] , frame.data[7] , frame.timestamp_us / 1000 ); if (count++ > 100) { break; } } }