master
wangyueyang 5 months ago
parent e452ac00c7
commit 2fd4b21b55

@ -13,8 +13,11 @@ internal class Program
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\log4net.xml"));
string s = "55 AA 00 00 01 01 00 D9 00 00 00 00 00 00 0E 00 00 00 0E 00 25 64 69 73 70 30 3B 31 CD A3 D7 BC C1 CB 00 00 0D 0A".Replace(" ", "");
for (int i = 0; i < s.Length-1; i+=2)
{
Console.Write($"0x{s[i]}{s[i+1]},");
}
ExportDb exportDb = new ExportDb();
exportDb.Export();
}
}

@ -1,4 +1,5 @@
using System.Net.Sockets;
using HybirdFrameworkCore.Utils;
using log4net;
namespace Service.Led;
@ -13,18 +14,14 @@ public class LedClient
"houtui",
new byte[]
{
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x34, 0xBA, 0xF3, 0xCD, 0xCB, 0x00, 0x00,
0x0D, 0x0A
0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x0C,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x36,0xCE,0xDE,0xB3,0xB5,0x00,0x00,0x0D,0x0A
}
},
{
"qianjin",
new byte[]
{
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x37, 0xC7, 0xB0, 0xBD, 0xF8, 0x00, 0x00,
0x0D, 0x0A
0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x0E,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3B,0x31,0xCD,0xA3,0xD7,0xBC,0xC1,0xCB,0x00,0x00,0x0D,0x0A
}
},
{
@ -95,22 +92,36 @@ public class LedClient
#endregion
private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient));
private static TcpClient? _tcpClient;
private static Socket? _socket;
private static string _ip;
private static int _port;
public static bool Init(string ip, int port)
{
Log.Info($"begin connect {ip}:{port}");
_tcpClient = new TcpClient();
_tcpClient.Connect(ip, port);
Log.Info($"end connect {ip}:{port} {_tcpClient.Connected}");
return _tcpClient.Connected;
_ip = ip;
_port = port;
Connect();
return _socket.Connected;
}
private static void Connect()
{
Log.Info($"begin connect {_ip}:{_port}");
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket.NoDelay = true;
_socket.Connect(_ip, _port);
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
}
public static bool InnerSend(byte[] bytes)
{
if (_tcpClient?.Connected ?? true)
Connect();
if (_socket?.Connected ?? true)
{
_tcpClient.GetStream().Write(bytes, 0, bytes.Length);
_socket?.Send(bytes);
Log.Info($"send {BitUtls.BytesToHexStr(bytes)}");
_socket?.Close();
return true;
}
return false;

@ -114,17 +114,17 @@
"enable": false
},
"plc": {
"enable": true
"enable": false
},
"swap": {
"enable": true
"enable": false
},
"task": {
"enable": false
},
"led": {
"enable": false,
"ip": "127.0.0.1",
"port": 10021
"enable": true,
"ip": "192.168.3.79",
"port": 10000
}
}

Loading…
Cancel
Save