46 changed files with 114 additions and 707 deletions
@ -1,9 +1,9 @@
@@ -1,9 +1,9 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://05atvgqt8tku"] |
||||
|
||||
[ext_resource type="Texture2D" uid="uid://ss8dh8aaqc4w" path="res://Example/Action3D/SkyBox/lakeside.jpg" id="1_akq3m"] |
||||
[ext_resource type="Texture2D" uid="uid://ss8dh8aaqc4w" path="res://Example/OldTest/Action3D/SkyBox/lakeside.jpg" id="1_akq3m"] |
||||
[ext_resource type="Texture2D" uid="uid://31r216hix0wk" path="res://icon.svg" id="2_b66wh"] |
||||
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionPlayer.cs" id="2_c0s4j"] |
||||
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionCamera.cs" id="3_ue0e3"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Action3D/Script/ActionPlayer.cs" id="2_c0s4j"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Action3D/Script/ActionCamera.cs" id="3_ue0e3"] |
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_hbme1"] |
||||
panorama = ExtResource("1_akq3m") |
Before Width: | Height: | Size: 4.1 MiB After Width: | Height: | Size: 4.1 MiB |
@ -1,9 +1,9 @@
@@ -1,9 +1,9 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://hp4ae14r3hpm"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewGateway.cs" id="1_tas7d"] |
||||
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewTcpGateway.cs" id="2_ct4oh"] |
||||
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewBacNetGateway.cs" id="3_ip8nj"] |
||||
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewBacnetHttpServer.cs" id="4_plubp"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewGateway.cs" id="1_tas7d"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewTcpGateway.cs" id="2_ct4oh"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewBacNetGateway.cs" id="3_ip8nj"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewBacnetHttpServer.cs" id="4_plubp"] |
||||
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="5_q4lsg"] |
||||
|
||||
[node name="Gateway" type="Control"] |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c8vhi8ojdtjnb"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/Gateway/Script/View/ViewModbusGateway.cs" id="1_34uaa"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/Gateway/Script/View/ViewModbusGateway.cs" id="1_34uaa"] |
||||
|
||||
[node name="ModbusGateway" type="Control"] |
||||
layout_mode = 3 |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c8kk7iegicmdr"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewModbusItem.cs" id="1_ih8g3"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewModbusItem.cs" id="1_ih8g3"] |
||||
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="1_upshn"] |
||||
|
||||
[node name="ModbusItem" type="Control"] |
@ -1,11 +1,11 @@
@@ -1,11 +1,11 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://qo2w16ececmu"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewMenu.cs" id="1_7ubyu"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewMenu.cs" id="1_7ubyu"] |
||||
[ext_resource type="FontFile" uid="uid://b1atsgy4xkk7d" path="res://Font/SourceHanSansCN-Regular.otf" id="1_tw1qu"] |
||||
[ext_resource type="PackedScene" uid="uid://c8kk7iegicmdr" path="res://Example/ModbusDebugTool/Component/modbus_item.tscn" id="3_c8jeq"] |
||||
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewEdit.cs" id="4_smsvf"] |
||||
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewMessage.cs" id="5_8s6lk"] |
||||
[ext_resource type="Script" path="res://Example/ModbusDebugTool/Script/ViewSettings.cs" id="6_38tri"] |
||||
[ext_resource type="PackedScene" uid="uid://c8kk7iegicmdr" path="res://Example/OldTest/ModbusDebugTool/Component/modbus_item.tscn" id="3_c8jeq"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewEdit.cs" id="4_smsvf"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewMessage.cs" id="5_8s6lk"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/ModbusDebugTool/Script/ViewSettings.cs" id="6_38tri"] |
||||
|
||||
[node name="Menu" type="Control"] |
||||
layout_mode = 3 |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bhsavl0d80s6j"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs" id="1_j773b"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/SystemExamples/PlayerStorage/Script/DataStorageItem.cs" id="1_j773b"] |
||||
|
||||
[resource] |
||||
script = ExtResource("1_j773b") |
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://tee7nc525si7"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs" id="1_goow2"] |
||||
[ext_resource type="Script" path="res://Example/OldTest/SystemExamples/PlayerStorage/Script/ViewStorage.cs" id="1_goow2"] |
||||
|
||||
[node name="PlayerStorage" type="Control"] |
||||
layout_mode = 3 |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bvnma1n064xbx"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/SaveSystem/Script/ViewSaveSystem.cs" id="1_mtdgp"] |
||||
|
||||
[node name="SaveSystem" type="Control"] |
||||
layout_mode = 3 |
||||
anchors_preset = 15 |
||||
anchor_right = 1.0 |
||||
anchor_bottom = 1.0 |
||||
grow_horizontal = 2 |
||||
grow_vertical = 2 |
||||
script = ExtResource("1_mtdgp") |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using Godot; |
||||
using LiteDB; |
||||
using Renci.SshNet; |
||||
|
||||
namespace EGFramework.Examples.Test{ |
||||
public partial class ViewSaveSystem : Node,IEGFramework |
||||
{ |
||||
public override void _Ready() |
||||
{ |
||||
|
||||
} |
||||
|
||||
public override void _ExitTree() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
[gd_resource type="StyleBoxFlat" format=3 uid="uid://t4prctf3uxtb"] |
||||
|
||||
[resource] |
||||
bg_color = Color(0.858824, 0.858824, 0.858824, 1) |
||||
border_width_left = 2 |
||||
border_width_top = 2 |
||||
border_width_right = 2 |
||||
border_width_bottom = 2 |
||||
border_color = Color(0, 0, 0, 1) |
||||
corner_radius_top_left = 16 |
||||
corner_radius_top_right = 16 |
||||
corner_radius_bottom_right = 16 |
||||
corner_radius_bottom_left = 16 |
||||
corner_detail = 1 |
@ -1,3 +0,0 @@
@@ -1,3 +0,0 @@
|
||||
[gd_resource type="Theme" format=3 uid="uid://cbf2s7b2p1p2j"] |
||||
|
||||
[resource] |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dfa86yq8m28rk"] |
||||
|
||||
[ext_resource type="Script" path="res://Example/UsingTest/Script/EGSaveTest.cs" id="1_eij2h"] |
||||
|
||||
[node name="Test" type="Control"] |
||||
layout_mode = 3 |
||||
anchors_preset = 15 |
||||
anchor_right = 1.0 |
||||
anchor_bottom = 1.0 |
||||
grow_horizontal = 2 |
||||
grow_vertical = 2 |
||||
script = ExtResource("1_eij2h") |
||||
|
||||
[node name="Timer" type="Timer" parent="."] |
||||
autostart = true |
||||
|
||||
[node name="Label" type="Label" parent="."] |
||||
layout_mode = 0 |
||||
offset_right = 361.0 |
||||
offset_bottom = 164.0 |
||||
|
||||
[node name="Button1" type="Button" parent="."] |
||||
visible = false |
||||
layout_mode = 0 |
||||
offset_right = 50.0 |
||||
offset_bottom = 50.0 |
@ -1,45 +0,0 @@
@@ -1,45 +0,0 @@
|
||||
using Godot; |
||||
using System; |
||||
using EGFramework; |
||||
using WebDav; |
||||
using System.Threading.Tasks; |
||||
using System.Net; |
||||
|
||||
public partial class EGMDnsTest : Node, IEGFramework |
||||
{ |
||||
private string serverUrl = "http://192.168.1.170:5212/dav"; |
||||
private string username = "ZK@zk.com"; |
||||
private string password = "uQTl7lzLSMZQ1QBd7sZZMlG2Gya65XKM"; |
||||
|
||||
public override void _Ready() |
||||
{ |
||||
//TestDav(); |
||||
} |
||||
|
||||
public async void TestDav(){ |
||||
this.EGWebDav().InitClient(serverUrl,username,password); |
||||
await InitClient(); |
||||
} |
||||
public async Task<bool> InitClient() |
||||
{ |
||||
string result = EncodeCredentials(username,password); |
||||
GD.Print(result); |
||||
//ScanWebDavAndDownload(); |
||||
//await this.EGWebDav().DownloadFile("/dav/Picture/风景1.jpg",ProjectSettings.GlobalizePath("user://"),"风景1.jpg"); |
||||
//Print("download success!"); |
||||
//await this.EGWebDav().UploadFile(ProjectSettings.GlobalizePath("user://4.mp4"),"/dav/Picture","4.mp4"); |
||||
await this.EGWebDav().UploadFile(ProjectSettings.GlobalizePath("user://PPT_Test.jpg"),"/dav/Picture","PPT_Test.jpg"); |
||||
GD.Print("upload success!"); |
||||
//var result = await this.EGWebDav().GetList("/Video"); |
||||
//Print(JsonConvert.SerializeObject(result)); |
||||
return true; |
||||
} |
||||
public static string EncodeCredentials(string username, string password) |
||||
{ |
||||
string credentials = $"{username}:{password}"; |
||||
byte[] credentialsBytes = System.Text.Encoding.UTF8.GetBytes(credentials); |
||||
string encodedCredentials = Convert.ToBase64String(credentialsBytes); |
||||
return encodedCredentials; |
||||
} |
||||
|
||||
} |
@ -1,249 +0,0 @@
@@ -1,249 +0,0 @@
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using Godot; |
||||
using LiteDB; |
||||
using Renci.SshNet; |
||||
|
||||
namespace EGFramework.Examples.Test{ |
||||
public partial class EGSaveTest : Node,IEGFramework |
||||
{ |
||||
public Label Label { set; get; } |
||||
public override void _Ready() |
||||
{ |
||||
this.Label = this.GetNode<Label>("Label"); |
||||
// this.EGEnabledThread(); |
||||
// this.ExecuteAfterSecond(TestMainThreadFunc,2.0f);new PrivateKeyFile("../../../.ssh/id_ed25519") |
||||
//base._Ready(); |
||||
//TestCode(); |
||||
|
||||
// this.EGEnabledProtocolTool<EGSsh>(); |
||||
// this.EGEnabledProtocolTool<EGTCPClient>(); |
||||
// this.EGEnabledProtocolTool<EGTCPServer>(); |
||||
this.EGOnMessage<EasyMessage>(); |
||||
this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{ |
||||
}); |
||||
TestProcess(); |
||||
// //TestSsh(); |
||||
// //TestTCPSend(); |
||||
// TestTCPServer(); |
||||
// TestFTP(); |
||||
} |
||||
|
||||
public override void _ExitTree() |
||||
{ |
||||
this.EGProcess().CloseProcess("cmd.exe"); |
||||
} |
||||
|
||||
public void TestFTP(){ |
||||
EGFtpSave ftp = new EGFtpSave(); |
||||
ftp.InitSave("127.0.0.1"); |
||||
IEnumerable<IEGFileMsg> msgs = ftp.ListRemoteFilePath("/App/"); |
||||
foreach(IEGFileMsg msg in msgs){ |
||||
GD.Print(msg.FileName+" | "+msg.IsCollection+" | "+msg.Size+"kb | "+msg.LastModify); |
||||
} |
||||
} |
||||
|
||||
public void TestProcess(){ |
||||
this.EGEnabledProtocolTool<EGProcess>(); |
||||
this.EGProcess().InitProcess("cmd.exe"); |
||||
// this.EGProcess().SendStringData("cmd.exe","SaveData\\ffmpeg.exe -version\n"); |
||||
this.EGProcess().SendStringData("cmd.exe","ipconfig"); |
||||
} |
||||
|
||||
public async void TestSsh(){ |
||||
await this.EGSsh().ConnectSsh("127.0.0.1","jkpete",new PrivateKeyFile("../../../.ssh/id_ed25519")); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1",ProtocolType.SSHClient); |
||||
} |
||||
public async void TestTCPSend(){ |
||||
await this.EGTCPClient().ConnectTCP("127.0.0.1",5555); |
||||
await this.EGTCPClient().ConnectTCP("127.0.0.1",6666); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:5555",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:6666",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:6666",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:6666",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:6666",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1:5555",ProtocolType.TCPClient); |
||||
} |
||||
|
||||
public void TestTCPServer(){ |
||||
this.EGTCPServer().StartServer(5555); |
||||
this.EGTCPServer().StartServer(6666); |
||||
} |
||||
|
||||
public async void TestThread(){ |
||||
await Task.Run(()=>{ |
||||
//this.ExecuteInMainThread(TestMainThreadFunc); |
||||
this.ExecuteAfterSecond(TestMainThreadFunc,2.0f); |
||||
}); |
||||
} |
||||
|
||||
public void TestMainThreadFunc(){ |
||||
this.Label.Text = "Thread Test"; |
||||
GD.Print("Invoked!"); |
||||
} |
||||
|
||||
public void TestSqlite(){ |
||||
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>(); |
||||
this.EGSqlite().SaveData(new SqliteBackpackItem{ |
||||
ItemID = 10, |
||||
ItemCount = 1, |
||||
BackpackID = 1, |
||||
}); |
||||
GD.Print(this.EGSqlite().ExceptionMsg); |
||||
// var properties = typeof(SqliteBackpackItem).GetFields(); |
||||
// Godot.GD.Print(properties.Count() + " Readed "); |
||||
} |
||||
public void TestCode(){ |
||||
// this.EGSave().OpenUserPath(); |
||||
// GD.Print(ProjectSettings.GlobalizePath("res://SaveData/Default.json")); |
||||
// GD.Print(ProjectSettings.GlobalizePath("user://SaveData/Default.json")); |
||||
// GD.Print(Path.GetDirectoryName(ProjectSettings.GlobalizePath("res://SaveData/Default.json"))); |
||||
|
||||
// string Path2 = "Data1.json".GetGodotResPath(); |
||||
// this.EGSave().LoadObjectFile<EGJsonSave>(Path2); |
||||
|
||||
// this.EGSave().SetObject(Path2,"Customer1",new Customer() { Name = "Andy" }); |
||||
// this.EGSave().SetObject(Path2,"Customer3",new Customer() { Name = "Terry" }); |
||||
|
||||
// string CardPath1 = "Card1"; |
||||
// FileAccess fileAccess = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read); |
||||
// GD.Print(fileAccess.GetAsText()); |
||||
// FileAccess testJson = FileAccess.Open("res://TestJson.json", FileAccess.ModeFlags.Read); |
||||
// this.EGSave().ReadObject<EGJsonSave>("TestJson",testJson.GetAsText()); |
||||
// Customer customer = this.EGSave().GetObject<Customer>("TestJson","Customer3"); |
||||
// GD.Print("ReadName is "+customer.Name); |
||||
|
||||
// FileAccess testCSV = FileAccess.Open("res://SaveData/TestCSV.json", FileAccess.ModeFlags.Read); |
||||
|
||||
|
||||
// EGCsvSave csvSave = new EGCsvSave(); |
||||
// csvSave.InitSaveFile("SaveData/TestCsv.csv"); |
||||
// Customer testData = csvSave.GetData<Customer>("",1); |
||||
// GD.Print("Name = "+testData.Name +" || ID = "+testData.Id); |
||||
// CustomerByte testData = new CustomerByte(){ |
||||
// Id = 1008, |
||||
// Name = "AddDataDefault", |
||||
// IsActive = true |
||||
// }; |
||||
// csvSave.SetData("",testData,2) |
||||
|
||||
string Path1 = "SaveData/TestCsv.csv".GetGodotResPath(); |
||||
this.EGSave().LoadDataFile<EGCsvSave>(Path1); |
||||
IEnumerable<Customer> allResult = this.EGSave().FindData<Customer>(Path1,"",cus=>cus.Id==0); |
||||
foreach(Customer customer in allResult){ |
||||
GD.Print(customer.Id +"|" + customer.Name); |
||||
} |
||||
// this.EGSave().SetData(Path1,"Customer1",new Customer() { Name = "Andy" },9); |
||||
// IEnumerable<Customer> allResult = this.EGSave().GetAllData<Customer>(Path1,""); |
||||
// foreach(Customer customer in allResult){ |
||||
// GD.Print(customer.Id +"|" + customer.Name); |
||||
// } |
||||
// Customer customer1 = this.EGSave().GetData<Customer>(Path1,"",0); |
||||
// GD.Print(customer1.Id +"|" + customer1.Name); |
||||
|
||||
|
||||
// FileAccess testCsv = FileAccess.Open("res://SaveData/TestCsv.csv", FileAccess.ModeFlags.Read); |
||||
// this.EGSave().ReadData<EGCsvSave>("TestCsv",testCsv.GetAsText()); |
||||
|
||||
|
||||
// this.EGSave().LoadObjectFile<EGByteSave>("SaveData/testDat.dat"); |
||||
// // this.EGSave().SetObject("SaveData/testDat.dat","",testData); |
||||
// CustomerByte testDat = this.EGSave().GetObject<CustomerByte>("SaveData/testDat.dat",""); |
||||
// GD.Print(testDat.Id); |
||||
|
||||
// System.Linq.Expressions.Expression<Func<Customer, bool>> expr = i => i.Name == "Creature"; |
||||
// IEnumerable<Customer> linqResult = csvSave.FindData<Customer>("",expr); |
||||
// GD.Print("Find result " + linqResult.Count()); |
||||
// foreach(Customer customer in linqResult){ |
||||
// GD.Print(customer.Id); |
||||
// } |
||||
|
||||
// GD.Print(typeof(Customer)); |
||||
// Type type = typeof(Customer); |
||||
// foreach(PropertyInfo property in type.GetProperties()){ |
||||
// GD.Print(property.Name); |
||||
// CsvParamAttribute csvParam = property.GetCustomAttribute<CsvParamAttribute>(); |
||||
// if(csvParam != null){ |
||||
// GD.Print("["+csvParam._name+"]"); |
||||
// } |
||||
// } |
||||
// foreach(FieldInfo property in type.GetFields()){ |
||||
// GD.Print(property.Name); |
||||
// } |
||||
} |
||||
} |
||||
public struct SqliteBackpackItem{ |
||||
public int Id { get; set; } |
||||
public int ItemID { get; set; } |
||||
public int ItemCount { get; set; } |
||||
public int BackpackID { get; set; } |
||||
} |
||||
|
||||
public class Customer |
||||
{ |
||||
[CsvParam("ID")] |
||||
public int Id { get; set; } |
||||
[CsvParam("Name")] |
||||
public string Name { get; set; } |
||||
public string[] Phones { get; set; } |
||||
[CsvParam("是否启用")] |
||||
public bool IsActive { get; set; } |
||||
} |
||||
|
||||
public class CustomerByte : Customer, IResponse, IRequest |
||||
{ |
||||
public byte[] ToProtocolByteData() |
||||
{ |
||||
byte[] data = new byte[0]; |
||||
data = data.Concat(((uint)Id).ToBytesLittleEndian()).ToArray(); |
||||
return data; |
||||
} |
||||
|
||||
public string ToProtocolData() |
||||
{ |
||||
return ""; |
||||
} |
||||
|
||||
|
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
if(protocolBytes != null && protocolBytes.Length >= 4){ |
||||
Id = (int)protocolBytes.ToUINTLittleEndian(); |
||||
return true; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class EasyMessage : IResponse, IRequest |
||||
{ |
||||
public byte[] sendByte = null; |
||||
public string sendString = null; |
||||
public byte[] ToProtocolByteData() |
||||
{ |
||||
return sendByte; |
||||
} |
||||
|
||||
public string ToProtocolData() |
||||
{ |
||||
return sendString; |
||||
} |
||||
|
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
try |
||||
{ |
||||
GD.Print("[String]"+protocolData); |
||||
// GD.Print("[Bytes]"+protocolBytes); |
||||
return true; |
||||
} |
||||
catch (System.Exception) |
||||
{ |
||||
|
||||
throw; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,315 +0,0 @@
@@ -1,315 +0,0 @@
|
||||
using Godot; |
||||
using static Godot.GD; |
||||
using System.Collections.Generic; |
||||
using EGFramework; |
||||
using Newtonsoft.Json; |
||||
using System; |
||||
using System.Net; |
||||
|
||||
namespace EGFramework.Examples{ |
||||
public partial class EGTest : Node,IEGFramework |
||||
{ |
||||
public Label label { set; get; } |
||||
|
||||
public override void _Ready() |
||||
{ |
||||
this.EGEnabledProtocolTools(); |
||||
|
||||
this.EGMqtt().ConnectMQTTServer("192.168.1.220"); |
||||
|
||||
//this.EGUDP().UDPDevices[5555].Connect(IPAddress.Parse("224.0.0.251"),5353); |
||||
//byte[] sendData = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x5F, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5F, 0x64, 0x6E, 0x73, 0x2D, 0x73, 0x64, 0x04, 0x5F, 0x75, 0x64, 0x70, 0x05, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0x0C, 0x00, 0x01 }; |
||||
//this.EGUDP().UDPDevices[5555].Send(sendData); |
||||
// this.EGRegisterMessageEvent<PrintResponse>((e,sender,protocol)=>{ |
||||
// Print(sender); |
||||
// }); |
||||
// this.EGOnMessage<PrintResponse>(); |
||||
// this.EGReadFromFile("SaveData/MySeg2.seg2"); |
||||
//TestTCPClient(); |
||||
//TestSerialPort(); |
||||
//TestTCPServer(); |
||||
//this.EGUDP(); |
||||
//this.EGUDPListen(11000); |
||||
//this.EGSendMessage(new MessageStruct(1,"xxx"),"192.168.1.192:9002",ProtocolType.UDP); |
||||
//this.EGHttpClient(); |
||||
//this.EGHttpServer().Listen("http://+:6555/index/"); |
||||
} |
||||
public override void _Process(double delta) |
||||
{ |
||||
//Print(this.EGMqtt().MqttDevices["192.168.1.220"].IsConnected); |
||||
} |
||||
public override void _ExitTree() |
||||
{ |
||||
|
||||
} |
||||
|
||||
public void OnButton1Click(){ |
||||
this.EGMqtt().SubScribeTheme("192.168.1.220","test"); |
||||
byte[] testData = {0x3A,0x55}; |
||||
this.EGMqtt().PublishTheme("192.168.1.220","test",testData); |
||||
} |
||||
|
||||
public void RefreshMsg(bool coil){ |
||||
label.Text += coil+" "; |
||||
} |
||||
public void OnTimer(){ |
||||
//this.EGSendMessage(new MessageStruct(1,"山东博裕1"),"COM4",ProtocolType.SerialPort); |
||||
//this.EGSendMessage(new MessageStruct(1,"山东博裕1"),"192.168.1.244:6060",ProtocolType.TCPClient); |
||||
//this.EGSendMessage(new ModbusTCP_WriteMultiCoil(1,0,sendData),"192.168.1.200:3000",ProtocolType.TCPClient); |
||||
//TestSingleCoil(); |
||||
//TestMultiCoil(); |
||||
//TestSingleHoldingRegister(); |
||||
//TestMultiHoldingRegister(); |
||||
} |
||||
public void TestModbus(){ |
||||
label = this.GetNode<Label>("Label"); |
||||
label.Text = "[Modbus]"; |
||||
this.EGRegisterMessageEvent<MessageResponse>((e,sender,type)=>{ |
||||
Print("[Got Response]"+"[sender = "+sender+"]"+"["+type+"]"+ e.MessageId+"||"+e.Author); |
||||
}); |
||||
this.EGOnMessage<MessageResponse>(); |
||||
this.EGRegisterMessageEvent<ModbusTCP_Response>((e,sender,type)=>{ |
||||
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadCoil){ |
||||
int registerId = 0; |
||||
foreach(bool coil in e.Coil){ |
||||
Print(registerId + "Status:" + coil); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadDiscreteInput){ |
||||
int registerId = 0; |
||||
foreach(bool discreteInput in e.DiscreteInput){ |
||||
Print(registerId + "Status:" + discreteInput); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadHoldingRegisters){ |
||||
int registerId = 0; |
||||
foreach(ushort holdingRegister in e.HoldingRegister){ |
||||
Print(registerId + "Status:" + holdingRegister); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.TCPClient && e.FunctionType == ModbusFunctionType.ReadInputRegisters){ |
||||
int registerId = 0; |
||||
foreach(ushort inputRegister in e.InputRegister){ |
||||
Print(registerId + "Status:" + inputRegister); |
||||
label.Text+=registerId + "Status:" + inputRegister; |
||||
registerId++; |
||||
} |
||||
} |
||||
//this.EGOffMessage<ModbusTCP_Response>(); |
||||
}); |
||||
|
||||
this.EGRegisterMessageEvent<ModbusRTU_Response>((e,sender,type)=>{ |
||||
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadCoil){ |
||||
int registerId = 0; |
||||
foreach(bool coil in e.Coil){ |
||||
Print(registerId + "Status:" + coil); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadDiscreteInput){ |
||||
int registerId = 0; |
||||
foreach(bool discreteInput in e.DiscreteInput){ |
||||
Print(registerId + "Status:" + discreteInput); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadHoldingRegisters){ |
||||
int registerId = 0; |
||||
foreach(ushort holdingRegister in e.HoldingRegister){ |
||||
Print(registerId + "Status:" + holdingRegister); |
||||
registerId++; |
||||
} |
||||
} |
||||
if(type == ProtocolType.SerialPort && e.FunctionType == ModbusFunctionType.ReadInputRegisters){ |
||||
int registerId = 0; |
||||
foreach(ushort inputRegister in e.InputRegister){ |
||||
Print(registerId + "Status:" + inputRegister); |
||||
label.Text+=registerId + "Status:" + inputRegister; |
||||
registerId++; |
||||
} |
||||
} |
||||
//this.EGOffMessage<ModbusRTU_Response>(); |
||||
}); |
||||
|
||||
} |
||||
|
||||
public void TestTCPServer(){ |
||||
this.EGTCPServer().OnClientConnect.Register(e=>{ |
||||
Print(e +" is connected"); |
||||
this.EGSendMessage(new MessageStruct(1,"Hello"),e,ProtocolType.TCPServer); |
||||
}); |
||||
this.EGTCPServer().OnClientDisconnect.Register(e=>{ |
||||
Print(e +" is disconnect"); |
||||
}); |
||||
this.EGTCPServerListen(9999); |
||||
} |
||||
|
||||
public void TestSqlite(){ |
||||
this.EGSqlite().SaveData(new TestBoxMessage()); |
||||
List<TestBoxMessage> result = this.EGSqlite().GetDataSet<TestBoxMessage>(); |
||||
if(result == null){ |
||||
PrintErr(this.EGSqlite().ExceptionMsg); |
||||
} |
||||
Print("Result = " + result[0].TestDouble + result[0].TestFloat); |
||||
} |
||||
public void TestSerialPort(){ |
||||
this.EGSerialPort().SetBaudRate(9600); |
||||
this.EGSendMessage(new ModbusRTU_ReadInputRegisters(1,0,2),"COM4",ProtocolType.SerialPort); |
||||
this.EGSendMessage(new ModbusRTU_ReadCoils(1,0,8),"COM4",ProtocolType.SerialPort); |
||||
this.EGOnMessage<ModbusRTU_Response>(); |
||||
} |
||||
|
||||
public void TestTCPClient(){ |
||||
this.EGTCPClient(); |
||||
this.EGSendMessage(new ModbusTCP_ReadDiscreteInput(1,0,8),"192.168.1.196:6000",ProtocolType.TCPClient); |
||||
this.EGSendMessage(new ModbusTCP_ReadInputRegisters(1,0,2),"192.168.1.196:6000",ProtocolType.TCPClient); |
||||
this.EGOnMessage<ModbusTCP_Response>(); |
||||
} |
||||
|
||||
private bool IsOpen = false; |
||||
public void TestSingleCoil(){ |
||||
if(IsOpen){ |
||||
//this.EGSendMessage(new ModbusRTU_WriteSingleCoil(1,0,false),"COM4",ProtocolType.SerialPort); |
||||
this.EGSendMessage(new ModbusTCP_WriteSingleCoil(1,0,false),"192.168.1.196:6000",ProtocolType.TCPClient); |
||||
IsOpen = false; |
||||
}else{ |
||||
//this.EGSendMessage(new ModbusRTU_WriteSingleCoil(1,0,true),"COM4",ProtocolType.SerialPort); |
||||
this.EGSendMessage(new ModbusTCP_WriteSingleCoil(1,0,true),"192.168.1.196:6000",ProtocolType.TCPClient); |
||||
IsOpen = true; |
||||
} |
||||
} |
||||
public void TestMultiCoil(){ |
||||
byte[] OpenCode = {0xFF}; |
||||
byte[] CloseCode = {0x00}; |
||||
if(IsOpen){ |
||||
this.EGSendMessage(new ModbusRTU_WriteMultiCoil(1,0,CloseCode.ToBoolArray()),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = false; |
||||
}else{ |
||||
this.EGSendMessage(new ModbusRTU_WriteMultiCoil(1,0,OpenCode.ToBoolArray()),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = true; |
||||
} |
||||
} |
||||
public void TestSingleHoldingRegister(){ |
||||
if(IsOpen){ |
||||
this.EGSendMessage(new ModbusRTU_WriteSingleHoldingRegister(1,0,0x00),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = false; |
||||
}else{ |
||||
this.EGSendMessage(new ModbusRTU_WriteSingleHoldingRegister(1,0,0x01),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = true; |
||||
} |
||||
} |
||||
public void TestMultiHoldingRegister(){ |
||||
ushort[] OpenCode = {1,1,1,1,1,1,1,1}; |
||||
ushort[] CloseCode = {0,0,0,0,0,0,0,0}; |
||||
if(IsOpen){ |
||||
this.EGSendMessage(new ModbusRTU_WriteMultiHoldingRegister(1,0,CloseCode),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = false; |
||||
}else{ |
||||
this.EGSendMessage(new ModbusRTU_WriteMultiHoldingRegister(1,0,OpenCode),"COM4",ProtocolType.SerialPort); |
||||
IsOpen = true; |
||||
} |
||||
} |
||||
|
||||
} |
||||
public class TestBoxMessage { |
||||
public int Code = 0; |
||||
public float TestFloat = 0.1f; |
||||
public double TestDouble; |
||||
public bool IsHaveMessage; |
||||
public string MessageInfo; |
||||
public MessageType MsgType; |
||||
public MessageStruct MsgStruct; |
||||
public MessagePair MsgPair; |
||||
public TestBoxMessage(){ |
||||
this.Code = 1; |
||||
this.TestFloat = 1.2f; |
||||
this.TestDouble = 2.52; |
||||
this.IsHaveMessage = true; |
||||
this.MessageInfo = "DefaultInfo"; |
||||
MsgType = MessageType.TypeInt; |
||||
MsgPair = new MessagePair(); |
||||
MsgStruct = new MessageStruct(5,"Ad"); |
||||
} |
||||
public string ToProtocolData() |
||||
{ |
||||
return JsonConvert.SerializeObject(this); |
||||
} |
||||
} |
||||
public class MessagePair{ |
||||
public int MessageId; |
||||
public string Author; |
||||
public string MessageInfo; |
||||
public int TimeStamp; |
||||
public MessagePair(){ |
||||
this.MessageId = 10001; |
||||
this.Author = "Admin"; |
||||
this.MessageInfo = "Hello every one!"; |
||||
this.TimeStamp = 1690188342; |
||||
} |
||||
} |
||||
public struct MessageStruct : IRequest,IEGFramework{ |
||||
public string FunctionCode; |
||||
public int MessageId; |
||||
public string Author; |
||||
public MessageStruct(int messageId,string author){ |
||||
FunctionCode = "Message"; |
||||
MessageId = messageId; |
||||
Author = author; |
||||
} |
||||
public byte[] ToProtocolByteData() |
||||
{ |
||||
return JsonConvert.SerializeObject(this).ToBytesByEncoding("GBK"); |
||||
} |
||||
public string ToProtocolData() |
||||
{ |
||||
return ""; |
||||
//return JsonConvert.SerializeObject(this); |
||||
} |
||||
} |
||||
public struct MessageResponse : IResponse |
||||
{ |
||||
public string FunctionCode { set; get; } |
||||
public int MessageId; |
||||
public string Author; |
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
try |
||||
{ |
||||
//GD.Print(protocolData); |
||||
MessageResponse res = JsonConvert.DeserializeObject<MessageResponse>(protocolData); |
||||
if(res.FunctionCode == "Message"){ |
||||
this.FunctionCode = res.FunctionCode; |
||||
this.MessageId = res.MessageId; |
||||
this.Author = res.Author; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
catch (Exception) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public struct PrintResponse : IResponse |
||||
{ |
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
//Print("Received String is " + protocolData); |
||||
Print("Received bytes is " + protocolBytes.ToStringByHex()); |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
|
||||
public enum MessageType{ |
||||
TypeString = 1, |
||||
TypeInt = 2, |
||||
TypeObject = 3, |
||||
TypeArray = 4 |
||||
} |
||||
} |
Loading…
Reference in new issue