using System.Net.Sockets; using System.Net; using static System.Console; var vgaControl = new CVGAControl(true); vgaControl.Initialize(false); int numOfAdaptors = vgaControl.GetNumOfAdaptors(); WriteLine($"Number of adaptors: {numOfAdaptors}"); for (int i = 0; i < numOfAdaptors; i++) { //vgaControl.SelectAdaptor(i); /*var id = vgaControl.GetAdaptorID(i); var name = vgaControl.GetAdaptorName(i); WriteLine($"Id: {id}, name: {name}"); */ WriteLine($"Id: {vgaControl.GetAdaptorID(i)}"); WriteLine($"Name: {vgaControl.GetAdaptorName(i)}"); } var nbEffects = CVGAControl.GetNumOfEffects(1); for (int nEffect = 0; nEffect < nbEffects; ++nEffect) { WriteLine($"Effect id: {CVGAControl.GetEffectID(1, nEffect)}, name: {CVGAControl.GetEffectName(1, nEffect)}"); int nOptionTypes = 0; CVGAControl.GetEffectOptionTypes(1, nEffect, out nOptionTypes); WriteLine($"option types: {nOptionTypes}"); WriteLine($"----------"); } /* for (int i = 0; i <= 100; i++) { var n = 1.0 - (double)i / 100; vgaControl.SetLEDColor(1, (byte)(255.0 * (1.0 - n)), (byte)(255.0 * n), (byte)(20.0 * n)); Thread.Sleep(50); }*/ byte effectId = 0; var optionType = 40; int nType = (optionType & 32) != 0 ? 0 : 1; vgaControl.SetLEDBehavior( 1, // 1 : ALL. effectId, // effectId 0, // nEffect (byte)optionType, // nParams 0, // nSpeed 0, // nDuration (byte)nType, 0, 255 // Brightness. ); // Default color. vgaControl.SetLEDColor(1, 0, 255, 40); vgaControl.SetLEDBehavior( 1, // 1 : ALL. effectId, // effectId 0, // nEffect (byte)optionType, // nParams 0, // nSpeed 0, // nDuration (byte)nType, 0, 255 // Brightness. ); // Default color. vgaControl.SetLEDColor(1, 0, 255, 40); var server = new TcpListener(IPAddress.Loopback, 6577); server.Start(); var buffer = new byte[3]; while (true) { WriteLine("Waiting new client..."); var socket = server.AcceptSocket(); socket.Blocking = true; socket.ReceiveTimeout = 10_000; try { while (socket.Connected) { var n = socket.Receive(buffer, buffer.Length, SocketFlags.None); if (n == 0) { socket.Close(); break; } //WriteLine($"n: {n}, {socket.Connected}"); var r = buffer[0]; var g = buffer[1]; var b = buffer[2]; //WriteLine($"RGB: {r}, {g}, {b}"); vgaControl.SetLEDColor(1, r, g, b); } } catch (SocketException exception) { WriteLine(exception.ToString()); } } vgaControl.Terminate(); WriteLine("Press any key"); Console.ReadKey();