88using OpenHardwareMonitor . Hardware ;
99using System . Collections . Generic ;
1010using System . IO . Ports ;
11+ using System . Collections ;
1112
1213namespace ConsoleApp1
1314{
@@ -38,6 +39,7 @@ public class Class1
3839 static string serialPortIndex = "" ;
3940 static int baudRateValue = 115200 ;
4041
42+
4143 static void Main ( string [ ] args )
4244 {
4345
@@ -78,6 +80,9 @@ static void Main(string[] args)
7880 Init ( ) ;
7981 Thread thread = new Thread ( SetEsp32 ) ;
8082 thread . Start ( ) ;
83+ Thread thread2 = new Thread ( UpdateReceive ) ;
84+ thread2 . Start ( ) ;
85+
8186 }
8287
8388 static double RamapValue ( double Value , double Low1Val , double High1Val , double Low2Val , double High2Val )
@@ -206,9 +211,7 @@ static void SetEsp32()
206211 Console . WriteLine ( "===================bilibili日出东水===================\n " ) ;
207212 Console . WriteLine ( "ID_1 CPU 使用率: {0} %\n " , cpuLoad ) ;
208213 Console . WriteLine ( "ID_2 CPU 温度: {0} C\n " , cpuTemperature ) ;
209-
210214 Console . WriteLine ( "ID_3 内存使用率: {0} %\n " , ramLoad ) ;
211-
212215 Console . WriteLine ( "ID_4 GPU 使用率: {0} %\n " , gpuLoad ) ;
213216 Console . WriteLine ( "ID_5 GPU 显存占用: {0} %\n " , gpuRamLoad ) ;
214217 Console . WriteLine ( "ID_6 GPU 温度: {0} C\n " , gpuTemperature ) ;
@@ -221,8 +224,9 @@ static void SetEsp32()
221224
222225 Console . WriteLine ( "配置的数据类型: [{0}] / [{1}] \n " , _sendType_1 , _sendType_2 ) ;
223226
224- string sendStr1 = Convert . ToString ( Math . Round ( RamapValue ( _sendValue_1 , 0 , 100.0 , 0 , useVoltage ) , 0 ) ) ;
225- string sendStr2 = Convert . ToString ( Math . Round ( RamapValue ( _sendValue_2 , 0 , 100.0 , 0 , useVoltage ) , 0 ) ) ;
227+ string sendStr1 = Math . Round ( RamapValue ( _sendValue_1 , 0.0 , 99.0 , 0.0 , useVoltage ) , 0 ) . ToString ( "00" ) ;
228+ string sendStr2 = Math . Round ( RamapValue ( _sendValue_2 , 0.0 , 99.0 , 0.0 , useVoltage ) , 0 ) . ToString ( "00" ) ;
229+
226230 Esp32Connected ( sendStr2 + "," + sendStr1 ) ;
227231 Console . WriteLine ( "\n ----------------OpenHardwareMonitor------------------" ) ;
228232 System . Threading . Thread . Sleep ( updateTime ) ;
@@ -294,13 +298,32 @@ static void Init()
294298 computer . Open ( ) ;
295299 }
296300
301+ static void UpdateReceive ( )
302+ {
303+ try
304+ {
305+ while ( true )
306+ {
307+ String input = serialPort . ReadLine ( ) ;
308+ Console . WriteLine ( "回读数据:" + input ) ;
309+ System . Threading . Thread . Sleep ( 0 ) ;
310+ }
311+ }
312+ catch ( Exception _exception )
313+ {
314+ Console . WriteLine ( _exception ) ;
315+ }
316+
317+ }
318+
297319 static void Esp32Connected ( string message )
298320 {
299321 if ( isWiredWireless )
300322 {
301323 if ( serialPort . IsOpen )
302324 {
303- serialPort . WriteLine ( message ) ;
325+ //serialPort.WriteLine(message);
326+ serialPort . Write ( message ) ;
304327 Console . WriteLine ( "串口号: {0} 波特率: {1} 发送信息: {2}" , serialPortIndex , baudRateValue , message ) ;
305328 }
306329 else
0 commit comments