Compare commits
	
		
			641 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 4a85e31a4f | ||
|   | 302c270ad5 | ||
|   | 3c1517d0f3 | ||
|   | f9fb222044 | ||
|   | e8edc02ba3 | ||
|   | 95a44e3053 | ||
|   | 74a9fe9a87 | ||
|   | 4d03f9ea1a | ||
|   | 67c96ca991 | ||
|   | 88fb793c68 | ||
|   | d6d02d8cc5 | ||
|   | c5a3f8e2e3 | ||
|   | 27e8653a1a | ||
|   | 863beda82c | ||
|   | bac84c3ecd | ||
|   | 2fca2ad9f8 | ||
|   | dd75286fe0 | ||
|   | 7f91792cf1 | ||
|   | 0e0ccad311 | ||
|   | 0691f72e67 | ||
|   | 7e38a51720 | ||
|   | 34ca8243a3 | ||
|   | 112fea7632 | ||
|   | 378763e4ee | ||
|   | 517bd0394d | ||
|   | 70adb97fb5 | ||
|   | 623d44cabe | ||
|   | 0d479ca00b | ||
|   | 8bc49ef437 | ||
|   | f83fcec786 | ||
|   | 93690ce40d | ||
|   | f82c5f2f27 | ||
|   | a83c1c3899 | ||
|   | 91d6aed109 | ||
|   | db8f8fe51d | ||
|   | 4596004b17 | ||
|   | d5540906cb | ||
|   | 90796a979d | ||
|   | 2190a87772 | ||
|   | c5953b83f8 | ||
|   | 24bc60abf0 | ||
|   | 31eee6b009 | ||
|   | c5da565a8f | ||
|   | 947cd712e1 | ||
|   | edc208f96b | ||
|   | 1fb0296ee7 | ||
|   | 6488d3df87 | ||
|   | 56189d78e0 | ||
|   | bff18127b8 | ||
|   | 363206e0ba | ||
|   | fd3e378501 | ||
|   | 4ba2fe4c9d | ||
|   | 2c499626ad | ||
|   | 2b581a03c3 | ||
|   | 450c15210a | ||
|   | 65fed8cc93 | ||
|   | 4b64771ea2 | ||
|   | f39977a6ff | ||
|   | 933b535caa | ||
|   | 8abc5d2f20 | ||
|   | d8783cd994 | ||
|   | d5d087feb5 | ||
|   | 6ba3399df7 | ||
|   | 65124b3aa8 | ||
|   | 98597f4726 | ||
|   | e7981f0d8e | ||
|   | cf654427c3 | ||
|   | ff2f628282 | ||
|   | ae818ca265 | ||
|   | 0f2aed458e | ||
|   | d486c44ff6 | ||
|   | ca7b9980bf | ||
|   | 3c71e6a8e3 | ||
|   | 542442864c | ||
|   | 5edb64fa85 | ||
|   | 8dc1c898a3 | ||
|   | 1ed35726b0 | ||
|   | 27fae9ebaa | ||
|   | b103f25c94 | ||
|   | abff450274 | ||
|   | c260736a11 | ||
|   | 166ac2307a | ||
|   | b21a4e1a4d | ||
|   | f7dc943fa3 | ||
|   | bfbd2693ec | ||
|   | 819e71c993 | ||
|   | 9fd0b489a2 | ||
|   | f5fe9f8dae | ||
|   | f9ffc18145 | ||
|   | 08db5b983a | ||
|   | 5b3b4c8c50 | ||
|   | 73f914ffc4 | ||
|   | d6bdd73ed6 | ||
|   | 7370ee7349 | ||
|   | 4574596bac | ||
|   | 4d16855e36 | ||
|   | 13a0d4d282 | ||
|   | b9cd06b829 | ||
|   | 5b460e8fa2 | ||
|   | 41087edf17 | ||
|   | 2afcc38e38 | ||
|   | e59ccce25f | ||
|   | d7425890e8 | ||
|   | a989a837fb | ||
|   | db1221da50 | ||
|   | cf794569ed | ||
|   | 51e5bbab0d | ||
|   | 2c197ed2b2 | ||
|   | d8fc6665b3 | ||
|   | c671a79822 | ||
|   | 9d93ce4c41 | ||
|   | a6d99fe227 | ||
|   | 923b8bca31 | ||
|   | e2c30d1c88 | ||
|   | b6d9f2a04e | ||
|   | 57306ea664 | ||
|   | cd7f3fd02f | ||
|   | 0482e077a8 | ||
|   | 5f986a45ca | ||
|   | ca7b49c0d5 | ||
|   | 52dd555e6c | ||
|   | 579b1a59f9 | ||
|   | 5299c5c4be | ||
|   | f7756bccef | ||
|   | a6b874d160 | ||
|   | 3e5fb3ddcf | ||
|   | 5e6bcb12d3 | ||
|   | 14303f1429 | ||
|   | 96711ba022 | ||
|   | cbfc0fdbdc | ||
|   | 6e81886c0e | ||
|   | 2d976bc132 | ||
|   | 57f6a476af | ||
|   | 8491ed296e | ||
|   | cd1288afdc | ||
|   | ec6c830cb0 | ||
|   | 2f86ccc4bf | ||
|   | 8ca445aec0 | ||
|   | 1e1f27c8a5 | ||
|   | 2b84bde367 | ||
|   | b52e58551d | ||
|   | 9aceed00bf | ||
|   | 58814f7f74 | ||
|   | 6a70ef9f31 | ||
|   | 82cc4ca500 | ||
|   | 4567fa04ed | ||
|   | 8b98b5d818 | ||
|   | 176d0351af | ||
|   | d63dc3384b | ||
|   | 1ccd704e30 | ||
|   | f5d23dbe79 | ||
|   | 75bfe53ac3 | ||
|   | 3308f916dd | ||
|   | e7140279ca | ||
|   | 1034719f5e | ||
|   | 2c00043a7f | ||
|   | 65c695d9ce | ||
|   | 57253fe46a | ||
|   | 4e5c443440 | ||
|   | 0b3b73d8ec | ||
|   | 921eabc134 | ||
|   | 0faa428751 | ||
|   | f71a2fdd63 | ||
|   | 4eb9ed8aba | ||
|   | d7b549abb8 | ||
|   | 95d723c578 | ||
|   | 2fcd853e86 | ||
|   | 07eef7c812 | ||
|   | b01e0757fa | ||
|   | 32844a20c6 | ||
|   | 5b6532c601 | ||
|   | 2c5b4b4027 | ||
|   | 72d7ecf195 | ||
|   | 2cfa6b4306 | ||
|   | 6f6ffde0ab | ||
|   | 1694739a16 | ||
|   | 95d1e8bfca | ||
|   | 60dec08e3c | ||
|   | a99d71be93 | ||
|   | f1331b6a0c | ||
|   | 10d66b642b | ||
|   | cd2310e4a8 | ||
|   | 1b399cf6b0 | ||
|   | 877445bc0a | ||
|   | 9a5b345bde | ||
|   | fc9e8ea7b3 | ||
|   | 32be6fcfc1 | ||
|   | 49847236c2 | ||
|   | d8424443e6 | ||
|   | f3b571ec3f | ||
|   | 99318bb5d7 | ||
|   | 1aa154c9aa | ||
|   | c65d8a445b | ||
|   | 80f4f85570 | ||
|   | 5beee43a6b | ||
|   | 8d6ae203a0 | ||
|   | 4353479a5c | ||
|   | 34d7687f9e | ||
|   | b1dc3cf4af | ||
|   | 6a58b95933 | ||
|   | d3badfd02b | ||
|   | 0098be057b | ||
|   | 6f972aa515 | ||
|   | 7407ba6313 | ||
|   | 1c79de207b | ||
|   | 257c79db92 | ||
|   | 9d1934a308 | ||
|   | d70f959902 | ||
|   | e4d810222f | ||
|   | bc1af4ae07 | ||
|   | 6e688ef43f | ||
|   | f0fe1b23dc | ||
|   | aaf2006401 | ||
|   | b821e26935 | ||
|   | 7ae4287157 | ||
|   | c6fcc38a65 | ||
|   | ab2d5c8853 | ||
|   | 5e557ff0bc | ||
|   | 918ca449a1 | ||
|   | 8e73368008 | ||
|   | f3c1faf672 | ||
|   | d6df04dd6a | ||
|   | b1b9e51ab6 | ||
|   | e49d4770ac | ||
|   | 8fa1075511 | ||
|   | 9a70169b94 | ||
|   | fefb928237 | ||
|   | ad7e700d0d | ||
|   | 1699c69147 | ||
|   | 1695f7cece | ||
|   | 052c27f907 | ||
|   | dc46c32b30 | ||
|   | fa63349bb2 | ||
|   | ffe26448a6 | ||
|   | 4af51e8a84 | ||
|   | 1e453cf5a5 | ||
|   | 591282b87d | ||
|   | e87528d520 | ||
|   | d79eb0411d | ||
|   | ac1e0a4cf7 | ||
|   | 9525eab130 | ||
|   | 89b317496c | ||
|   | 13be91e78b | ||
|   | f68c1437f3 | ||
|   | 4c64c969bb | ||
|   | b4bf3b5138 | ||
|   | 083bc4b400 | ||
|   | e8683c5bcc | ||
|   | 80e0d1de91 | ||
|   | dbe841037e | ||
|   | bdd537c33c | ||
|   | c0c3846094 | ||
|   | 9e8710e7d2 | ||
|   | 475553fdf6 | ||
|   | 9d570f5b45 | ||
|   | af7fafd34f | ||
|   | d43130f4fc | ||
|   | 7500194620 | ||
|   | eb27c29144 | ||
|   | 43260b3e24 | ||
|   | f80713f0aa | ||
|   | 0c4bdc7ad1 | ||
|   | 811cff7bd0 | ||
|   | 30269aa75c | ||
|   | e345ef7083 | ||
|   | f559c9b8f7 | ||
|   | f4af0916b2 | ||
|   | f15f14f28d | ||
|   | 834f44f58d | ||
|   | b36f45dcf4 | ||
|   | 11ba21c9a8 | ||
|   | b045557ce1 | ||
|   | 0dd251a3f6 | ||
|   | 793acb1725 | ||
|   | 921243e8bd | ||
|   | bd9d7a90d9 | ||
|   | cc444a4cea | ||
|   | 38ca1fa168 | ||
|   | 7a552b87ec | ||
|   | 36923d3190 | ||
|   | a9d3017123 | ||
|   | 313acd4976 | ||
|   | a4c91bb268 | ||
|   | f9b566984b | ||
|   | 8dd261854d | ||
|   | 7351e62d87 | ||
|   | 0593ae720b | ||
|   | a0a7b08e08 | ||
|   | 9a3bc6b8b3 | ||
|   | 5acae17f71 | ||
|   | f1e5b76ef2 | ||
|   | 53c628fde9 | ||
|   | baca0a70c0 | ||
|   | 3e8d0af404 | ||
|   | cf9a91d9d5 | ||
|   | 02b9e282c6 | ||
|   | 9ce87f235f | ||
|   | e329bea1b2 | ||
|   | 8086e7b54d | ||
|   | f7a875606e | ||
|   | 196eaf85f4 | ||
|   | 876a55668e | ||
|   | 05bd21bdd5 | ||
|   | fb51a08cc6 | ||
|   | dd83d7f4d3 | ||
|   | 842a56f7ce | ||
|   | 9246a6e797 | ||
|   | 8ad693f717 | ||
|   | f4c2ee7cc4 | ||
|   | 6043441faa | ||
|   | 4a065c3710 | ||
|   | 0ef800bdd7 | ||
|   | 56eaa1910d | ||
|   | 201788e286 | ||
|   | 506e0f144f | ||
|   | 72f68bfdd9 | ||
|   | 2f9869b11d | ||
|   | 8ffcf6498c | ||
|   | d224ae1923 | ||
|   | fed2063a19 | ||
|   | db2810cdd7 | ||
|   | 4f1a6781ef | ||
|   | beffa5d5a4 | ||
|   | 7a20f1de07 | ||
|   | cd25cf726b | ||
|   | d6b1bc3842 | ||
|   | a4385fb9bb | ||
|   | 7045f2b8ea | ||
|   | 07ca1a4de8 | ||
|   | 24f289e692 | ||
|   | 01bcdaae2d | ||
|   | 55890008d1 | ||
|   | 5ab9b01879 | ||
|   | e4abb333b3 | ||
|   | 09f476c745 | ||
|   | 8806e68dce | ||
|   | 2ef1e25cd8 | ||
|   | 10e7f202aa | ||
|   | ccd7000c09 | ||
|   | 8ee7b798cf | ||
|   | 7733cf5bf0 | ||
|   | a05ce86dd7 | ||
|   | 91f51c32e8 | ||
|   | f910202bba | ||
|   | 6d77194a8f | ||
|   | 9deb89c15f | ||
|   | 4b62a092b4 | ||
|   | 81c8f626f9 | ||
|   | 3e846c42fb | ||
|   | 63ad7fd766 | ||
|   | 9ff1e9aa34 | ||
|   | 8d162b6f3d | ||
|   | 9844d10bef | ||
|   | b908fa8489 | ||
|   | 15a10643a7 | ||
|   | 299617aca1 | ||
|   | 45647d697a | ||
|   | 48f5105d38 | ||
|   | fe1c741d68 | ||
|   | fa42cc1f00 | ||
|   | 42cf5e7a81 | ||
|   | 47905e1aa1 | ||
|   | 9a8e907df3 | ||
|   | 106fe85582 | ||
|   | 4b3571bd57 | ||
|   | 96b537401a | ||
|   | 721c9eb057 | ||
|   | 51701bf6d6 | ||
|   | dbde68bd56 | ||
|   | ad2c9f585a | ||
|   | 562093c468 | ||
|   | b0295584a3 | ||
|   | 208c54de98 | ||
|   | 63e2d941a1 | ||
|   | 3956838e9c | ||
|   | abeee58bb0 | ||
|   | d5b1b49722 | ||
|   | 564ed03ff8 | ||
|   | 70db4c76b4 | ||
|   | d059f7975b | ||
|   | 4e74e6dc2d | ||
|   | b6deb96658 | ||
|   | 3839e966be | ||
|   | 3dd035849c | ||
|   | 3d6532b5d6 | ||
|   | bf7c175ee7 | ||
|   | f84af35ed6 | ||
|   | 99063b3eb1 | ||
|   | 3bec18f28d | ||
|   | 15de7a7894 | ||
|   | e20e04e677 | ||
|   | 5fc6ae2835 | ||
|   | 7d281b8c96 | ||
|   | 4880b801a7 | ||
|   | 74e354456a | ||
|   | af2e03aa36 | ||
|   | d8fa660ab6 | ||
|   | 1a62d48297 | ||
|   | 7ba01be13d | ||
|   | 1a83d64db7 | ||
|   | 5b53014c40 | ||
|   | 83685340af | ||
|   | 31e0cc4dec | ||
|   | 56b87fc1f5 | ||
|   | 6b956a2dd7 | ||
|   | 1937623d7d | ||
|   | 3b60b10945 | ||
|   | 7173acd350 | ||
|   | 6310d87338 | ||
|   | 49a1ed7c18 | ||
|   | d426e280d9 | ||
|   | 6154fb29f1 | ||
|   | 97d48ef9d6 | ||
|   | 88992625c4 | ||
|   | bc6eb44218 | ||
|   | cf9ccd799d | ||
|   | ffa0e4e771 | ||
|   | 60fa9c196c | ||
|   | df860d22fb | ||
|   | cb46ff326c | ||
|   | f277a853ef | ||
|   | 9ae34f67c3 | ||
|   | c9223218cc | ||
|   | c0dd645aba | ||
|   | 2e948eb5b6 | ||
|   | c3276889cf | ||
|   | a76ca8282d | ||
|   | 8ce6b8362f | ||
|   | 842fb12f05 | ||
|   | d63e1511af | ||
|   | 278783b8e0 | ||
|   | d24e3c922d | ||
|   | 1d02cd2283 | ||
|   | 8edeb82a87 | ||
|   | 146e9279de | ||
|   | 47105f50a9 | ||
|   | 16c9c80f37 | ||
|   | 8e7e4bc95a | ||
|   | 0aa3d2f930 | ||
|   | ce77755a1e | ||
|   | 0f31f20c87 | ||
|   | ee6da2aaa5 | ||
|   | a35f087cd9 | ||
|   | 6e029b44dd | ||
|   | 973c0cff34 | ||
|   | 2027eea6ac | ||
|   | 2f43692f33 | ||
|   | 6d24992f88 | ||
|   | b4388a58d6 | ||
|   | 158aa05fac | ||
|   | f2731bf55e | ||
|   | 7304e99fce | ||
|   | 02700b83eb | ||
|   | 676b25acf9 | ||
|   | 556359ea2d | ||
|   | b72923e0f5 | ||
|   | 115ac9f75e | ||
|   | 32e36f6708 | ||
|   | d949b7a4f9 | ||
|   | eae1171ff5 | ||
|   | 76a1b75a51 | ||
|   | 8882c0daea | ||
|   | 07ebc16d59 | ||
|   | 0ceb109964 | ||
|   | 118b0d0038 | ||
|   | 5e87067792 | ||
|   | c946a252e8 | ||
|   | f9ad2ba1dd | ||
|   | 0d0ecd33bd | ||
|   | e4b98fd05b | ||
|   | 95a5933303 | ||
|   | da3b55fa64 | ||
|   | fbbabfb90e | ||
|   | f13da6830d | ||
|   | f560a8e2f8 | ||
|   | 56f1139c2f | ||
|   | 773bdfc1e2 | ||
|   | f449666628 | ||
|   | 3f282de0ab | ||
|   | 440dd8d22f | ||
|   | dcff9de2f7 | ||
|   | a192866543 | ||
|   | 10081416de | ||
|   | e2bed618f9 | ||
|   | 03ab1f3823 | ||
|   | ac8aeb63d9 | ||
|   | 2e16d822fa | ||
|   | e407d873fa | ||
|   | fd712a1dbe | ||
|   | e9028b40ce | ||
|   | c9da3dee7c | ||
|   | c8c224e202 | ||
|   | f34559daaf | ||
|   | 9fefbf4c27 | ||
|   | 1af9fd73ea | ||
|   | 75ef394eff | ||
|   | ec6cc2c63e | ||
|   | 06bc2e192b | ||
|   | 78701ec7c1 | ||
|   | c925fab7e4 | ||
|   | 42fd72c164 | ||
|   | 7fd160e1a2 | ||
|   | 97a0d940eb | ||
|   | efaa099d81 | ||
|   | 47864a804b | ||
|   | 91136c0e43 | ||
|   | 28c3b1bd61 | ||
|   | 551352bc40 | ||
|   | e73c24c925 | ||
|   | 7ec4c286cc | ||
|   | 6705e2ec4b | ||
|   | 6f0373063b | ||
|   | f64eef60b5 | ||
|   | 89546bf86b | ||
|   | 793678feca | ||
|   | 923cc3019a | ||
|   | 10eb98a5f6 | ||
|   | bd9e89d8dd | ||
|   | 1926b4ce73 | ||
|   | 4ef3062d74 | ||
|   | abb6e0f60f | ||
|   | f204d8d84e | ||
|   | fa301656f1 | ||
|   | 7e1221028f | ||
|   | 41308cb2dd | ||
|   | 130600521c | ||
|   | cd57548a48 | ||
|   | efacc99f76 | ||
|   | f0d236e172 | ||
|   | a8118bd8c6 | ||
|   | 0e58f2ef53 | ||
|   | f4b22b3a0c | ||
|   | df5bd281c7 | ||
|   | a3f23837ce | ||
|   | 612d989b97 | ||
|   | 42c01ee9a2 | ||
|   | 14074db591 | ||
|   | 43dfdd7942 | ||
|   | f397b97ccf | ||
|   | 95f8716144 | ||
|   | 17ba472b2e | ||
|   | 42d82571ab | ||
|   | 9119a28141 | ||
|   | a32263d838 | ||
|   | 208ae2bb88 | ||
|   | 4d85462a85 | ||
|   | f601aa9ca0 | ||
|   | 8aee3ad455 | ||
|   | 6a2a1e9561 | ||
|   | 5f8786c9dc | ||
|   | 73f1d3eead | ||
|   | 2bf21bb3c3 | ||
|   | f80f0dbb11 | ||
|   | 37518c70c4 | ||
|   | e5951b5bef | ||
|   | ab320bd90b | ||
|   | 7bd36b5371 | ||
|   | b882b0f2bc | ||
|   | 38d7ae73cc | ||
|   | 4527c6ee5d | ||
|   | 85829e70c1 | ||
|   | 256c08d82a | ||
|   | c2ce03c047 | ||
|   | f2af19e198 | ||
|   | 930b7c092d | ||
|   | 00757c69c6 | ||
|   | 55f267d0fc | ||
|   | 6b96aff6e8 | ||
|   | 32b773a8fa | ||
|   | 03089adad6 | ||
|   | 4a1fe746ab | ||
|   | aa52c05d2c | ||
|   | 26407a43e7 | ||
|   | a02934bf19 | ||
|   | 09c65fba09 | ||
|   | 4305c727d0 | ||
|   | 188339897f | ||
|   | 4ecff9a707 | ||
|   | 355aed49c6 | ||
|   | 4717b6b0f0 | ||
|   | 45ebe9048d | ||
|   | b2170c49a3 | ||
|   | dc2f4d6115 | ||
|   | 1eb132440f | ||
|   | a464bbc37a | ||
|   | ed995697c2 | ||
|   | 163cd84c7b | ||
|   | 293d7cc292 | ||
|   | 5de1b4e74c | ||
|   | 7b474975da | ||
|   | beab51516b | ||
|   | fe8685a50c | ||
|   | f9af5d0885 | ||
|   | e8136a9720 | ||
|   | 531e5d4556 | ||
|   | e66255963a | ||
|   | 246aac8ee4 | ||
|   | 23cfeff685 | ||
|   | a5e7e0d126 | ||
|   | 5bebc30ba0 | ||
|   | 0e7057f5b9 | ||
|   | 7c6c365ba4 | ||
|   | 424c9bb0c5 | ||
|   | 9d0f26594c | ||
|   | 99c17de079 | ||
|   | b1e3dd0af6 | ||
|   | 261cb89530 | ||
|   | ff6773ba37 | ||
|   | bdfbbfcbbd | ||
|   | 0c4cd56758 | ||
|   | 4a36658321 | ||
|   | 7aae938685 | ||
|   | 3723401e7a | ||
|   | 70631366a9 | ||
|   | 0e40bbda3e | ||
|   | e9aa475398 | ||
|   | 8d2a811184 | ||
|   | dd7f5b6700 | ||
|   | a4f6277737 | ||
|   | c2bfaacbb7 | ||
|   | a17cbfa2d4 | ||
|   | fb9a101555 | ||
|   | e319cf0200 | ||
|   | 0a8395ef6a | ||
|   | 38df5e01be | ||
|   | ebd891a868 | ||
|   | 4ab2395cbe | ||
|   | 5f1f989fc9 | ||
|   | 44b709eee3 | ||
|   | d0d7726597 | ||
|   | 054c342aeb | ||
|   | c79c33baf7 | ||
|   | 23b00e35b2 | ||
|   | fe51079266 | ||
|   | 0791b0bbee | ||
|   | dbf04c8eeb | ||
|   | 6204256df8 | ||
|   | 93cc8c2327 | ||
|   | 68a2e5bbbc | ||
|   | 72792153f2 | ||
|   | 88b6ef1897 | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -363,6 +363,4 @@ MigrationBackup/ | ||||
| FodyWeavers.xsd | ||||
|  | ||||
|  | ||||
| /framework/*pro* | ||||
| /framework/*Pro* | ||||
|  | ||||
|   | ||||
							
								
								
									
										103
									
								
								framework/.editorconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								framework/.editorconfig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | ||||
| [*.cs] | ||||
|  | ||||
| # CA1848: 使用 LoggerMessage 委托 | ||||
| dotnet_diagnostic.CA1848.severity = none | ||||
|  | ||||
| # CA2254: 模板应为静态表达式 | ||||
| dotnet_diagnostic.CA2254.severity = suggestion | ||||
|  | ||||
| [*.cs] | ||||
| #### 命名样式 #### | ||||
|  | ||||
| # 命名规则 | ||||
|  | ||||
| dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion | ||||
| dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface | ||||
| dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i | ||||
|  | ||||
| dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion | ||||
| dotnet_naming_rule.types_should_be_pascal_case.symbols = types | ||||
| dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case | ||||
|  | ||||
| dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion | ||||
| dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members | ||||
| dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case | ||||
|  | ||||
| # 符号规范 | ||||
|  | ||||
| dotnet_naming_symbols.interface.applicable_kinds = interface | ||||
| dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||||
| dotnet_naming_symbols.interface.required_modifiers =  | ||||
|  | ||||
| dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum | ||||
| dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||||
| dotnet_naming_symbols.types.required_modifiers =  | ||||
|  | ||||
| dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method | ||||
| dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||||
| dotnet_naming_symbols.non_field_members.required_modifiers =  | ||||
|  | ||||
| # 命名样式 | ||||
|  | ||||
| dotnet_naming_style.begins_with_i.required_prefix = I | ||||
| dotnet_naming_style.begins_with_i.required_suffix =  | ||||
| dotnet_naming_style.begins_with_i.word_separator =  | ||||
| dotnet_naming_style.begins_with_i.capitalization = pascal_case | ||||
|  | ||||
| dotnet_naming_style.pascal_case.required_prefix =  | ||||
| dotnet_naming_style.pascal_case.required_suffix =  | ||||
| dotnet_naming_style.pascal_case.word_separator =  | ||||
| dotnet_naming_style.pascal_case.capitalization = pascal_case | ||||
|  | ||||
| dotnet_naming_style.pascal_case.required_prefix =  | ||||
| dotnet_naming_style.pascal_case.required_suffix =  | ||||
| dotnet_naming_style.pascal_case.word_separator =  | ||||
| dotnet_naming_style.pascal_case.capitalization = pascal_case | ||||
|  | ||||
| [*.vb] | ||||
| #### 命名样式 #### | ||||
|  | ||||
| # 命名规则 | ||||
|  | ||||
| dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion | ||||
| dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface | ||||
| dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始 | ||||
|  | ||||
| dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion | ||||
| dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型 | ||||
| dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 | ||||
|  | ||||
| dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion | ||||
| dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员 | ||||
| dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 | ||||
|  | ||||
| # 符号规范 | ||||
|  | ||||
| dotnet_naming_symbols.interface.applicable_kinds = interface | ||||
| dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected | ||||
| dotnet_naming_symbols.interface.required_modifiers =  | ||||
|  | ||||
| dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum | ||||
| dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected | ||||
| dotnet_naming_symbols.类型.required_modifiers =  | ||||
|  | ||||
| dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method | ||||
| dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected | ||||
| dotnet_naming_symbols.非字段成员.required_modifiers =  | ||||
|  | ||||
| # 命名样式 | ||||
|  | ||||
| dotnet_naming_style.以_i_开始.required_prefix = I | ||||
| dotnet_naming_style.以_i_开始.required_suffix =  | ||||
| dotnet_naming_style.以_i_开始.word_separator =  | ||||
| dotnet_naming_style.以_i_开始.capitalization = pascal_case | ||||
|  | ||||
| dotnet_naming_style.帕斯卡拼写法.required_prefix =  | ||||
| dotnet_naming_style.帕斯卡拼写法.required_suffix =  | ||||
| dotnet_naming_style.帕斯卡拼写法.word_separator =  | ||||
| dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case | ||||
|  | ||||
| dotnet_naming_style.帕斯卡拼写法.required_prefix =  | ||||
| dotnet_naming_style.帕斯卡拼写法.required_suffix =  | ||||
| dotnet_naming_style.帕斯卡拼写法.word_separator =  | ||||
| dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case | ||||
							
								
								
									
										63
									
								
								framework/.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								framework/.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| ############################################################################### | ||||
| # Set default behavior to automatically normalize line endings. | ||||
| ############################################################################### | ||||
| * text=auto | ||||
|  | ||||
| ############################################################################### | ||||
| # Set default behavior for command prompt diff. | ||||
| # | ||||
| # This is need for earlier builds of msysgit that does not have it on by | ||||
| # default for csharp files. | ||||
| # Note: This is only used by command line | ||||
| ############################################################################### | ||||
| #*.cs     diff=csharp | ||||
|  | ||||
| ############################################################################### | ||||
| # Set the merge driver for project and solution files | ||||
| # | ||||
| # Merging from the command prompt will add diff markers to the files if there | ||||
| # are conflicts (Merging from VS is not affected by the settings below, in VS | ||||
| # the diff markers are never inserted). Diff markers may cause the following  | ||||
| # file extensions to fail to load in VS. An alternative would be to treat | ||||
| # these files as binary and thus will always conflict and require user | ||||
| # intervention with every merge. To do so, just uncomment the entries below | ||||
| ############################################################################### | ||||
| #*.sln       merge=binary | ||||
| #*.csproj    merge=binary | ||||
| #*.vbproj    merge=binary | ||||
| #*.vcxproj   merge=binary | ||||
| #*.vcproj    merge=binary | ||||
| #*.dbproj    merge=binary | ||||
| #*.fsproj    merge=binary | ||||
| #*.lsproj    merge=binary | ||||
| #*.wixproj   merge=binary | ||||
| #*.modelproj merge=binary | ||||
| #*.sqlproj   merge=binary | ||||
| #*.wwaproj   merge=binary | ||||
|  | ||||
| ############################################################################### | ||||
| # behavior for image files | ||||
| # | ||||
| # image files are treated as binary by default. | ||||
| ############################################################################### | ||||
| #*.jpg   binary | ||||
| #*.png   binary | ||||
| #*.gif   binary | ||||
|  | ||||
| ############################################################################### | ||||
| # diff behavior for common document formats | ||||
| #  | ||||
| # Convert binary document formats to text before diffing them. This feature | ||||
| # is only available from the command line. Turn it on by uncommenting the  | ||||
| # entries below. | ||||
| ############################################################################### | ||||
| #*.doc   diff=astextplain | ||||
| #*.DOC   diff=astextplain | ||||
| #*.docx  diff=astextplain | ||||
| #*.DOCX  diff=astextplain | ||||
| #*.dot   diff=astextplain | ||||
| #*.DOT   diff=astextplain | ||||
| #*.pdf   diff=astextplain | ||||
| #*.PDF   diff=astextplain | ||||
| #*.rtf   diff=astextplain | ||||
| #*.RTF   diff=astextplain | ||||
							
								
								
									
										364
									
								
								framework/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										364
									
								
								framework/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,364 @@ | ||||
| ## Ignore Visual Studio temporary files, build results, and | ||||
| ## files generated by popular Visual Studio add-ons. | ||||
| ## | ||||
| ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore | ||||
|  | ||||
| # User-specific files | ||||
| *.rsuser | ||||
| *.suo | ||||
| *.user | ||||
| *.userosscache | ||||
| *.sln.docstates | ||||
|  | ||||
| # User-specific files (MonoDevelop/Xamarin Studio) | ||||
| *.userprefs | ||||
|  | ||||
| # Mono auto generated files | ||||
| mono_crash.* | ||||
|  | ||||
| # Build results | ||||
| [Dd]ebug/ | ||||
| [Dd]ebugPublic/ | ||||
| [Rr]elease/ | ||||
| [Rr]eleases/ | ||||
| x64/ | ||||
| x86/ | ||||
| [Ww][Ii][Nn]32/ | ||||
| [Aa][Rr][Mm]/ | ||||
| [Aa][Rr][Mm]64/ | ||||
| bld/ | ||||
| [Bb]in/ | ||||
| [Oo]bj/ | ||||
| [Oo]ut/ | ||||
| [Ll]og/ | ||||
| [Ll]ogs/ | ||||
|  | ||||
| # Visual Studio 2015/2017 cache/options directory | ||||
| .vs/ | ||||
| # Uncomment if you have tasks that create the project's static files in wwwroot | ||||
| #wwwroot/ | ||||
|  | ||||
| # Visual Studio 2017 auto generated files | ||||
| Generated\ Files/ | ||||
|  | ||||
| # MSTest test Results | ||||
| [Tt]est[Rr]esult*/ | ||||
| [Bb]uild[Ll]og.* | ||||
|  | ||||
| # NUnit | ||||
| *.VisualState.xml | ||||
| TestResult.xml | ||||
| nunit-*.xml | ||||
|  | ||||
| # Build Results of an ATL Project | ||||
| [Dd]ebugPS/ | ||||
| [Rr]eleasePS/ | ||||
| dlldata.c | ||||
|  | ||||
| # Benchmark Results | ||||
| BenchmarkDotNet.Artifacts/ | ||||
|  | ||||
| # .NET Core | ||||
| project.lock.json | ||||
| project.fragment.lock.json | ||||
| artifacts/ | ||||
|  | ||||
| # ASP.NET Scaffolding | ||||
| ScaffoldingReadMe.txt | ||||
|  | ||||
| # StyleCop | ||||
| StyleCopReport.xml | ||||
|  | ||||
| # Files built by Visual Studio | ||||
| *_i.c | ||||
| *_p.c | ||||
| *_h.h | ||||
| *.ilk | ||||
| *.meta | ||||
| *.obj | ||||
| *.iobj | ||||
| *.pch | ||||
| *.pdb | ||||
| *.ipdb | ||||
| *.pgc | ||||
| *.pgd | ||||
| *.rsp | ||||
| *.sbr | ||||
| *.tlb | ||||
| *.tli | ||||
| *.tlh | ||||
| *.tmp | ||||
| *.tmp_proj | ||||
| *_wpftmp.csproj | ||||
| *.log | ||||
| *.vspscc | ||||
| *.vssscc | ||||
| .builds | ||||
| *.pidb | ||||
| *.svclog | ||||
| *.scc | ||||
|  | ||||
| # Chutzpah Test files | ||||
| _Chutzpah* | ||||
|  | ||||
| # Visual C++ cache files | ||||
| ipch/ | ||||
| *.aps | ||||
| *.ncb | ||||
| *.opendb | ||||
| *.opensdf | ||||
| *.sdf | ||||
| *.cachefile | ||||
| *.VC.db | ||||
| *.VC.VC.opendb | ||||
|  | ||||
| # Visual Studio profiler | ||||
| *.psess | ||||
| *.vsp | ||||
| *.vspx | ||||
| *.sap | ||||
|  | ||||
| # Visual Studio Trace Files | ||||
| *.e2e | ||||
|  | ||||
| # TFS 2012 Local Workspace | ||||
| $tf/ | ||||
|  | ||||
| # Guidance Automation Toolkit | ||||
| *.gpState | ||||
|  | ||||
| # ReSharper is a .NET coding add-in | ||||
| _ReSharper*/ | ||||
| *.[Rr]e[Ss]harper | ||||
| *.DotSettings.user | ||||
|  | ||||
| # TeamCity is a build add-in | ||||
| _TeamCity* | ||||
|  | ||||
| # DotCover is a Code Coverage Tool | ||||
| *.dotCover | ||||
|  | ||||
| # AxoCover is a Code Coverage Tool | ||||
| .axoCover/* | ||||
| !.axoCover/settings.json | ||||
|  | ||||
| # Coverlet is a free, cross platform Code Coverage Tool | ||||
| coverage*.json | ||||
| coverage*.xml | ||||
| coverage*.info | ||||
|  | ||||
| # Visual Studio code coverage results | ||||
| *.coverage | ||||
| *.coveragexml | ||||
|  | ||||
| # NCrunch | ||||
| _NCrunch_* | ||||
| .*crunch*.local.xml | ||||
| nCrunchTemp_* | ||||
|  | ||||
| # MightyMoose | ||||
| *.mm.* | ||||
| AutoTest.Net/ | ||||
|  | ||||
| # Web workbench (sass) | ||||
| .sass-cache/ | ||||
|  | ||||
| # Installshield output folder | ||||
| [Ee]xpress/ | ||||
|  | ||||
| # DocProject is a documentation generator add-in | ||||
| DocProject/buildhelp/ | ||||
| DocProject/Help/*.HxT | ||||
| DocProject/Help/*.HxC | ||||
| DocProject/Help/*.hhc | ||||
| DocProject/Help/*.hhk | ||||
| DocProject/Help/*.hhp | ||||
| DocProject/Help/Html2 | ||||
| DocProject/Help/html | ||||
|  | ||||
| # Click-Once directory | ||||
| publish/ | ||||
|  | ||||
| # Publish Web Output | ||||
| *.[Pp]ublish.xml | ||||
| *.azurePubxml | ||||
| # Note: Comment the next line if you want to checkin your web deploy settings, | ||||
| # but database connection strings (with potential passwords) will be unencrypted | ||||
| *.pubxml | ||||
| *.publishproj | ||||
|  | ||||
| # Microsoft Azure Web App publish settings. Comment the next line if you want to | ||||
| # checkin your Azure Web App publish settings, but sensitive information contained | ||||
| # in these scripts will be unencrypted | ||||
| PublishScripts/ | ||||
|  | ||||
| # NuGet Packages | ||||
| *.nupkg | ||||
| # NuGet Symbol Packages | ||||
| *.snupkg | ||||
| # The packages folder can be ignored because of Package Restore | ||||
| **/[Pp]ackages/* | ||||
| # except build/, which is used as an MSBuild target. | ||||
| !**/[Pp]ackages/build/ | ||||
| # Uncomment if necessary however generally it will be regenerated when needed | ||||
| #!**/[Pp]ackages/repositories.config | ||||
| # NuGet v3's project.json files produces more ignorable files | ||||
| *.nuget.props | ||||
| *.nuget.targets | ||||
|  | ||||
| # Microsoft Azure Build Output | ||||
| csx/ | ||||
| *.build.csdef | ||||
|  | ||||
| # Microsoft Azure Emulator | ||||
| ecf/ | ||||
| rcf/ | ||||
|  | ||||
| # Windows Store app package directories and files | ||||
| AppPackages/ | ||||
| BundleArtifacts/ | ||||
| Package.StoreAssociation.xml | ||||
| _pkginfo.txt | ||||
| *.appx | ||||
| *.appxbundle | ||||
| *.appxupload | ||||
|  | ||||
| # Visual Studio cache files | ||||
| # files ending in .cache can be ignored | ||||
| *.[Cc]ache | ||||
| # but keep track of directories ending in .cache | ||||
| !?*.[Cc]ache/ | ||||
|  | ||||
| # Others | ||||
| ClientBin/ | ||||
| ~$* | ||||
| *~ | ||||
| *.dbmdl | ||||
| *.dbproj.schemaview | ||||
| *.jfm | ||||
| *.pfx | ||||
| *.publishsettings | ||||
| orleans.codegen.cs | ||||
|  | ||||
| # Including strong name files can present a security risk | ||||
| # (https://github.com/github/gitignore/pull/2483#issue-259490424) | ||||
| #*.snk | ||||
|  | ||||
| # Since there are multiple workflows, uncomment next line to ignore bower_components | ||||
| # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | ||||
| #bower_components/ | ||||
|  | ||||
| # RIA/Silverlight projects | ||||
| Generated_Code/ | ||||
|  | ||||
| # Backup & report files from converting an old project file | ||||
| # to a newer Visual Studio version. Backup files are not needed, | ||||
| # because we have git ;-) | ||||
| _UpgradeReport_Files/ | ||||
| Backup*/ | ||||
| UpgradeLog*.XML | ||||
| UpgradeLog*.htm | ||||
| ServiceFabricBackup/ | ||||
| *.rptproj.bak | ||||
|  | ||||
| # SQL Server files | ||||
| *.mdf | ||||
| *.ldf | ||||
| *.ndf | ||||
|  | ||||
| # Business Intelligence projects | ||||
| *.rdl.data | ||||
| *.bim.layout | ||||
| *.bim_*.settings | ||||
| *.rptproj.rsuser | ||||
| *- [Bb]ackup.rdl | ||||
| *- [Bb]ackup ([0-9]).rdl | ||||
| *- [Bb]ackup ([0-9][0-9]).rdl | ||||
|  | ||||
| # Microsoft Fakes | ||||
| FakesAssemblies/ | ||||
|  | ||||
| # GhostDoc plugin setting file | ||||
| *.GhostDoc.xml | ||||
|  | ||||
| # Node.js Tools for Visual Studio | ||||
| .ntvs_analysis.dat | ||||
| node_modules/ | ||||
|  | ||||
| # Visual Studio 6 build log | ||||
| *.plg | ||||
|  | ||||
| # Visual Studio 6 workspace options file | ||||
| *.opt | ||||
|  | ||||
| # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) | ||||
| *.vbw | ||||
|  | ||||
| # Visual Studio LightSwitch build output | ||||
| **/*.HTMLClient/GeneratedArtifacts | ||||
| **/*.DesktopClient/GeneratedArtifacts | ||||
| **/*.DesktopClient/ModelManifest.xml | ||||
| **/*.Server/GeneratedArtifacts | ||||
| **/*.Server/ModelManifest.xml | ||||
| _Pvt_Extensions | ||||
|  | ||||
| # Paket dependency manager | ||||
| .paket/paket.exe | ||||
| paket-files/ | ||||
|  | ||||
| # FAKE - F# Make | ||||
| .fake/ | ||||
|  | ||||
| # CodeRush personal settings | ||||
| .cr/personal | ||||
|  | ||||
| # Python Tools for Visual Studio (PTVS) | ||||
| __pycache__/ | ||||
| *.pyc | ||||
|  | ||||
| # Cake - Uncomment if you are using it | ||||
| # tools/** | ||||
| # !tools/packages.config | ||||
|  | ||||
| # Tabs Studio | ||||
| *.tss | ||||
|  | ||||
| # Telerik's JustMock configuration file | ||||
| *.jmconfig | ||||
|  | ||||
| # BizTalk build output | ||||
| *.btp.cs | ||||
| *.btm.cs | ||||
| *.odx.cs | ||||
| *.xsd.cs | ||||
|  | ||||
| # OpenCover UI analysis results | ||||
| OpenCover/ | ||||
|  | ||||
| # Azure Stream Analytics local run output | ||||
| ASALocalRun/ | ||||
|  | ||||
| # MSBuild Binary and Structured Log | ||||
| *.binlog | ||||
|  | ||||
| # NVidia Nsight GPU debugger configuration file | ||||
| *.nvuser | ||||
|  | ||||
| # MFractors (Xamarin productivity tool) working folder | ||||
| .mfractor/ | ||||
|  | ||||
| # Local History for Visual Studio | ||||
| .localhistory/ | ||||
|  | ||||
| # BeatPulse healthcheck temp database | ||||
| healthchecksdb | ||||
|  | ||||
| # Backup folder for Package Reference Convert tool in Visual Studio 2017 | ||||
| MigrationBackup/ | ||||
|  | ||||
| # Ionide (cross platform F# VS Code tools) working folder | ||||
| .ionide/ | ||||
|  | ||||
| # Fody - auto-generated XML schema | ||||
| FodyWeavers.xsd | ||||
|  | ||||
							
								
								
									
										15
									
								
								framework/Demo/Directory.Build.props
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								framework/Demo/Directory.Build.props
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| <Project> | ||||
| 	<PropertyGroup> | ||||
| 		<Version>3.0.0.16</Version> | ||||
| 		<LangVersion>latest</LangVersion> | ||||
| 		<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | ||||
| 		<Authors>Diego</Authors> | ||||
| 		<Product>ThingsGateway</Product> | ||||
| 		<Copyright>© 2023-present Diego</Copyright> | ||||
| 		<RepositoryUrl>https://gitee.com/diego2098/ThingsGateway</RepositoryUrl> | ||||
| 		<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages> | ||||
| 		<GenerateDocumentationFile>False</GenerateDocumentationFile> | ||||
| 	</PropertyGroup> | ||||
|  | ||||
|  | ||||
| </Project> | ||||
| @@ -23,8 +23,6 @@ internal class Program | ||||
| 
 | ||||
|         var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args); | ||||
| 
 | ||||
|         Serve.RunNative(); | ||||
| 
 | ||||
|         appBuilder.RootComponents.Add<App>("#app"); | ||||
| 
 | ||||
|         appBuilder.Services.ThingsGatewayComponentsConfigureServices(); | ||||
| @@ -34,6 +32,7 @@ internal class Program | ||||
|         AppDomain.CurrentDomain.UnhandledException += (sender, error) => | ||||
|         { | ||||
|         }; | ||||
| 
 | ||||
|         app.Run(); | ||||
|     } | ||||
| } | ||||
| @@ -2,7 +2,6 @@ | ||||
| 
 | ||||
| 	<PropertyGroup> | ||||
| 		<OutputType>WinExe</OutputType> | ||||
| 		<TargetFrameworks>net6.0;net8.0;</TargetFrameworks> | ||||
| 		<ApplicationIcon>favicon.ico</ApplicationIcon> | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| @@ -29,18 +28,5 @@ | ||||
| 	</ItemGroup> | ||||
| 
 | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
| 	  <Content Update="wwwroot\favicon.ico"> | ||||
| 	    <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
| 	  </Content> | ||||
| 	  <Content Update="wwwroot\favicon.png"> | ||||
| 	    <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
| 	  </Content> | ||||
| 	  <Content Update="wwwroot\index.html"> | ||||
| 	    <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
| 	  </Content> | ||||
| 	</ItemGroup> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| </Project> | ||||
| Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB | 
| @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Components; | ||||
| 
 | ||||
| using ThingsGateway.Components; | ||||
| 
 | ||||
| 
 | ||||
| namespace ThingsGateway.Foundation.Demo; | ||||
| using LogLevel = Microsoft.Extensions.Logging.LogLevel; | ||||
| /// <summary> | ||||
| @@ -35,17 +34,12 @@ public abstract class DriverDebugUIBase : ComponentBase, IDisposable | ||||
|         this.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 变量地址 | ||||
|     /// </summary> | ||||
|     public virtual string Address { get; set; } = "40001"; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     [Inject] | ||||
|     public InitTimezone InitTimezone { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 长度 | ||||
|     /// </summary> | ||||
| @@ -64,6 +58,13 @@ public abstract class DriverDebugUIBase : ComponentBase, IDisposable | ||||
|     /// 数据类型 | ||||
|     /// </summary> | ||||
|     protected virtual DataTypeEnum DataTypeEnum { get; set; } = DataTypeEnum.Int16; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     [Inject] | ||||
|     public InitTimezone InitTimezone { get; set; } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public virtual void Dispose() | ||||
|     { | ||||
| @@ -47,7 +47,7 @@ | ||||
|                                 <MRow Class="my-1" Justify="JustifyTypes.Start" Align="AlignTypes.Start" NoGutters> | ||||
|                                 <MTextField Class="mx-1 my-1" Style="max-width:200px" Label="读取长度" Dense Outlined HideDetails="@("auto")" @bind-Value=@Length /> | ||||
|                                     <MSelect Class="mx-1 my-1" Style="max-width:200px" @bind-Value="DataTypeEnum" Outlined Label="数据类型" | ||||
|                                              Items=@(typeof(DataTypeEnum).GetEnumList()) | ||||
|                                              Items=@(typeof(DataTypeEnum).GetEnumListWithOutSugar()) | ||||
|                                              MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })" | ||||
|                                              ItemText=@((u) =>u.Description) | ||||
|                                              ItemValue=@(u =>(DataTypeEnum)u.Value) | ||||
| @@ -87,9 +87,9 @@ | ||||
|                                 @foreach (var item in DeviceVariableRunTimes) | ||||
|                                 { | ||||
|                                     <MRow Dense Align="AlignTypes.Center"> | ||||
|                                         <MTextField Class="ma-1" Outlined Style="min-width:100px" Label=@(item.Description(x => x.Address)) Dense HideDetails="@("auto")" @bind-Value=@item.Address></MTextField> | ||||
|                                         <MSelect Class="mx-1 my-1" Style="max-width:120px" @bind-Value="item.DataTypeEnum" Outlined Label=@(item.Description(x => x.DataTypeEnum)) | ||||
|                                                  Items=@(typeof(DataTypeEnum).GetEnumList()) | ||||
|                                         <MTextField Class="ma-1" Outlined Style="min-width:100px" Label=@(item.DescriptionWithOutSugar(x => x.VariableAddress)) Dense HideDetails="@("auto")" @bind-Value=@item.VariableAddress></MTextField> | ||||
|                                         <MSelect Class="mx-1 my-1" Style="max-width:120px" @bind-Value="item.DataTypeEnum" Outlined Label=@(item.DescriptionWithOutSugar(x => x.DataTypeEnum)) | ||||
|                                                  Items=@(typeof(DataTypeEnum).GetEnumListWithOutSugar()) | ||||
|                                                  MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })" | ||||
|                                                  ItemText=@((u) =>u.Description) | ||||
|                                                  ItemValue=@(u =>(DataTypeEnum)u.Value) | ||||
| @@ -97,7 +97,7 @@ | ||||
|                                               Dense> | ||||
|                                     </MSelect> | ||||
| 
 | ||||
|                                     <MTextField Class="ma-1" Outlined Style="max-width:100px" Label=@(item.Description(x => x.IntervalTime)) Dense HideDetails="@("auto")" @bind-Value=@item.IntervalTime></MTextField> | ||||
|                                     <MTextField Class="ma-1" Outlined Style="max-width:100px" Label=@(item.DescriptionWithOutSugar(x => x.IntervalTime)) Dense HideDetails="@("auto")" @bind-Value=@item.IntervalTime></MTextField> | ||||
| 
 | ||||
|                                         <MTextField Class="ma-1" Outlined Style="max-width:100px" Label=实时值 Readonly ClearIcon="" Dense HideDetails="@("auto")" Value=item.Value?.ToJsonString()></MTextField> | ||||
| 
 | ||||
| @@ -30,66 +30,16 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|     /// MaxPack | ||||
|     /// </summary> | ||||
|     public int MaxPack = 100; | ||||
|     private StringNumber _selected = 0; | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     ~DriverDebugUIPage() | ||||
|     { | ||||
|         this.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment CodeContent { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment OtherContent { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public override IReadWrite Plc { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment ReadWriteContent { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Sections | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public List<(string Code, string Language)> Sections { get; set; } = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// ShowDefaultOtherContent | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public bool ShowDefaultOtherContent { get; set; } = true; | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void Dispose() | ||||
|     { | ||||
|         Plc?.SafeDispose(); | ||||
|         base.Dispose(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// MulReadAsync | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public async Task MulReadAsync() | ||||
|     { | ||||
|         var deviceVariableSourceReads = Plc.LoadSourceRead<DeviceVariableSourceRead, DeviceVariableRunTime>(DeviceVariableRunTimes, MaxPack, 1000); | ||||
|         var deviceVariableSourceReads = Plc.LoadSourceRead<DeviceVariableSourceRead, DeviceVariableRunTime>(DeviceVariableRunTimes, MaxPack); | ||||
|         foreach (var item in deviceVariableSourceReads) | ||||
|         { | ||||
|             var result = await Plc.ReadAsync(item.Address, item.Length); | ||||
|             var result = await Plc.ReadAsync(item.VariableAddress, item.Length); | ||||
|             if (result.IsSuccess) | ||||
|             { | ||||
|                 try | ||||
| @@ -107,14 +57,20 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                 Messages.Add((Microsoft.Extensions.Logging.LogLevel.Warning, DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + result.Message)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private StringNumber _selected = 0; | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// Sections | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
|     [Parameter] | ||||
|     public List<(string Code, string Language)> Sections { get; set; } = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// ShowDefaultOtherContent | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public bool ShowDefaultOtherContent { get; set; } = true; | ||||
| 
 | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
| @@ -124,25 +80,25 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                                 new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40001", | ||||
|                                     VariableAddress="40001", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40011", | ||||
|                                     VariableAddress="40011", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40031", | ||||
|                                     VariableAddress="40031", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40101", | ||||
|                                     VariableAddress="40101", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|             }; | ||||
| @@ -154,7 +110,7 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                     /// <inheritdoc/> | ||||
|                     public TimerTick TimerTick { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
|                     public string Address { get; set; } | ||||
|                     public string VariableAddress { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
|                     public int Length { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
| @@ -168,7 +124,7 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                     public int IntervalTime { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
|                     [Description("变量地址")] | ||||
|                     public string Address { get; set; } | ||||
|                     public string VariableAddress { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
|                     public int Index { get; set; } | ||||
|                     /// <inheritdoc/> | ||||
| @@ -195,25 +151,25 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                                 new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40001", | ||||
|                                     VariableAddress="40001", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40011", | ||||
|                                     VariableAddress="40011", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40031", | ||||
|                                     VariableAddress="40031", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                                    new DeviceVariableRunTime() | ||||
|                                 { | ||||
|                                     DataTypeEnum=DataTypeEnum.Int16, | ||||
|                                     Address="40101", | ||||
|                                     VariableAddress="40101", | ||||
|                                     IntervalTime=1000, | ||||
|                                 }, | ||||
|                 }; | ||||
| @@ -222,7 +178,7 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
|                 var deviceVariableSourceReads = Plc.LoadSourceRead<DeviceVariableSourceRead, DeviceVariableRunTime>(DeviceVariableRunTimes, MaxPack); | ||||
|                 foreach (var item in deviceVariableSourceReads) | ||||
|                 { | ||||
|                     var result = await Plc.ReadAsync(item.Address, item.Length); | ||||
|                     var result = await Plc.ReadAsync(item.VariableAddress, item.Length); | ||||
|                     if (result.IsSuccess) | ||||
|                     { | ||||
|                         item.DeviceVariableRunTimes.PraseStructContent(result.Content); | ||||
| @@ -235,4 +191,46 @@ public partial class DriverDebugUIPage : DriverDebugUIBase | ||||
| """, "csharp"));
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment ReadWriteContent { get; set; } | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment OtherContent { get; set; } | ||||
|     /// <summary> | ||||
|     /// 自定义模板 | ||||
|     /// </summary> | ||||
|     [Parameter] | ||||
|     public RenderFragment CodeContent { get; set; } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     ~DriverDebugUIPage() | ||||
|     { | ||||
|         this.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public override IReadWrite Plc { get; set; } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void Dispose() | ||||
|     { | ||||
|         Plc?.SafeDispose(); | ||||
|         base.Dispose(); | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| } | ||||
| @@ -15,22 +15,22 @@ | ||||
| @using Microsoft.AspNetCore.Components.Web; | ||||
| @using System.IO.Ports; | ||||
| @using Masa.Blazor | ||||
| <MCard Flat Class="pa-2 my-1" Style="width:100%"> | ||||
| <MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%"> | ||||
|     <div class="mb-4">通道配置</div> | ||||
|     <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center"> | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(_serialProperty.Description(x => x.PortName)) Dense HideDetails="@("auto")" @bind-Value=@_serialProperty.PortName /> | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(_serialProperty.Description(x => x.BaudRate)) Dense HideDetails="@("auto")" @bind-Value=@_serialProperty.BaudRate /> | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(_serialProperty.Description(x => x.DataBits)) Dense HideDetails="@("auto")" @bind-Value=@_serialProperty.DataBits /> | ||||
|         <MSelect Class="ma-1 " Style="max-width:200px" Outlined @bind-Value="_serialProperty.Parity" Label="@(_serialProperty.Description(x => x.Parity))" | ||||
|                  Items=@(typeof(Parity).GetEnumList()) | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(serialProperty.DescriptionWithOutSugar(x => x.PortName)) Dense HideDetails="@("auto")" @bind-Value=@serialProperty.PortName /> | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(serialProperty.DescriptionWithOutSugar(x => x.BaudRate)) Dense HideDetails="@("auto")" @bind-Value=@serialProperty.BaudRate /> | ||||
|         <MTextField Style="max-width:100px" Class="ma-1" Outlined Label=@(serialProperty.DescriptionWithOutSugar(x => x.DataBits)) Dense HideDetails="@("auto")" @bind-Value=@serialProperty.DataBits /> | ||||
|         <MSelect Class="ma-1 " Style="max-width:200px" Outlined @bind-Value="serialProperty.Parity" Label="@(serialProperty.DescriptionWithOutSugar(x => x.Parity))" | ||||
|                  Items=@(typeof(Parity).GetEnumListWithOutSugar()) | ||||
|                  MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })" | ||||
|                  ItemText=@((u) =>u.Description) | ||||
|                  ItemValue=@(u =>(Parity)u.Value) | ||||
|                  HideDetails=@("auto") Height="30" | ||||
|                  Dense> | ||||
|         </MSelect> | ||||
|         <MSelect Class="ma-1 " Style="max-width:200px" Outlined @bind-Value="_serialProperty.StopBits" Label="@(_serialProperty.Description(x => x.StopBits))" | ||||
|                  Items=@(typeof(StopBits).GetEnumList()) | ||||
|         <MSelect Class="ma-1 " Style="max-width:200px" Outlined @bind-Value="serialProperty.StopBits" Label="@(serialProperty.DescriptionWithOutSugar(x => x.StopBits))" | ||||
|                  Items=@(typeof(StopBits).GetEnumListWithOutSugar()) | ||||
|                  MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })" | ||||
|                  ItemText=@((u) =>u.Description) | ||||
|                  ItemValue=@(u =>(StopBits)u.Value) | ||||
| @@ -20,17 +20,11 @@ public partial class SerialSessionPage : IDisposable | ||||
|     /// </summary> | ||||
|     public Action<LogLevel, object, string, Exception> LogAction; | ||||
| 
 | ||||
|     private readonly SerialProperty _serialProperty = new(); | ||||
|     private TouchSocketConfig _config; | ||||
|     private SerialSession _serialSession { get; set; } = new(); | ||||
|     private TouchSocketConfig config; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _serialSession.SafeDispose(); | ||||
|     } | ||||
|     private readonly SerialProperty serialProperty = new(); | ||||
| 
 | ||||
|     private SerialSession SerialSession { get; set; } = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
| @@ -38,49 +32,20 @@ public partial class SerialSessionPage : IDisposable | ||||
|     /// <returns></returns> | ||||
|     public SerialSession GetSerialSession() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
|         config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         _config.SetSerialProperty(_serialProperty); | ||||
|         config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         config.SetSerialProperty(serialProperty); | ||||
|         //载入配置 | ||||
|         _serialSession.Setup(_config); | ||||
|         return _serialSession; | ||||
|         SerialSession.Setup(config); | ||||
|         return SerialSession; | ||||
|     } | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             _serialSession.Setup(_config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
| 
 | ||||
|     private async Task ConnectAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _serialSession.Close(); | ||||
|             SerialSession.Close(); | ||||
|             await GetSerialSession().ConnectAsync(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
| @@ -93,12 +58,49 @@ public partial class SerialSessionPage : IDisposable | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _serialSession.Close(); | ||||
|             SerialSession.Close(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             LogAction?.Invoke(LogLevel.Error, null, null, ex); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             SerialSession.Setup(config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     private void LogOut(LogLevel logLevel, object source, string message, Exception exception) => LogAction?.Invoke(logLevel, source, message, exception); | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         SerialSession.SafeDispose(); | ||||
|     } | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
| @@ -17,12 +17,12 @@ | ||||
| @using System.Collections.Concurrent; | ||||
| @using ThingsGateway.Foundation.Core; | ||||
| @using Masa.Blazor | ||||
| <MCard Flat Class="pa-2 my-1" Style="width:100%"> | ||||
| <MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%"> | ||||
|     <div class="mb-4">通道配置</div> | ||||
|     <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center"> | ||||
| 
 | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@_ip /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@_port /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@IP /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@Port /> | ||||
| 
 | ||||
|         <MButton Class="ma-1" OnClick=@ConnectAsync Color="primary"> | ||||
|             连接 | ||||
| @@ -20,77 +20,23 @@ public partial class TcpClientPage : IDisposable | ||||
|     /// </summary> | ||||
|     public Action<LogLevel, object, string, Exception> LogAction; | ||||
| 
 | ||||
|     private TouchSocketConfig _config; | ||||
|     private TouchSocketConfig config; | ||||
|     /// <summary> | ||||
|     /// IP | ||||
|     /// </summary> | ||||
|     private string _ip = "127.0.0.1"; | ||||
|     private string IP = "127.0.0.1"; | ||||
|     /// <summary> | ||||
|     /// Port | ||||
|     /// </summary> | ||||
|     public int _port { get; set; } = 502; | ||||
|     public int Port { get; set; } = 502; | ||||
| 
 | ||||
|     private TcpClient _tcpClient { get; set; } = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _tcpClient.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public TcpClient GetTcpClient() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         _config.SetRemoteIPHost(new IPHost(_ip + ":" + _port)); | ||||
|         //载入配置 | ||||
|         _tcpClient.Setup(_config); | ||||
|         return _tcpClient; | ||||
|     } | ||||
| 
 | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             _config.SetRemoteIPHost(new IPHost(_ip + ":" + _port)); | ||||
|             _tcpClient.Setup(_config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
|     private TcpClient TcpClient { get; set; } = new(); | ||||
| 
 | ||||
|     private async Task ConnectAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _tcpClient.Close(); | ||||
|             TcpClient.Close(); | ||||
|             await GetTcpClient().ConnectAsync(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
| @@ -104,7 +50,7 @@ public partial class TcpClientPage : IDisposable | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _tcpClient.Close(); | ||||
|             TcpClient.Close(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -112,5 +58,59 @@ public partial class TcpClientPage : IDisposable | ||||
|             LogAction?.Invoke(LogLevel.Error, null, null, ex); | ||||
|         } | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public TcpClient GetTcpClient() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         config.SetRemoteIPHost(new IPHost(IP + ":" + Port)); | ||||
|         //载入配置 | ||||
|         TcpClient.Setup(config); | ||||
|         return TcpClient; | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             config.SetRemoteIPHost(new IPHost(IP + ":" + Port)); | ||||
|             TcpClient.Setup(config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     private void LogOut(LogLevel logLevel, object source, string message, Exception exception) => LogAction?.Invoke(logLevel, source, message, exception); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         TcpClient.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
| @@ -18,18 +18,18 @@ | ||||
| @using ThingsGateway.Foundation.Core; | ||||
| @using Masa.Blazor | ||||
| 
 | ||||
| <MCard Flat Class="pa-2 my-1" Style="width:100%"> | ||||
| <MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%"> | ||||
|     <div class="mb-4">通道配置</div> | ||||
|     <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center"> | ||||
| 
 | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@_ip /> | ||||
|          <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@_port /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@ip /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@port /> | ||||
| 
 | ||||
|         <MButton Class="ma-1" OnClick=@Connect Color="primary"> | ||||
|             启动 | ||||
|             连接 | ||||
|         </MButton> | ||||
|         <MButton Class="ma-1" OnClick=@DisConnect Color="red"> | ||||
|             停止 | ||||
|             断开 | ||||
|         </MButton> | ||||
| 
 | ||||
| 
 | ||||
| @@ -20,73 +20,19 @@ public partial class TcpServerPage : IDisposable | ||||
|     /// </summary> | ||||
|     public Action<LogLevel, object, string, Exception> LogAction; | ||||
| 
 | ||||
|     private TouchSocketConfig _config; | ||||
|     private TouchSocketConfig config; | ||||
| 
 | ||||
|     private string _ip = "127.0.0.1"; | ||||
|     private string ip = "127.0.0.1"; | ||||
| 
 | ||||
|     private int _port = 502; | ||||
|     private int port = 502; | ||||
| 
 | ||||
|     private TcpService _tcpServer { get; set; } = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _tcpServer.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public TcpService GetTcpServer() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         _config.SetListenIPHosts(new IPHost[] { new IPHost(_ip + ":" + _port) }); | ||||
|         //载入配置 | ||||
|         _tcpServer.Setup(_config); | ||||
|         return _tcpServer; | ||||
|     } | ||||
| 
 | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             _config.SetListenIPHosts(new IPHost[] { new IPHost(_ip + ":" + _port) }); | ||||
|             _tcpServer.Setup(_config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
|     private TcpService TcpServer { get; set; } = new(); | ||||
| 
 | ||||
|     private void Connect() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _tcpServer.Stop(); | ||||
|             TcpServer.Stop(); | ||||
|             GetTcpServer().Start(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
| @@ -100,12 +46,63 @@ public partial class TcpServerPage : IDisposable | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _tcpServer.Stop(); | ||||
|             TcpServer.Stop(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             LogAction?.Invoke(LogLevel.Error, null, null, ex); | ||||
|         } | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public TcpService GetTcpServer() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         config.SetListenIPHosts(new IPHost[] { new IPHost(ip + ":" + port) }); | ||||
|         //载入配置 | ||||
|         TcpServer.Setup(config); | ||||
|         return TcpServer; | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             config.SetListenIPHosts(new IPHost[] { new IPHost(ip + ":" + port) }); | ||||
|             TcpServer.Setup(config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     private void LogOut(LogLevel logLevel, object source, string message, Exception exception) => LogAction?.Invoke(logLevel, source, message, exception); | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         TcpServer.SafeDispose(); | ||||
|     } | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
| @@ -18,12 +18,12 @@ | ||||
| @using ThingsGateway.Foundation.Core; | ||||
| @using Masa.Blazor | ||||
| 
 | ||||
| <MCard Flat Class="pa-2 my-1" Style="width:100%"> | ||||
| <MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%"> | ||||
|     <div class="mb-4">通道配置</div> | ||||
|     <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center"> | ||||
| 
 | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@_ip /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@_port /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="IP地址" Dense Outlined HideDetails="@("auto")" @bind-Value=@IP /> | ||||
|         <MTextField Class="ma-1" Style="max-width:100px" Label="端口" Dense Outlined HideDetails="@("auto")" @bind-Value=@Port /> | ||||
| 
 | ||||
|         <MButton Class="ma-1" OnClick=Connect Color="primary"> | ||||
|             连接 | ||||
| @@ -15,85 +15,28 @@ namespace ThingsGateway.Foundation.Demo; | ||||
| /// <inheritdoc/> | ||||
| public partial class UdpSessionPage : IDisposable | ||||
| { | ||||
|     /// <summary> | ||||
|     /// IP | ||||
|     /// </summary> | ||||
|     public string _ip = "127.0.0.1"; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Port | ||||
|     /// </summary> | ||||
|     public int _port = 502; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 日志输出 | ||||
|     /// </summary> | ||||
|     public Action<LogLevel, object, string, Exception> LogAction; | ||||
| 
 | ||||
|     private TouchSocketConfig _config; | ||||
|     private UdpSession _udpSession { get; set; } = new(); | ||||
| 
 | ||||
|     private TouchSocketConfig config; | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// IP | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _udpSession.SafeDispose(); | ||||
|     } | ||||
| 
 | ||||
|     public string IP = "127.0.0.1"; | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// Port | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public UdpSession GetUdpSession() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         _config.SetRemoteIPHost(new IPHost(_ip + ":" + _port)); | ||||
|         _config.SetBindIPHost(new IPHost(0)); | ||||
|         //载入配置 | ||||
|         _udpSession.Setup(_config); | ||||
|         return _udpSession; | ||||
|     } | ||||
|     public int Port = 502; | ||||
| 
 | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             _config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             _config.SetRemoteIPHost(new IPHost(_ip + ":" + _port)); | ||||
|             _config.SetBindIPHost(new IPHost(0)); | ||||
|             _udpSession.Setup(_config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         _config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
|     private UdpSession UdpSession { get; set; } = new(); | ||||
| 
 | ||||
|     private void Connect() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _udpSession.Stop(); | ||||
|             UdpSession.Stop(); | ||||
|             GetUdpSession().Start(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
| @@ -106,7 +49,7 @@ public partial class UdpSessionPage : IDisposable | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _udpSession.Stop(); | ||||
|             UdpSession.Stop(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -114,5 +57,57 @@ public partial class UdpSessionPage : IDisposable | ||||
|             LogAction?.Invoke(LogLevel.Error, null, null, ex); | ||||
|         } | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// 获取对象 | ||||
|     /// </summary> | ||||
|     /// <returns></returns> | ||||
|     public UdpSession GetUdpSession() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
|         var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|         LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|         config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|         config.SetRemoteIPHost(new IPHost(IP + ":" + Port)); | ||||
|         config.SetBindIPHost(new IPHost(0)); | ||||
|         //载入配置 | ||||
|         UdpSession.Setup(config); | ||||
|         return UdpSession; | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         config ??= new TouchSocketConfig(); | ||||
| 
 | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     /// <param name="firstRender"></param> | ||||
|     protected override void OnAfterRender(bool firstRender) | ||||
|     { | ||||
|         if (firstRender) | ||||
|         { | ||||
|             var LogMessage = new LoggerGroup() { LogLevel = LogLevel.Trace }; | ||||
|             LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = LogLevel.Trace }); | ||||
|             config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage)); | ||||
|             config.SetRemoteIPHost(new IPHost(IP + ":" + Port)); | ||||
|             config.SetBindIPHost(new IPHost(0)); | ||||
|             UdpSession.Setup(config); | ||||
|         } | ||||
|         base.OnAfterRender(firstRender); | ||||
|     } | ||||
|     private void LogOut(LogLevel logLevel, object source, string message, Exception exception) => LogAction?.Invoke(logLevel, source, message, exception); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     public void Dispose() | ||||
|     { | ||||
|         UdpSession.SafeDispose(); | ||||
|     } | ||||
|     internal void StateHasChangedAsync() | ||||
|     { | ||||
|         StateHasChanged(); | ||||
|     } | ||||
| } | ||||
| @@ -19,10 +19,10 @@ public class DeviceVariableRunTime : IDeviceVariableRunTime | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     [Description("读取间隔")] | ||||
|     public int? IntervalTime { get; set; } | ||||
|     public int IntervalTime { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     [Description("变量地址")] | ||||
|     public string Address { get; set; } | ||||
|     public string VariableAddress { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     public int Index { get; set; } | ||||
|     /// <inheritdoc/> | ||||
| @@ -33,16 +33,10 @@ public class DeviceVariableRunTime : IDeviceVariableRunTime | ||||
|     /// <inheritdoc/> | ||||
|     [Description("实时值")] | ||||
|     public object Value { get; set; } | ||||
| 
 | ||||
|     public bool IsOnline { get; set; } | ||||
| 
 | ||||
|     public string LastErrorMessage { get; set; } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public OperResult SetValue(object value, DateTime dateTime = default, string lastErrorMessage = null) | ||||
|     public OperResult SetValue(object value, DateTime dateTime = default, bool isOnline = true) | ||||
|     { | ||||
|         Value = value; | ||||
|         return OperResult.CreateSuccessResult(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @@ -18,9 +18,9 @@ namespace ThingsGateway.Foundation.Demo; | ||||
| public class DeviceVariableSourceRead : IDeviceVariableSourceRead<IDeviceVariableRunTime> | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public TimerTick IntervalTimeTick { get; set; } | ||||
|     public TimerTick TimerTick { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     public string Address { get; set; } | ||||
|     public string VariableAddress { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     public int Length { get; set; } | ||||
|     /// <inheritdoc/> | ||||
| @@ -24,7 +24,7 @@ | ||||
|                 <Logo CONFIG_COPYRIGHT=@CONFIG_COPYRIGHT  CONFIG_TITLE=@CONFIG_TITLE HeightInt=@(IsMobile?BlazorResourceConst.AppBarHeight:BlazorResourceConst.AppBarHeight+BlazorResourceConst.PageTabsHeight) /> | ||||
|                 <AppList ClassString="overflow-y-auto" Routable | ||||
|                          StyleString=@($"height: calc(100vh - {BlazorResourceConst.AppBarHeight+BlazorResourceConst.PageTabsHeight}px);") | ||||
|                          Items="_navs" /> | ||||
|                          Items="Navs" /> | ||||
|             </MNavigationDrawer> | ||||
| 
 | ||||
|             <MAppBar Color="barcolor" Style=@($"{(!(IsMobile||_drawerOpen!=true)? "left:200px;":"")}") Elevation="1" App Flat ClippedRight Dense ElevateOnScroll | ||||
| @@ -37,7 +37,7 @@ | ||||
| 
 | ||||
|             <MMain Style=@($"{(!(IsMobile||_drawerOpen!=true)? "padding-left:200px;":"")}")> | ||||
|                 <div class="full-width"> | ||||
|                     <PageTabs @ref="_pageTabs" PageTabItems="_pageTabItems" /> | ||||
|                     <PageTabs @ref="_pageTabs" PageTabItems="pageTabItems" /> | ||||
|                 </div> | ||||
|                 <MDivider Center></MDivider> | ||||
|                 <MCard Flat Class="overflow-y-auto overflow-x-hidden ma-auto pa-0 rounded-0" Style=@($"height: calc(100vh - {BlazorResourceConst.AppBarHeight+BlazorResourceConst.PageTabsHeight+BlazorResourceConst.FooterHeight}px);")> | ||||
| @@ -1,12 +1,12 @@ | ||||
| #region copyright | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //------------------------------------------------------------------------------ | ||||
| #endregion | ||||
| 
 | ||||
| @@ -17,9 +17,8 @@ namespace ThingsGateway.Foundation.Demo; | ||||
| public partial class MainLayout | ||||
| { | ||||
| 
 | ||||
|     private List<NavItem> _navs { get; set; } = new(); | ||||
|     private List<PageTabItem> _pageTabItems { get; set; } = new(); | ||||
| 
 | ||||
|     private List<NavItem> Navs { get; set; } = new(); | ||||
|     private List<PageTabItem> pageTabItems { get; set; } = new(); | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         var dataString = | ||||
| @@ -27,7 +26,7 @@ public partial class MainLayout | ||||
| [ | ||||
|   { | ||||
|     "Href": "/index", | ||||
|     "Title": "首页" | ||||
|     "Title": "首页" | ||||
|   }, | ||||
|   { | ||||
|     "Title": "Modbus", | ||||
| @@ -70,8 +69,28 @@ public partial class MainLayout | ||||
|     "Title": "Siemens", | ||||
|     "Children": [ | ||||
|       { | ||||
|         "Href": "/Siemens", | ||||
|         "Title": "Siemens" | ||||
|         "Href": "/S7_1500", | ||||
|         "Title": "S7_1500" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/S7_1200", | ||||
|         "Title": "S7_1200" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/S7_200", | ||||
|         "Title": "S7_200" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/S7_200SMART", | ||||
|         "Title": "S7_200SMART" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/S7_300", | ||||
|         "Title": "S7_400" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/S7_400", | ||||
|         "Title": "S7_400" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
| @@ -119,7 +138,7 @@ public partial class MainLayout | ||||
| 
 | ||||
| 
 | ||||
| """;
 | ||||
|         _navs = dataString.FromJsonString<List<NavItem>>(); | ||||
|         Navs = dataString.FromJsonString<List<NavItem>>(); | ||||
| 
 | ||||
| #if Pro | ||||
|         var dataStringPro = | ||||
| @@ -188,47 +207,26 @@ public partial class MainLayout | ||||
|     ] | ||||
|   }, | ||||
|   { | ||||
|     "Title": "HZW_QTJC_01", | ||||
|     "Title": "GasCustom", | ||||
|     "Children": [ | ||||
|       { | ||||
|         "Href": "/HZW_QTJC_01Serial", | ||||
|         "Title": "HZW_QTJC_01Serial" | ||||
|         "Href": "/GasCustomSerial", | ||||
|         "Title": "GasCustomSerial" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/HZW_QTJC_01SerialOverTcp", | ||||
|         "Title": "HZW_QTJC_01SerialOverTcp" | ||||
|         "Href": "/GasCustomSerialOverTcp", | ||||
|         "Title": "GasCustomSerialOverTcp" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   { | ||||
|     "Title": "LQTCP", | ||||
|     "Children": [ | ||||
|       { | ||||
|         "Href": "/LQTCP", | ||||
|         "Title": "LQTCP" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   { | ||||
|     "Title": "KELID2008", | ||||
|     "Children": [ | ||||
|       { | ||||
|         "Href": "/KELID2008", | ||||
|         "Title": "KELID2008" | ||||
|       }, | ||||
|       { | ||||
|         "Href": "/KELID2008OverTcp", | ||||
|         "Title": "KELID2008OverTcp" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   } | ||||
| 
 | ||||
| ] | ||||
| 
 | ||||
| 
 | ||||
| """;
 | ||||
|         Navs.AddRange(dataStringPro.FromJsonString<List<NavItem>>()); | ||||
| #endif | ||||
|         _pageTabItems = _navs.PasePageTabItem(); | ||||
|         pageTabItems = Navs.PasePageTabItem(); | ||||
|         base.OnInitialized(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,152 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||||
|  | ||||
| 	<PropertyGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro'"> | ||||
| 		<DefineConstants>Pro</DefineConstants> | ||||
| 	</PropertyGroup> | ||||
| 	<ItemGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro'"> | ||||
|  | ||||
|  | ||||
|  | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Melsec\Page\QnA3E_BinaryDebugPage.razor.cs" Link="Pages\Melsec\QnA3E_BinaryDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Melsec\Page\QnA3E_BinaryDebugPage.razor" Link="Pages\Melsec\QnA3E_BinaryDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.Melsec\ThingsGateway.Foundation.Adapter.Melsec.csproj" /> | ||||
|  | ||||
| 		 | ||||
| 		 | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.AllenBradleyCip\Page\AllenBradleyCipTcpDebugPage.razor.cs" Link="Pages\ABCIP\AllenBradleyCipTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.AllenBradleyCip\Page\AllenBradleyCipTcpDebugPage.razor" Link="Pages\ABCIP\AllenBradleyCipTcpDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.AllenBradleyCip\ThingsGateway.Foundation.Adapter.AllenBradleyCip.csproj" /> | ||||
|  | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Omron\Page\OmronFinsTcpDebugPage.razor.cs" Link="Pages\OmronFins\OmronFinsTcpDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Omron\Page\OmronFinsUdpDebugPage.razor.cs" Link="Pages\OmronFins\OmronFinsUdpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Omron\Page\OmronFinsTcpDebugPage.razor" Link="Pages\OmronFins\OmronFinsTcpDebugPage.razor" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Omron\Page\OmronFinsUdpDebugPage.razor" Link="Pages\OmronFins\OmronFinsUdpDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.Omron\ThingsGateway.Foundation.Adapter.Omron.csproj" /> | ||||
|  | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Secs\Page\SecsHsmsTcpDebugPage.razor.cs" Link="Pages\Secs\SecsHsmsTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Secs\Page\SecsHsmsTcpDebugPage.razor" Link="Pages\Secs\SecsHsmsTcpDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.Secs\ThingsGateway.Foundation.Adapter.Secs.csproj" /> | ||||
|  | ||||
|  | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.TS550\Page\TS550DebugPage.razor.cs" Link="Pages\TS550\TS550DebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.TS550\Page\TS550DebugPage.razor" Link="Pages\TS550\TS550DebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.TS550\ThingsGateway.Foundation.Adapter.TS550.csproj" /> | ||||
|  | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Vigor\Page\VigorSerialDebugPage.razor.cs" Link="Pages\Vigor\VigorSerialDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\PluginPro\ThingsGateway.Plugin.Vigor\Page\VigorSerialOverTcpDebugPage.razor.cs" Link="Pages\Vigor\VigorSerialOverTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Vigor\Page\VigorSerialDebugPage.razor" Link="Pages\Vigor\VigorSerialDebugPage.razor" /> | ||||
| 		<Content Include="..\..\PluginPro\ThingsGateway.Plugin.Vigor\Page\VigorSerialOverTcpDebugPage.razor" Link="Pages\Vigor\VigorSerialOverTcpDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\FoundationPro\ThingsGateway.Foundation.Adapter.Vigor\ThingsGateway.Foundation.Adapter.Vigor.csproj" /> | ||||
|  | ||||
|  | ||||
| 		<Compile Include="..\..\PluginProAF2021\ThingsGateway.Plugin.HZW_QTJC_01\Page\HZW_QTJC_01SerialDebugPage.razor.cs" Link="Pages\HZW_QTJC_01\HZW_QTJC_01SerialDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\PluginProAF2021\ThingsGateway.Plugin.HZW_QTJC_01\Page\HZW_QTJC_01SerialOverTcpDebugPage.razor.cs" Link="Pages\HZW_QTJC_01\HZW_QTJC_01SerialOverTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\PluginProAF2021\ThingsGateway.Plugin.HZW_QTJC_01\Page\HZW_QTJC_01SerialDebugPage.razor" Link="Pages\HZW_QTJC_01\HZW_QTJC_01SerialDebugPage.razor" /> | ||||
| 		<Content Include="..\..\PluginProAF2021\ThingsGateway.Plugin.HZW_QTJC_01\Page\HZW_QTJC_01SerialOverTcpDebugPage.razor" Link="Pages\HZW_QTJC_01\HZW_QTJC_01SerialOverTcpDebugPage.razor" /> | ||||
| 		<ProjectReference Include="..\..\PluginProAF2021\ThingsGateway.Foundation.Adapter.HZW_QTJC_01\ThingsGateway.Foundation.Adapter.HZW_QTJC_01.csproj" /> | ||||
|  | ||||
|  | ||||
| 		 | ||||
| 	</ItemGroup> | ||||
|  | ||||
|  | ||||
|  | ||||
| 	<ItemGroup> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007DebugPage.razor.cs" Link="Pages\DLT645\DLT645_2007DebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\MqttRpcNameVaueWithId.cs" Link="Pages\Mqtt\MqttRpcNameVaueWithId.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientDebugPage.razor.cs" Link="Pages\Mqtt\MqttClientDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientPage.razor.cs" Link="Pages\Mqtt\MqttClientPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\PrivateLogger.cs" Link="Pages\Mqtt\PrivateLogger.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcClient.cs" Link="Pages\Mqtt\MqttRpcClient.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcClientExtensions.cs" Link="Pages\Mqtt\MqttRpcClientExtensions.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcTopicPair.cs" Link="Pages\Mqtt\MqttRpcTopicPair.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007DebugPage.razor" Link="Pages\DLT645\DLT645_2007DebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007OverTcpDebugPage.razor.cs" Link="Pages\DLT645\DLT645_2007OverTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007OverTcpDebugPage.razor" Link="Pages\DLT645\DLT645_2007OverTcpDebugPage.razor" /> | ||||
|  | ||||
| 		 | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuDebugPage.razor.cs" Link="Pages\Modbus\ModbusRtuDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuDebugPage.razor" Link="Pages\Modbus\ModbusRtuDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuOverTcpDebugPage.razor.cs" Link="Pages\Modbus\ModbusRtuOverTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuOverTcpDebugPage.razor" Link="Pages\Modbus\ModbusRtuOverTcpDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuOverUdpDebugPage.razor.cs" Link="Pages\Modbus\ModbusRtuOverUdpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusRtuOverUdpDebugPage.razor" Link="Pages\Modbus\ModbusRtuOverUdpDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusSerialServerDebugPage.razor.cs" Link="Pages\Modbus\ModbusSerialServerDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusSerialServerDebugPage.razor" Link="Pages\Modbus\ModbusSerialServerDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpDebugPage.razor.cs" Link="Pages\Modbus\ModbusTcpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpDebugPage.razor" Link="Pages\Modbus\ModbusTcpDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpDtuDebugPage.razor.cs" Link="Pages\Modbus\ModbusTcpDtuDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpDtuDebugPage.razor" Link="Pages\Modbus\ModbusTcpDtuDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpServerDebugPage.razor.cs" Link="Pages\Modbus\ModbusTcpServerDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusTcpServerDebugPage.razor" Link="Pages\Modbus\ModbusTcpServerDebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusUdpDebugPage.razor.cs" Link="Pages\Modbus\ModbusUdpDebugPage.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Modbus\Page\ModbusUdpDebugPage.razor" Link="Pages\Modbus\ModbusUdpDebugPage.razor" /> | ||||
|  | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAClientDebugPage.razor.cs" Link="Pages\OPCDA\OPCDAClientDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAClientPage.razor.cs" Link="Pages\OPCDA\OPCDAClientPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAImportVariable.razor.cs" Link="Pages\OPCDA\OPCDAImportVariable.razor.cs" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAClientDebugPage.razor" Link="Pages\OPCDA\OPCDAClientDebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAClientPage.razor" Link="Pages\OPCDA\OPCDAClientPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCDA\Page\OPCDAImportVariable.razor" Link="Pages\OPCDA\OPCDAImportVariable.razor" /> | ||||
|  | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAClientDebugPage.razor" Link="Pages\OPCUA\OPCUAClientDebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAClientPage.razor" Link="Pages\OPCUA\OPCUAClientPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAImportVariable.razor" Link="Pages\OPCUA\OPCUAImportVariable.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAClientDebugPage.razor.cs" Link="Pages\OPCUA\OPCUAClientDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAClientPage.razor.cs" Link="Pages\OPCUA\OPCUAClientPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.OPCUA\Page\OPCUAImportVariable.razor.cs" Link="Pages\OPCUA\OPCUAImportVariable.razor.cs" /> | ||||
|  | ||||
|  | ||||
|  | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_1200DebugPage.razor" Link="Pages\Siemens\S7_1200DebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_1500DebugPage.razor" Link="Pages\Siemens\S7_1500DebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_200DebugPage.razor" Link="Pages\Siemens\S7_200DebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_200SMARTDebugPage.razor" Link="Pages\Siemens\S7_200SMARTDebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_300DebugPage.razor" Link="Pages\Siemens\S7_300DebugPage.razor" /> | ||||
| 		<Content Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_400DebugPage.razor" Link="Pages\Siemens\S7_400DebugPage.razor" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_1200DebugPage.razor.cs" Link="Pages\Siemens\S7_1200DebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_1500DebugPage.razor.cs" Link="Pages\Siemens\S7_1500DebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_200DebugPage.razor.cs" Link="Pages\Siemens\S7_200DebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_200SMARTDebugPage.razor.cs" Link="Pages\Siemens\S7_200SMARTDebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_300DebugPage.razor.cs" Link="Pages\Siemens\S7_300DebugPage.razor.cs" /> | ||||
| 		<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Siemens\Page\S7_400DebugPage.razor.cs" Link="Pages\Siemens\S7_400DebugPage.razor.cs" /> | ||||
|  | ||||
|  | ||||
| 	</ItemGroup> | ||||
|  | ||||
|  | ||||
| 	<ItemGroup > | ||||
| 		<PackageReference Include="ThingsGateway.Foundation.Adapter.DLT645" Version="*" /> | ||||
| 		<PackageReference Include="ThingsGateway.Foundation.Adapter.Modbus" Version="*" /> | ||||
| 		<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCDA" Version="*" /> | ||||
| 		<PackageReference Include="ThingsGateway.Foundation.Adapter.OPCUA" Version="*" /> | ||||
| 		<PackageReference Include="ThingsGateway.Foundation.Adapter.Siemens" Version="*" /> | ||||
| 		<!--<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.DLT645\ThingsGateway.Foundation.Adapter.DLT645.csproj" /> | ||||
| 		<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Modbus\ThingsGateway.Foundation.Adapter.Modbus.csproj" /> | ||||
| 		<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCDA\ThingsGateway.Foundation.Adapter.OPCDA.csproj" /> | ||||
| 		<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.OPCUA\ThingsGateway.Foundation.Adapter.OPCUA.csproj" /> | ||||
| 		<ProjectReference Include="..\..\Foundation\ThingsGateway.Foundation.Adapter.Siemens\ThingsGateway.Foundation.Adapter.Siemens.csproj" />--> | ||||
|  | ||||
| 	</ItemGroup> | ||||
| 	<ItemGroup > | ||||
| 		<ProjectReference Include="..\..\Web\ThingsGateway.Components\ThingsGateway.Components.csproj" /> | ||||
| 	</ItemGroup> | ||||
|  | ||||
|  | ||||
| 	<ItemGroup> | ||||
| 		<Content Update="wwwroot\**"> | ||||
| 			<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||||
| 		</Content> | ||||
| 	</ItemGroup> | ||||
|  | ||||
|  | ||||
|  | ||||
| 	<ItemGroup> | ||||
| 	  <Content Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientDebugPage.razor" Link="Pages\Mqtt\MqttClientDebugPage.razor" /> | ||||
| 	  <Content Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientPage.razor" Link="Pages\Mqtt\MqttClientPage.razor" /> | ||||
| 		<PackageReference Include="MQTTnet" Version="4.3.1.873" /> | ||||
| 	</ItemGroup> | ||||
|  | ||||
|  | ||||
|  | ||||
| </Project> | ||||
| Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB | 
| Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB | 
| @@ -1,14 +1,16 @@ | ||||
| <Project> | ||||
| 	<Import Project="$(SolutionDir)\Directory.Build.props" /> | ||||
| 	<!--如果编译net45报错无支持,用一下方法添加net45包--> | ||||
| 	<!--VS顶部菜单栏 -> 视图 -> 其他 -> 程序包控制台 | ||||
| 	Install-Package Microsoft.NETFramework.ReferenceAssemblies.net45 | ||||
| 	--> | ||||
| 	<PropertyGroup> | ||||
| 		<TargetFrameworks>net45;netstandard2.0;net6.0;net8.0;</TargetFrameworks> | ||||
| 		<Version>3.0.0.16</Version> | ||||
| 		<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||||
| 		<LangVersion>latest</LangVersion> | ||||
| 		<TargetFrameworks>net45;netstandard2.0;net6.0;net7.0</TargetFrameworks> | ||||
| 		<Description> | ||||
| 			ThingsGateway.Foundation是工业设备通讯类库,归属于ThingsGateway边缘网关项目,说明文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| 		</Description> | ||||
| 		<Authors>Diego</Authors> | ||||
| 		<Product>ThingsGateway</Product> | ||||
| 		<Copyright>© 2023-present Diego</Copyright> | ||||
| 		<RepositoryUrl>https://gitee.com/diego2098/ThingsGateway</RepositoryUrl> | ||||
| 		<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||||
| 		<EmbedUntrackedSource>true</EmbedUntrackedSource> | ||||
| 		<EmbedAllSources>true</EmbedAllSources> | ||||
| @@ -20,11 +22,17 @@ | ||||
| 		<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||||
| 		<PackageProjectUrl>https://diego2098.gitee.io/thingsgateway-docs/</PackageProjectUrl> | ||||
| 		<PackageTags>ThingsGateway;Diego;dotNET China;Blazor;设备采集;边缘网关</PackageTags> | ||||
| 		<PackageOutputPath>..\..\nupkgs</PackageOutputPath> | ||||
| 		<AssemblyOriginatorKeyFile>..\..\..\snks/ThingsGateway.snk</AssemblyOriginatorKeyFile> | ||||
| 		<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||||
| 		<SignAssembly>True</SignAssembly> | ||||
| 		<DelaySign>False</DelaySign> | ||||
| 		<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages> | ||||
| 		<PackageOutputPath>../../nupkgs</PackageOutputPath> | ||||
| 		<AssemblyOriginatorKeyFile>../../../snks/ThingsGateway.snk</AssemblyOriginatorKeyFile> | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| 	<PropertyGroup> | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
| 		<None Include="..\..\..\README.md" Pack="true" PackagePath="\" /> | ||||
| 	</ItemGroup> | ||||
| @@ -15,7 +15,7 @@ namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// 控制码 | ||||
| /// </summary> | ||||
| internal enum ControlCode : byte | ||||
| public enum ControlCode : byte | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 读数据 | ||||
| @@ -18,7 +18,7 @@ namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// 解析参数 | ||||
| /// </summary> | ||||
| internal class DataInfo | ||||
| public class DataInfo | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 解析长度 | ||||
| @@ -35,7 +35,12 @@ internal class DataInfo | ||||
| } | ||||
| internal static class DLT645Helper | ||||
| { | ||||
| 
 | ||||
|     internal static byte[] BytesAdd(this byte[] bytes, int value) | ||||
|     { | ||||
|         for (int index = 0; index < bytes.Length; ++index) | ||||
|             bytes[index] = (byte)(bytes[index] + value); | ||||
|         return bytes; | ||||
|     } | ||||
| 
 | ||||
|     internal static string Get2007ErrorMessage(byte buffer) | ||||
|     { | ||||
| @@ -0,0 +1,480 @@ | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //------------------------------------------------------------------------------ | ||||
| #endregion | ||||
|  | ||||
| using System.ComponentModel; | ||||
|  | ||||
| using ThingsGateway.Foundation.Extension.Generic; | ||||
|  | ||||
| namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// DLT645_2007 | ||||
| /// </summary> | ||||
| public class DLT645_2007 : ReadWriteDevicesSerialSessionBase | ||||
| { | ||||
|     /// <summary> | ||||
|     /// DLT645_2007 | ||||
|     /// </summary> | ||||
|     /// <param name="serialSession"></param> | ||||
|     public DLT645_2007(SerialSession serialSession) : base(serialSession) | ||||
|     { | ||||
|         ThingsGatewayBitConverter = new DLT645_2007BitConverter(EndianType.Big); | ||||
|         RegisterByteLength = 2; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 增加FE FE FE FE的报文头部 | ||||
|     /// </summary> | ||||
|     [Description("前导符报文头")] | ||||
|     public bool EnableFEHead { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 写入需操作员代码 | ||||
|     /// </summary> | ||||
|     [Description("操作员代码")] | ||||
|     public string OperCode { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 写入密码 | ||||
|     /// </summary> | ||||
|     [Description("写入密码")] | ||||
|     public string Password { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 通讯地址BCD码,一般应该是12个字符 | ||||
|     /// </summary> | ||||
|     [Description("通讯地址")] | ||||
|     public string Station { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|  | ||||
|         var str = """ | ||||
|             查看附带文档或者相关资料,下面列举一下常见的数据标识地址  | ||||
|              | ||||
|             地址                       说明                     | ||||
|             ----------------------------------------- | ||||
|             02010100    A相电压 | ||||
|             02020100    A相电流 | ||||
|             02030000    瞬时总有功功率 | ||||
|             00000000    (当前)组合有功总电能 | ||||
|             00010000    (当前)正向有功总电能 | ||||
|              | ||||
|             """; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + str; | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Read, Station); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = WaitingClientEx.SendThenResponse(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Read, Station); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         var dataHandleAdapter = new DLT645_2007DataHandleAdapter | ||||
|         { | ||||
|             EnableFEHead = EnableFEHead | ||||
|         }; | ||||
|         SerialSession.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, string value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|  | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             Password ??= string.Empty; | ||||
|             OperCode ??= string.Empty; | ||||
|             if (Password.Length < 8) | ||||
|                 Password = Password.PadLeft(8, '0'); | ||||
|             if (OperCode.Length < 8) | ||||
|                 OperCode = OperCode.PadLeft(8, '0'); | ||||
|             var data = DataTransUtil.SpliceArray(Password.ByHexStringToBytes(), OperCode.ByHexStringToBytes()); | ||||
|             string[] strArray = value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Write, Station, data, strArray); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = WaitingClientEx.SendThenResponse(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, byte[] value, CancellationToken cancellationToken = default) => Write(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, bool[] value, CancellationToken cancellationToken = default) => Write(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override async Task<OperResult> WriteAsync(string address, string value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|  | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             Password ??= string.Empty; | ||||
|             OperCode ??= string.Empty; | ||||
|             if (Password.Length < 8) | ||||
|                 Password = Password.PadLeft(8, '0'); | ||||
|             if (OperCode.Length < 8) | ||||
|                 OperCode = OperCode.PadLeft(8, '0'); | ||||
|             var data = DataTransUtil.SpliceArray(Password.ByHexStringToBytes(), OperCode.ByHexStringToBytes()); | ||||
|             string[] strArray = value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Write, Station, data, strArray); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, byte[] value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, uint value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, double value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, float value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, long value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, ulong value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, ushort value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, short value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, int value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, bool[] value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|  | ||||
|     #region 其他方法 | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 广播校时 | ||||
|     /// </summary> | ||||
|     /// <param name="dateTime"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public OperResult BroadcastTime(DateTime dateTime, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             string str = $"{dateTime.Second:D2}{dateTime.Minute:D2}{dateTime.Hour:D2}{dateTime.Day:D2}{dateTime.Month:D2}{dateTime.Year % 100:D2}"; | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.BroadcastTime, str.ByHexStringToBytes().ToArray(), "999999999999".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 SerialSession.Send(commandResult.Content); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 冻结 | ||||
|     /// </summary> | ||||
|     /// <param name="dateTime"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> FreezeAsync(DateTime dateTime, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             string str = $"{dateTime.Minute:D2}{dateTime.Hour:D2}{dateTime.Day:D2}{dateTime.Month:D2}"; | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.Freeze, str.ByHexStringToBytes().ToArray(), Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|  | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 读取通信地址 | ||||
|     /// </summary> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult<string>> ReadDeviceStationAsync(CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.ReadStation, null, "AAAAAAAAAAAA".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     var buffer = result1.Content.SelectMiddle(0, 6).BytesAdd(-0x33); | ||||
|                     return OperResult.CreateSuccessResult(buffer.Reverse().ToArray().ToHexString()); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult<string>(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<string>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 修改波特率 | ||||
|     /// </summary> | ||||
|     /// <param name="baudRate"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WriteBaudRateAsync(int baudRate, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             byte baudRateByte; | ||||
|             switch (baudRate) | ||||
|             { | ||||
|                 case 600: baudRateByte = 0x02; break; | ||||
|                 case 1200: baudRateByte = 0x04; break; | ||||
|                 case 2400: baudRateByte = 0x08; break; | ||||
|                 case 4800: baudRateByte = 0x10; break; | ||||
|                 case 9600: baudRateByte = 0x20; break; | ||||
|                 case 19200: baudRateByte = 0x40; break; | ||||
|                 default: return new OperResult<string>($"不支持此波特率:{baudRate}"); | ||||
|             } | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WriteBaudRate, new byte[] { baudRateByte }, Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 更新通信地址 | ||||
|     /// </summary> | ||||
|     /// <param name="station"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WriteDeviceStationAsync(string station, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WriteStation, station.ByHexStringToBytes().Reverse().ToArray(), "AAAAAAAAAAAA".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|  | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// 修改密码 | ||||
|     /// </summary> | ||||
|     /// <param name="level"></param> | ||||
|     /// <param name="oldPassword"></param> | ||||
|     /// <param name="newPassword"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WritePasswordAsync(byte level, string oldPassword, string newPassword, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|  | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             string str = $"04000C{level + 1:D2}"; | ||||
|  | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WritePassword, | ||||
|                 str.ByHexStringToBytes().Reverse().ToArray() | ||||
|                 .SpliceArray(oldPassword.ByHexStringToBytes().Reverse().ToArray()) | ||||
|                 .SpliceArray(newPassword.ByHexStringToBytes().Reverse().ToArray()) | ||||
|                 , Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     #endregion | ||||
|  | ||||
| } | ||||
| @@ -50,7 +50,7 @@ public class DLT645_2007Address : DeviceAddressBase | ||||
|     /// <returns></returns> | ||||
|     public static DLT645_2007Address ParseFrom(string address) | ||||
|     { | ||||
|         DLT645_2007Address dlt645_2007Address = new(); | ||||
|         DLT645_2007Address dLT645_2007Address = new(); | ||||
|         byte[] array; | ||||
|         array = new byte[0]; | ||||
|         if (address.IndexOf(';') < 0) | ||||
| @@ -59,7 +59,7 @@ public class DLT645_2007Address : DeviceAddressBase | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             string[] strArray = address.SplitStringBySemicolon(); | ||||
|             string[] strArray = address.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
| 
 | ||||
|             for (int index = 0; index < strArray.Length; ++index) | ||||
|             { | ||||
| @@ -69,11 +69,11 @@ public class DLT645_2007Address : DeviceAddressBase | ||||
|                     if (station.IsNullOrEmpty()) station = string.Empty; | ||||
|                     if (station.Length < 12) | ||||
|                         station = station.PadLeft(12, '0'); | ||||
|                     dlt645_2007Address.Station = station.ByHexStringToBytes().Reverse().ToArray(); | ||||
|                     dLT645_2007Address.Station = station.ByHexStringToBytes().Reverse().ToArray(); | ||||
|                 } | ||||
|                 else if (strArray[index].Contains("r=")) | ||||
|                 { | ||||
|                     dlt645_2007Address.Reverse = strArray[index].Substring(2).ToBool(false); | ||||
|                     dLT645_2007Address.Reverse = strArray[index].Substring(2).GetBoolValue(); | ||||
|                 } | ||||
|                 else if (!strArray[index].Contains("=")) | ||||
|                 { | ||||
| @@ -81,8 +81,8 @@ public class DLT645_2007Address : DeviceAddressBase | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         dlt645_2007Address.DataId = array; | ||||
|         return dlt645_2007Address; | ||||
|         dLT645_2007Address.DataId = array; | ||||
|         return dLT645_2007Address; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| @@ -100,7 +100,7 @@ public class DLT645_2007Address : DeviceAddressBase | ||||
|         } | ||||
|         if (!Reverse) | ||||
|         { | ||||
|             stringGeter.Append($"s={Reverse};"); | ||||
|             stringGeter.Append($"s={Reverse.ToString()};"); | ||||
|         } | ||||
|         return stringGeter.ToString(); | ||||
|     } | ||||
| @@ -26,41 +26,7 @@ public class DLT645_2007BitConverter : ThingsGatewayBitConverter | ||||
|     public DLT645_2007BitConverter(EndianType endianType) : base(endianType) | ||||
|     { | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override short ToInt16(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToInt16(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override ushort ToUInt16(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToUInt16(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override float ToSingle(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToSingle(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override long ToInt64(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToInt64(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override int ToInt32(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToInt32(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override uint ToUInt32(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToUInt32(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override ulong ToUInt64(byte[] buffer, int offset) | ||||
|     { | ||||
|         return Convert.ToUInt64(this.ToString(buffer, offset, buffer.Length)); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// DLT645协议转换double | ||||
|     /// </summary> | ||||
| @@ -19,7 +19,7 @@ namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// DLT645_2007DataHandleAdapter | ||||
| /// </summary> | ||||
| internal class DLT645_2007DataHandleAdapter : ReadWriteDevicesSingleStreamDataHandleAdapter<DLT645_2007Message> | ||||
| public class DLT645_2007DataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<DLT645_2007Message> | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 增加FE FE FE FE的报文头部 | ||||
| @@ -14,7 +14,7 @@ namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class DLT645_2007Message : MessageBase, IMessage | ||||
| public class DLT645_2007Message : MessageBase, IMessage | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public override int HeadBytesLength => -1; | ||||
| @@ -0,0 +1,480 @@ | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //------------------------------------------------------------------------------ | ||||
| #endregion | ||||
|  | ||||
| using System.ComponentModel; | ||||
|  | ||||
| using ThingsGateway.Foundation.Extension.Generic; | ||||
|  | ||||
| namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| /// <summary> | ||||
| /// DLT645_2007 | ||||
| /// </summary> | ||||
| public class DLT645_2007OverTcp : ReadWriteDevicesTcpClientBase | ||||
| { | ||||
|     /// <summary> | ||||
|     /// DLT645_2007 | ||||
|     /// </summary> | ||||
|     /// <param name="tcpClient"></param> | ||||
|     public DLT645_2007OverTcp(TcpClient tcpClient) : base(tcpClient) | ||||
|     { | ||||
|         ThingsGatewayBitConverter = new DLT645_2007BitConverter(EndianType.Big); | ||||
|         RegisterByteLength = 2; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 增加FE FE FE FE的报文头部 | ||||
|     /// </summary> | ||||
|     [Description("前导符报文头")] | ||||
|     public bool EnableFEHead { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 写入需操作员代码 | ||||
|     /// </summary> | ||||
|     [Description("操作员代码")] | ||||
|     public string OperCode { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 写入密码 | ||||
|     /// </summary> | ||||
|     [Description("写入密码")] | ||||
|     public string Password { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 通讯地址BCD码,一般应该是12个字符 | ||||
|     /// </summary> | ||||
|     [Description("通讯地址")] | ||||
|     public string Station { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|  | ||||
|         var str = """ | ||||
|             查看附带文档或者相关资料,下面列举一下常见的数据标识地址  | ||||
|              | ||||
|             地址                       说明                     | ||||
|             ----------------------------------------- | ||||
|             02010100    A相电压 | ||||
|             02020100    A相电流 | ||||
|             02030000    瞬时总有功功率 | ||||
|             00000000    (当前)组合有功总电能 | ||||
|             00010000    (当前)正向有功总电能 | ||||
|              | ||||
|             """; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + str; | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Read, Station); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = WaitingClientEx.SendThenResponse(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Read, Station); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         var dataHandleAdapter = new DLT645_2007DataHandleAdapter | ||||
|         { | ||||
|             EnableFEHead = EnableFEHead | ||||
|         }; | ||||
|         TcpClient.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, string value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|  | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             Password ??= string.Empty; | ||||
|             OperCode ??= string.Empty; | ||||
|             if (Password.Length < 8) | ||||
|                 Password = Password.PadLeft(8, '0'); | ||||
|             if (OperCode.Length < 8) | ||||
|                 OperCode = OperCode.PadLeft(8, '0'); | ||||
|             var data = DataTransUtil.SpliceArray(Password.ByHexStringToBytes(), OperCode.ByHexStringToBytes()); | ||||
|             string[] strArray = value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Write, Station, data, strArray); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = WaitingClientEx.SendThenResponse(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, byte[] value, CancellationToken cancellationToken = default) => Write(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, bool[] value, CancellationToken cancellationToken = default) => Write(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override async Task<OperResult> WriteAsync(string address, string value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|  | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             Password ??= string.Empty; | ||||
|             OperCode ??= string.Empty; | ||||
|             if (Password.Length < 8) | ||||
|                 Password = Password.PadLeft(8, '0'); | ||||
|             if (OperCode.Length < 8) | ||||
|                 OperCode = OperCode.PadLeft(8, '0'); | ||||
|             var data = DataTransUtil.SpliceArray(Password.ByHexStringToBytes(), OperCode.ByHexStringToBytes()); | ||||
|             string[] strArray = value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command(address, (byte)ControlCode.Write, Station, data, strArray); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, byte[] value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, uint value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, double value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, float value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, long value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, ulong value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, ushort value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, short value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, int value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, bool[] value, CancellationToken cancellationToken = default) => WriteAsync(address, value.ToString(), cancellationToken); | ||||
|  | ||||
|  | ||||
|     #region 其他方法 | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 广播校时 | ||||
|     /// </summary> | ||||
|     /// <param name="dateTime"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public OperResult BroadcastTime(DateTime dateTime, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             string str = $"{dateTime.Second:D2}{dateTime.Minute:D2}{dateTime.Hour:D2}{dateTime.Day:D2}{dateTime.Month:D2}{dateTime.Year % 100:D2}"; | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.BroadcastTime, str.ByHexStringToBytes().Reverse().ToArray(), "999999999999".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 TcpClient.Send(commandResult.Content); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 冻结 | ||||
|     /// </summary> | ||||
|     /// <param name="dateTime"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> FreezeAsync(DateTime dateTime, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             string str = $"{dateTime.Minute:D2}{dateTime.Hour:D2}{dateTime.Day:D2}{dateTime.Month:D2}"; | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.Freeze, str.ByHexStringToBytes().Reverse().ToArray(), Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|  | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 读取通信地址 | ||||
|     /// </summary> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult<string>> ReadDeviceStationAsync(CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.ReadStation, null, "AAAAAAAAAAAA".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     var buffer = result1.Content.SelectMiddle(0, 6).BytesAdd(-0x33); | ||||
|                     return OperResult.CreateSuccessResult(buffer.Reverse().ToArray().ToHexString()); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult<string>(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<string>(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 修改波特率 | ||||
|     /// </summary> | ||||
|     /// <param name="baudRate"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WriteBaudRateAsync(int baudRate, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             byte baudRateByte; | ||||
|             switch (baudRate) | ||||
|             { | ||||
|                 case 600: baudRateByte = 0x02; break; | ||||
|                 case 1200: baudRateByte = 0x04; break; | ||||
|                 case 2400: baudRateByte = 0x08; break; | ||||
|                 case 4800: baudRateByte = 0x10; break; | ||||
|                 case 9600: baudRateByte = 0x20; break; | ||||
|                 case 19200: baudRateByte = 0x40; break; | ||||
|                 default: return new OperResult<string>($"不支持此波特率:{baudRate}"); | ||||
|             } | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WriteBaudRate, new byte[] { baudRateByte }, Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 更新通信地址 | ||||
|     /// </summary> | ||||
|     /// <param name="station"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WriteDeviceStationAsync(string station, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WriteStation, station.ByHexStringToBytes().Reverse().ToArray(), "AAAAAAAAAAAA".ByHexStringToBytes()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|  | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     /// <summary> | ||||
|     /// 修改密码 | ||||
|     /// </summary> | ||||
|     /// <param name="level"></param> | ||||
|     /// <param name="oldPassword"></param> | ||||
|     /// <param name="newPassword"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<OperResult> WritePasswordAsync(byte level, string oldPassword, string newPassword, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|  | ||||
|             if (Station.IsNullOrEmpty()) Station = string.Empty; | ||||
|             if (Station.Length < 12) Station = Station.PadLeft(12, '0'); | ||||
|             string str = $"04000C{level:D2}"; | ||||
|  | ||||
|             var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.WritePassword, | ||||
|                 str.ByHexStringToBytes().Reverse().ToArray() | ||||
|                 .SpliceArray(oldPassword.ByHexStringToBytes().Reverse().ToArray()) | ||||
|                 .SpliceArray(newPassword.ByHexStringToBytes().Reverse().ToArray()) | ||||
|                 , Station.ByHexStringToBytes().Reverse().ToArray()); | ||||
|             if (commandResult.IsSuccess) | ||||
|             { | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(commandResult.Content, TimeOut, cancellationToken); | ||||
|                 var result1 = ((MessageBase)result.RequestInfo); | ||||
|                 if (result1.IsSuccess) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new OperResult(result1); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult(commandResult); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<string>(ex); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|     #endregion | ||||
|  | ||||
| } | ||||
| @@ -14,34 +14,25 @@ namespace ThingsGateway.Foundation.Adapter.DLT645; | ||||
| 
 | ||||
| internal static class PackHelper | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 打包变量,添加到<see href="deviceVariableSourceReads"></see> | ||||
|     /// </summary> | ||||
|     /// <param name="device"></param> | ||||
|     /// <param name="deviceVariables"></param> | ||||
|     /// <param name="maxPack">最大打包长度</param> | ||||
|     /// <param name="defaultIntervalTime">默认间隔时间</param> | ||||
|     /// <returns></returns> | ||||
|     public static List<T> LoadSourceRead<T, T2>(IReadWrite device, List<T2> deviceVariables, int maxPack, int defaultIntervalTime) where T : IDeviceVariableSourceRead<IDeviceVariableRunTime>, new() where T2 : IDeviceVariableRunTime, new() | ||||
|     public static List<T> LoadSourceRead<T, T2>(IReadWrite device, List<T2> deviceVariables, int maxPack) where T : IDeviceVariableSourceRead<IDeviceVariableRunTime>, new() where T2 : IDeviceVariableRunTime, new() | ||||
|     { | ||||
|         var byteConverter = device.ThingsGatewayBitConverter; | ||||
|         var result = new List<T>(); | ||||
|         //需要先剔除额外信息,比如dataformat等 | ||||
|         foreach (var item in deviceVariables) | ||||
|         { | ||||
|             var address = item.Address; | ||||
|             var address = item.VariableAddress; | ||||
| 
 | ||||
|             IThingsGatewayBitConverter transformParameter = ByteTransformUtil.GetTransByAddress(ref address, byteConverter); | ||||
|             item.ThingsGatewayBitConverter = transformParameter; | ||||
|             //item.Address = address; | ||||
|             item.Index = device.GetBitOffset(item.Address); | ||||
|             //item.VariableAddress = address; | ||||
|             item.Index = device.GetBitOffset(item.VariableAddress); | ||||
| 
 | ||||
|             result.Add(new() | ||||
|             { | ||||
|                 DeviceVariableRunTimes = new() { item }, | ||||
|                 Address = address, | ||||
|                 VariableAddress = address, | ||||
|                 Length = 1, | ||||
|                 IntervalTimeTick = new(item.IntervalTime ?? defaultIntervalTime) | ||||
|             }); | ||||
|         } | ||||
|         return result; | ||||
| @@ -12,6 +12,7 @@ | ||||
| 
 | ||||
| using System.Text; | ||||
| 
 | ||||
| using ThingsGateway.Foundation.Extension; | ||||
| using ThingsGateway.Foundation.Extension.String; | ||||
| 
 | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| @@ -53,7 +54,7 @@ public class ModbusAddress : DeviceAddressBase | ||||
|     /// <summary> | ||||
|     /// BitIndex | ||||
|     /// </summary> | ||||
|     public int BitIndex => (int)(Address.SplitStringByDelimiter().LastOrDefault().ToInt()); | ||||
|     public int BitIndex => (int)(Address.SplitDot().LastOrDefault().ToInt()); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 读取功能码 | ||||
| @@ -87,7 +88,7 @@ public class ModbusAddress : DeviceAddressBase | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             string[] strArray = address.SplitStringBySemicolon(); | ||||
|             string[] strArray = address.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | ||||
|             for (int index = 0; index < strArray.Length; ++index) | ||||
|             { | ||||
|                 if (strArray[index].ToUpper().StartsWith("S=")) | ||||
| @@ -24,7 +24,7 @@ internal class ModbusHelper | ||||
|     /// </summary> | ||||
|     internal static byte[] AddCrc(byte[] command) | ||||
|     { | ||||
|         return CRC16Utils.CRC16(command); | ||||
|         return EasyCRC16.CRC16(command); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -134,20 +134,22 @@ internal class ModbusHelper | ||||
| 
 | ||||
|         if (response[1] >= 0x80)//错误码 | ||||
|             return new OperResult<byte[], FilterResult>(GetDescriptionByErrorCode(response[2])) { Content2 = FilterResult.Success }; | ||||
|         if (response[1] <= 0x04) | ||||
|         if (response[1] <= 0x05) | ||||
|         { | ||||
|             if ((response.Length < response[2] + 5)) | ||||
|                 return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache }; | ||||
| 
 | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if ((response.Length < 8)) | ||||
|                 return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache }; | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         var data = response.SelectMiddle(0, response[1] <= 0x04 ? response[2] != 0 ? response[2] + 5 : 8 : 8); | ||||
|         if (crcCheck && !CRC16Utils.CheckCRC16(data)) | ||||
|         var data = response.SelectMiddle(0, response[2] != 0 ? response[2] + 5 : 8); | ||||
|         if (crcCheck && !EasyCRC16.CheckCRC16(data)) | ||||
|             return new OperResult<byte[], FilterResult>("Crc校验失败" + DataTransUtil.ByteToHexString(data, ' ')) { Content2 = FilterResult.Success }; | ||||
|         return GetModbusData(send, data.RemoveLast(2)); | ||||
|     } | ||||
| @@ -18,6 +18,7 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// </summary> | ||||
| public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
| { | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// ModbusRtu | ||||
|     /// </summary> | ||||
| @@ -44,24 +45,26 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
| 
 | ||||
|             return ModbusHelper.GetReadModbusCommand(address, length, Station).Then(a => SendThenReturn<ModbusRtuMessage>(a, cancellationToken)); | ||||
| 
 | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -76,8 +79,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -86,7 +88,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         ModbusRtuDataHandleAdapter dataHandleAdapter = new() | ||||
|         { | ||||
| @@ -103,8 +105,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -119,8 +120,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -135,8 +135,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -151,8 +150,7 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -160,5 +158,34 @@ public class ModbusRtu : ReadWriteDevicesSerialSessionBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             if (FrameTime != 0) | ||||
|                 Thread.Sleep(FrameTime); | ||||
|             var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             await Task.Delay(FrameTime, cancellationToken); | ||||
|             var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -17,7 +17,7 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// Rtu适配器 | ||||
| /// </summary> | ||||
| internal class ModbusRtuDataHandleAdapter : ReadWriteDevicesSingleStreamDataHandleAdapter<ModbusRtuMessage> | ||||
| public class ModbusRtuDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<ModbusRtuMessage> | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 检测CRC | ||||
| @@ -14,7 +14,7 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class ModbusRtuMessage : MessageBase, IMessage | ||||
| public class ModbusRtuMessage : MessageBase, IMessage | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public override int HeadBytesLength => -1; | ||||
| @@ -40,7 +40,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| @@ -51,8 +51,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -67,8 +66,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -77,13 +75,14 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         ModbusRtuDataHandleAdapter dataHandleAdapter = new() | ||||
|         { | ||||
| @@ -100,8 +99,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -116,8 +114,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -132,8 +129,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -148,8 +144,7 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -157,4 +152,34 @@ public class ModbusRtuOverTcp : ReadWriteDevicesTcpClientBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             if (FrameTime != 0) | ||||
|                 Thread.Sleep(FrameTime); | ||||
|             var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             await Task.Delay(FrameTime, cancellationToken); | ||||
|             var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -38,7 +38,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
| @@ -47,8 +47,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -63,8 +62,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -73,7 +71,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         ModbusRtuOverUdpDataHandleAdapter dataHandleAdapter = new() | ||||
|         { | ||||
| @@ -87,9 +85,10 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -99,8 +98,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -115,8 +113,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -131,8 +128,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -147,8 +143,7 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusRtuMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -156,5 +151,34 @@ public class ModbusRtuOverUdp : ReadWriteDevicesUdpSessionBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             if (FrameTime != 0) | ||||
|                 Thread.Sleep(FrameTime); | ||||
|             var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             await Task.Delay(FrameTime, cancellationToken); | ||||
|             var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -15,7 +15,7 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class ModbusRtuOverUdpDataHandleAdapter : ReadWriteDevicesUdpDataHandleAdapter<ModbusRtuMessage> | ||||
| public class ModbusRtuOverUdpDataHandleAdapter : ReadWriteDevicesUdpDataHandleAdapter<ModbusRtuMessage> | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 检测CRC | ||||
| @@ -0,0 +1,421 @@ | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //------------------------------------------------------------------------------ | ||||
| #endregion | ||||
|  | ||||
| using System.Collections.Concurrent; | ||||
|  | ||||
| using ThingsGateway.Foundation.Extension.Bool; | ||||
| using ThingsGateway.Foundation.Extension.Generic; | ||||
|  | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| public class ModbusSerialServer : ReadWriteDevicesSerialSessionBase | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 接收外部写入时,传出变量地址/写入字节组/转换规则/客户端 | ||||
|     /// </summary> | ||||
|     public Func<ModbusAddress, byte[], IThingsGatewayBitConverter, SerialSession, Task<OperResult>> WriteData; | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 继电器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer01ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 开关输入 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer02ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 输入寄存器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer03ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 保持寄存器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer04ByteBlocks = new(); | ||||
|     /// <inheritdoc/> | ||||
|     public ModbusSerialServer(SerialSession serialSession) : base(serialSession) | ||||
|     { | ||||
|         ThingsGatewayBitConverter = new ThingsGatewayBitConverter(EndianType.Big); | ||||
|         RegisterByteLength = 2; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 多站点 | ||||
|     /// </summary> | ||||
|     public bool MulStation { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 默认站点 | ||||
|     /// </summary> | ||||
|     public byte Station { get; set; } = 1; | ||||
|  | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override void Dispose() | ||||
|     { | ||||
|         foreach (var item in ModbusServer01ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer02ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer03ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer04ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         ModbusServer01ByteBlocks.Clear(); | ||||
|         ModbusServer02ByteBlocks.Clear(); | ||||
|         ModbusServer03ByteBlocks.Clear(); | ||||
|         ModbusServer04ByteBlocks.Clear(); | ||||
|         base.Dispose(); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return new OperResult<byte[]>("地址错误"); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         var ModbusServer01ByteBlock = ModbusServer01ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer02ByteBlock = ModbusServer02ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer03ByteBlock = ModbusServer03ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer04ByteBlock = ModbusServer04ByteBlocks[mAddress.Station]; | ||||
|         int len = mAddress.ReadFunction == 2 || mAddress.ReadFunction == 1 ? length : length * RegisterByteLength; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 1: | ||||
|                 byte[] bytes0 = new byte[len]; | ||||
|                 ModbusServer01ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer01ByteBlock.Read(bytes0); | ||||
|                 return OperResult.CreateSuccessResult(bytes0); | ||||
|             case 2: | ||||
|                 byte[] bytes1 = new byte[len]; | ||||
|                 ModbusServer02ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer02ByteBlock.Read(bytes1); | ||||
|                 return OperResult.CreateSuccessResult(bytes1); | ||||
|             case 3: | ||||
|  | ||||
|                 byte[] bytes3 = new byte[len]; | ||||
|                 ModbusServer03ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer03ByteBlock.Read(bytes3); | ||||
|                 return OperResult.CreateSuccessResult(bytes3); | ||||
|             case 4: | ||||
|                 byte[] bytes4 = new byte[len]; | ||||
|                 ModbusServer04ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer04ByteBlock.Read(bytes4); | ||||
|                 return OperResult.CreateSuccessResult(bytes4); | ||||
|         } | ||||
|         return new OperResult<byte[]>("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Read(address, length)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(object socketClient) | ||||
|     { | ||||
|         ModbusSerialServerDataHandleAdapter dataHandleAdapter = new(); | ||||
|         dataHandleAdapter.CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout); | ||||
|         SerialSession.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, byte[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult(ex); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return new OperResult("地址错误"); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         var ModbusServer03ByteBlock = ModbusServer03ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer04ByteBlock = ModbusServer04ByteBlocks[mAddress.Station]; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 3: | ||||
|                 ModbusServer03ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer03ByteBlock.Write(value); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|             case 4: | ||||
|                 ModbusServer04ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer04ByteBlock.Write(value); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|         } | ||||
|         return new OperResult("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, bool[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return (new OperResult(ex)); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return (new OperResult("地址错误")); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         var ModbusServer01ByteBlock = ModbusServer01ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer02ByteBlock = ModbusServer02ByteBlocks[mAddress.Station]; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 1: | ||||
|                 ModbusServer01ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer01ByteBlock.Write(value.BoolArrayToByte()); | ||||
|                 return (OperResult.CreateSuccessResult()); | ||||
|             case 2: | ||||
|                 ModbusServer02ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer02ByteBlock.Write(value.BoolArrayToByte()); | ||||
|                 return (OperResult.CreateSuccessResult()); | ||||
|         } | ||||
|         return new OperResult("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, byte[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Write(address, value)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, bool[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Write(address, value)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     protected override async Task Received(SerialSession client, ReceivedDataEventArgs e) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             var requestInfo = e.RequestInfo; | ||||
|             //接收外部报文 | ||||
|             if (requestInfo is ModbusSerialServerMessage modbusServerMessage) | ||||
|             { | ||||
|                 if (modbusServerMessage.CurModbusAddress == null) | ||||
|                 { | ||||
|                     return;//无法解析直接返回 | ||||
|                 } | ||||
|                 if (!modbusServerMessage.IsSuccess) | ||||
|                 { | ||||
|                     return;//无法解析直接返回 | ||||
|                 } | ||||
|  | ||||
|                 if (modbusServerMessage.CurModbusAddress.WriteFunction == 0)//读取 | ||||
|                 { | ||||
|                     var data = Read(modbusServerMessage.CurModbusAddress.ToString(), modbusServerMessage.Length); | ||||
|                     if (data.IsSuccess) | ||||
|                     { | ||||
|                         var coreData = data.Content; | ||||
|                         if (modbusServerMessage.CurModbusAddress.ReadFunction == 1 || modbusServerMessage.CurModbusAddress.ReadFunction == 2) | ||||
|                         { | ||||
|                             coreData = data.Content.Select(m => m > 0).ToArray().BoolArrayToByte().SelectMiddle(0, (int)Math.Ceiling(modbusServerMessage.Length / 8.0)); | ||||
|                         } | ||||
|                         var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 2).SpliceArray(new byte[] { (byte)coreData.Length }, coreData); | ||||
|                         SerialSession.Send(sendData); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         WriteError(SerialSession, modbusServerMessage);//返回错误码 | ||||
|                     } | ||||
|                 } | ||||
|                 else//写入 | ||||
|                 { | ||||
|                     var coreData = modbusServerMessage.Content; | ||||
|                     if (modbusServerMessage.CurModbusAddress.ReadFunction == 1 || modbusServerMessage.CurModbusAddress.ReadFunction == 2) | ||||
|                     { | ||||
|                         //写入继电器 | ||||
|                         if (WriteData != null) | ||||
|                         { | ||||
|                             // 接收外部写入时,传出变量地址/写入字节组/转换规则/客户端 | ||||
|                             if ((await WriteData(modbusServerMessage.CurModbusAddress, modbusServerMessage.Content, ThingsGatewayBitConverter, SerialSession)).IsSuccess) | ||||
|                             { | ||||
|                                 var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData.ByteToBoolArray(modbusServerMessage.Length)); | ||||
|                                 if (result.IsSuccess) | ||||
|                                 { | ||||
|                                     WriteSuccess03(SerialSession, modbusServerMessage); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     WriteError(SerialSession, modbusServerMessage); | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(SerialSession, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             //写入内存区 | ||||
|                             var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData.ByteToBoolArray(modbusServerMessage.Length)); | ||||
|                             if (result.IsSuccess) | ||||
|                             { | ||||
|                                 WriteSuccess03(SerialSession, modbusServerMessage); | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(SerialSession, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         //写入寄存器 | ||||
|                         if (WriteData != null) | ||||
|                         { | ||||
|  | ||||
|                             if ((await WriteData(modbusServerMessage.CurModbusAddress, modbusServerMessage.Content, ThingsGatewayBitConverter, SerialSession)).IsSuccess) | ||||
|                             { | ||||
|                                 var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData); | ||||
|                                 if (result.IsSuccess) | ||||
|                                 { | ||||
|                                     WriteSuccess03(SerialSession, modbusServerMessage); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     WriteError(SerialSession, modbusServerMessage); | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(SerialSession, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData); | ||||
|                             if (result.IsSuccess) | ||||
|                             { | ||||
|                                 WriteSuccess03(SerialSession, modbusServerMessage); | ||||
|  | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(SerialSession, modbusServerMessage); | ||||
|  | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             Logger.LogError(ex, ToString()); | ||||
|         } | ||||
|         //返回错误码 | ||||
|         static void WriteError(SerialSession SerialSession, ModbusSerialServerMessage modbusServerMessage) | ||||
|         { | ||||
|             var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 2) | ||||
| .SpliceArray(new byte[] { (byte)1 });//01 lllegal function | ||||
|             sendData[1] = (byte)(sendData[1] + 128); | ||||
|             SerialSession.Send(sendData); | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void WriteSuccess03(SerialSession SerialSession, ModbusSerialServerMessage modbusServerMessage) | ||||
|     { | ||||
|         var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 6); | ||||
|         SerialSession.Send(sendData); | ||||
|     } | ||||
|  | ||||
|     private void Init(ModbusAddress mAddress) | ||||
|     { | ||||
|         if (ModbusServer01ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer01ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer02ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer02ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer03ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer03ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer04ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer04ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|     } | ||||
| } | ||||
| @@ -15,7 +15,7 @@ using ThingsGateway.Foundation.Extension.Generic; | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| 
 | ||||
| /// <inheritdoc/> | ||||
| internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStreamDataHandleAdapter<ModbusSerialServerMessage> | ||||
| public class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<ModbusSerialServerMessage> | ||||
| { | ||||
|     private readonly ThingsGatewayBitConverter ThingsGatewayBitConverter = new(EndianType.Big); | ||||
| 
 | ||||
| @@ -34,7 +34,7 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|     /// </summary> | ||||
|     /// <param name="response">返回数据</param> | ||||
|     /// <returns></returns> | ||||
|     internal OperResult<byte[], FilterResult> GetModbusData(byte[] response) | ||||
|     internal OperResult<byte[]> GetModbusData(byte[] response) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
| @@ -42,30 +42,22 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|             if (func == 1 || func == 2 || func == 3 || func == 4 || func == 5 || func == 6) | ||||
|             { | ||||
|                 if (response.Length == 6) | ||||
|                     return OperResult.CreateSuccessResult(response, FilterResult.Success); | ||||
|                     return OperResult.CreateSuccessResult(response); | ||||
|             } | ||||
|             else if (func == 15 || func == 16) | ||||
|             { | ||||
|                 var length = ThingsGatewayBitConverter.ToByte(response, 6); | ||||
|                 if (response.Length == 7 + length) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(response, FilterResult.Success); | ||||
|                 } | ||||
|                 if (response.Length > 7 + length) | ||||
|                 { | ||||
|                     return new() { Content2 = FilterResult.Success, Message = $"数据长度{response.Length}错误" }; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new() { Content2 = FilterResult.Cache, Message = $"数据长度{response.Length}错误" }; | ||||
|                     return OperResult.CreateSuccessResult(response); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return new() { Content2 = FilterResult.Success, Message = $"数据长度{response.Length}错误" }; | ||||
|             return new OperResult<byte[]>() { Message = $"数据长度{response.Length}错误" }; | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new(ex) { Content2 = FilterResult.Success }; | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @@ -96,7 +88,7 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|                 { | ||||
|                     if (function > 6) | ||||
|                     { | ||||
|                         request.ModbusAddress = new ModbusAddress() | ||||
|                         request.CurModbusAddress = new ModbusAddress() | ||||
|                         { | ||||
|                             Station = station, | ||||
|                             Address = addressStart.ToString(), | ||||
| @@ -108,7 +100,7 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         request.ModbusAddress = new ModbusAddress() | ||||
|                         request.CurModbusAddress = new ModbusAddress() | ||||
|                         { | ||||
|                             Station = station, | ||||
|                             Address = addressStart.ToString(), | ||||
| @@ -121,7 +113,7 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     request.ModbusAddress = new ModbusAddress() | ||||
|                     request.CurModbusAddress = new ModbusAddress() | ||||
|                     { | ||||
|                         Station = station, | ||||
|                         Address = addressStart.ToString(), | ||||
| @@ -137,7 +129,7 @@ internal class ModbusSerialServerDataHandleAdapter : ReadWriteDevicesSingleStrea | ||||
|             { | ||||
|                 request.ErrorCode = result.ErrorCode; | ||||
|                 request.Message = result.Message; | ||||
|                 return result.Content2; | ||||
|                 return FilterResult.Cache; | ||||
|             } | ||||
|         } | ||||
|         else | ||||
| @@ -15,11 +15,15 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class ModbusSerialServerMessage : MessageBase, IMessage, IModbusServerMessage | ||||
| public class ModbusSerialServerMessage : MessageBase, IMessage | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public ModbusAddress ModbusAddress { get; set; } | ||||
|     /// <inheritdoc/> | ||||
|     /// <summary> | ||||
|     /// 当前关联的地址 | ||||
|     /// </summary> | ||||
|     public ModbusAddress CurModbusAddress { get; set; } | ||||
|     /// <summary> | ||||
|     /// 当前读写的数据长度 | ||||
|     /// </summary> | ||||
|     public int Length { get; set; } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -37,13 +37,13 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -53,8 +53,8 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             var data = SendThenReturn(commandResult, cancellationToken); | ||||
|             return data; | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -70,8 +70,8 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|             await ConnectAsync(cancellationToken); | ||||
| 
 | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             var data = await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|             return data; | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -81,7 +81,7 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
| 
 | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         ModbusTcpDataHandleAdapter dataHandleAdapter = new() | ||||
|         { | ||||
| @@ -98,8 +98,7 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -114,8 +113,7 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -130,8 +128,7 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -146,8 +143,7 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -155,4 +151,34 @@ public class ModbusTcp : ReadWriteDevicesTcpClientBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             if (FrameTime != 0) | ||||
|                 Thread.Sleep(FrameTime); | ||||
|             var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             await Task.Delay(FrameTime, cancellationToken); | ||||
|             var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -17,9 +17,9 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// ModbusTcpDataHandleAdapter | ||||
| /// </summary> | ||||
| internal class ModbusTcpDataHandleAdapter : ReadWriteDevicesSingleStreamDataHandleAdapter<ModbusTcpMessage> | ||||
| public class ModbusTcpDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<ModbusTcpMessage> | ||||
| { | ||||
|     private readonly IncrementCount _incrementCount = new(ushort.MaxValue); | ||||
|     private readonly EasyIncrementCount easyIncrementCount = new(ushort.MaxValue); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 检测事务标识符 | ||||
| @@ -39,7 +39,7 @@ internal class ModbusTcpDataHandleAdapter : ReadWriteDevicesSingleStreamDataHand | ||||
|     /// <inheritdoc/> | ||||
|     public override byte[] PackCommand(byte[] command) | ||||
|     { | ||||
|         return ModbusHelper.AddModbusTcpHead(command, (ushort)_incrementCount.GetCurrentValue()); | ||||
|         return ModbusHelper.AddModbusTcpHead(command, (ushort)easyIncrementCount.GetCurrentValue()); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -14,7 +14,7 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class ModbusTcpMessage : MessageBase, IMessage | ||||
| public class ModbusTcpMessage : MessageBase, IMessage | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public override int HeadBytesLength => 6; | ||||
| @@ -29,7 +29,6 @@ internal class ModbusTcpMessage : MessageBase, IMessage | ||||
|         HeadBytes = heads; | ||||
| 
 | ||||
|         int num = (HeadBytes[4] * 256) + HeadBytes[5]; | ||||
|         if (num > 0xff + 3) return false; | ||||
|         BodyLength = num; | ||||
| 
 | ||||
|         if (!IsCheckMessageId) | ||||
| @@ -14,14 +14,14 @@ using System.ComponentModel; | ||||
| 
 | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <inheritdoc/> | ||||
| public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
| public class ModbusTcpDtu : ReadWriteDevicesTcpServerBase | ||||
| { | ||||
|     /// <inheritdoc/> | ||||
|     public ModbusDtu(TcpService tcpService) : base(tcpService) | ||||
|     public ModbusTcpDtu(TcpService tcpService) : base(tcpService) | ||||
|     { | ||||
|         ThingsGatewayBitConverter = new ThingsGatewayBitConverter(EndianType.Big); | ||||
|         RegisterByteLength = 2; | ||||
|         ModbusDtuPlugin modbusTcpSalvePlugin = new ModbusDtuPlugin(); | ||||
|         ModbusTcpDtuPlugin modbusTcpSalvePlugin = new ModbusTcpDtuPlugin(); | ||||
|         tcpService.Config.ConfigurePlugins(a => | ||||
|          { | ||||
|              a.Add(modbusTcpSalvePlugin); | ||||
| @@ -35,18 +35,6 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|     [Description("检测事务标识符")] | ||||
|     public bool IsCheckMessageId { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 是否Rtu格式 | ||||
|     /// </summary> | ||||
|     [Description("是否Rtu格式")] | ||||
|     public bool IsRtu { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Crc校验 | ||||
|     /// </summary> | ||||
|     [Description("Crc校验")] | ||||
|     public bool Crc16CheckEnable { get; set; } = true; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 站号 | ||||
|     /// </summary> | ||||
| @@ -56,13 +44,13 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -73,8 +61,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             Connect(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -90,8 +77,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -100,53 +86,27 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         if (socketClient != default) | ||||
|         if (socketClient is SocketClient client) | ||||
|         { | ||||
|             if (!IsRtu) | ||||
|             ModbusTcpDataHandleAdapter dataHandleAdapter = new() | ||||
|             { | ||||
|                 IsCheckMessageId = IsCheckMessageId, | ||||
|                 CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|             }; | ||||
|             client.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             foreach (var item in TcpService.GetClients()) | ||||
|             { | ||||
|                 ModbusTcpDataHandleAdapter dataHandleAdapter = new() | ||||
|                 { | ||||
|                     IsCheckMessageId = IsCheckMessageId, | ||||
|                     CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|                 }; | ||||
|                 socketClient.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 ModbusRtuDataHandleAdapter dataHandleAdapter = new() | ||||
|                 { | ||||
|                     Crc16CheckEnable = Crc16CheckEnable, | ||||
|                     CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|                 }; | ||||
|                 socketClient.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             //只适配第一个 | ||||
|             var item = TcpService.GetClients().FirstOrDefault(); | ||||
|             if (item != null) | ||||
|             { | ||||
|                 if (!IsRtu) | ||||
|                 { | ||||
|                     ModbusTcpDataHandleAdapter dataHandleAdapter = new() | ||||
|                     { | ||||
|                         IsCheckMessageId = IsCheckMessageId, | ||||
|                         CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|                     }; | ||||
|                     item.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     ModbusRtuDataHandleAdapter dataHandleAdapter = new() | ||||
|                     { | ||||
|                         Crc16CheckEnable = Crc16CheckEnable, | ||||
|                         CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|                     }; | ||||
|                     item.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|                 } | ||||
|                 item.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -159,8 +119,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             Connect(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -176,8 +135,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             Connect(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -193,8 +151,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -210,8 +167,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(mAddress.SocketId, commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -219,42 +175,64 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(string id, byte[] command, CancellationToken cancellationToken) | ||||
|     private OperResult<byte[]> SendThenReturn(string id, OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
| 
 | ||||
|         if (TcpService.TryGetSocketClient($"ID={id}", out var client)) | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             SetDataAdapter(client); | ||||
|             return SendThenReturn<MessageBase>(command, cancellationToken, client); | ||||
|             if (TcpService.TryGetSocketClient($"ID={id}", out var client)) | ||||
|             { | ||||
|                 SetDataAdapter(client); | ||||
| 
 | ||||
|                 var item = commandResult.Content; | ||||
|                 if (FrameTime != 0) | ||||
|                     Thread.Sleep(FrameTime); | ||||
|                 var WaitingClientEx = client.CreateWaitingClient(new() { ThrowBreakException = true }); | ||||
|                 var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>("客户端未连接"); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>("客户端未连接"); | ||||
|             return commandResult; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(string id, byte[] command, CancellationToken cancellationToken) | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(string id, OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (TcpService.TryGetSocketClient($"ID={id}", out var client)) | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             SetDataAdapter(client); | ||||
|             return await SendThenReturnAsync<MessageBase>(command, cancellationToken, client); | ||||
|         } | ||||
|         else if (TcpService.SocketClients.Count == 1) | ||||
|         { | ||||
|             var client1 = TcpService.SocketClients.GetClients().FirstOrDefault(); | ||||
|             if (client1 != null) | ||||
|             if (TcpService.TryGetSocketClient($"ID={id}", out var client)) | ||||
|             { | ||||
|                 SetDataAdapter(client1); | ||||
|                 return await SendThenReturnAsync<MessageBase>(command, cancellationToken, client1); | ||||
|                 SetDataAdapter(client); | ||||
| 
 | ||||
|                 var item = commandResult.Content; | ||||
|                 await Task.Delay(FrameTime, cancellationToken); | ||||
|                 var WaitingClientEx = client.CreateWaitingClient(new() { ThrowBreakException = true }); | ||||
|                 var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|                 return (MessageBase)result.RequestInfo; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return new OperResult<byte[]>("客户端未连接"); | ||||
|             } | ||||
|         } | ||||
|         return new OperResult<byte[]>("客户端未连接"); | ||||
|         else | ||||
|         { | ||||
|             return commandResult; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     internal class ModbusDtuPlugin : PluginBase, ITcpReceivingPlugin | ||||
|     internal class ModbusTcpDtuPlugin : PluginBase, ITcpReceivingPlugin | ||||
|     { | ||||
|         public async Task OnTcpReceiving(ITcpClientBase client, ByteBlockEventArgs e) | ||||
|         public Task OnTcpReceiving(ITcpClientBase client, ByteBlockEventArgs e) | ||||
|         { | ||||
|             if (client is ISocketClient socket) | ||||
|             { | ||||
| @@ -265,7 +243,7 @@ public class ModbusDtu : ReadWriteDevicesTcpServerBase | ||||
|                     socket.ResetId(id); | ||||
|                 } | ||||
|             } | ||||
|             await e.InvokeNext();//如果本插件无法处理当前数据,请将数据转至下一个插件。 | ||||
|             return e.InvokeNext();//如果本插件无法处理当前数据,请将数据转至下一个插件。 | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,441 @@ | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| //  源代码使用协议遵循本仓库的开源协议及附加协议 | ||||
| //  Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway | ||||
| //  Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway | ||||
| //  使用文档:https://diego2098.gitee.io/thingsgateway-docs/ | ||||
| //  QQ群:605534569 | ||||
| //------------------------------------------------------------------------------ | ||||
| #endregion | ||||
|  | ||||
| using System.Collections.Concurrent; | ||||
| using System.ComponentModel; | ||||
|  | ||||
| using ThingsGateway.Foundation.Extension.Bool; | ||||
| using ThingsGateway.Foundation.Extension.Generic; | ||||
|  | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| public class ModbusTcpServer : ReadWriteDevicesTcpServerBase | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 接收外部写入时,传出变量地址/写入字节组/转换规则/客户端 | ||||
|     /// </summary> | ||||
|     public Func<ModbusAddress, byte[], IThingsGatewayBitConverter, SocketClient, Task<OperResult>> WriteData; | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 继电器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer01ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 开关输入 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer02ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 输入寄存器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer03ByteBlocks = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 保持寄存器 | ||||
|     /// </summary> | ||||
|     private ConcurrentDictionary<byte, ByteBlock> ModbusServer04ByteBlocks = new(); | ||||
|     /// <inheritdoc/> | ||||
|     public ModbusTcpServer(TcpService tcpService) : base(tcpService) | ||||
|     { | ||||
|         ThingsGatewayBitConverter = new ThingsGatewayBitConverter(EndianType.Big); | ||||
|         RegisterByteLength = 2; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 多站点 | ||||
|     /// </summary> | ||||
|     [Description("多站点")] | ||||
|     public bool MulStation { get; set; } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// 默认站点 | ||||
|     /// </summary> | ||||
|     [Description("默认站点")] | ||||
|     public byte Station { get; set; } = 1; | ||||
|  | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override void Dispose() | ||||
|     { | ||||
|         foreach (var item in ModbusServer01ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer02ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer03ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         foreach (var item in ModbusServer04ByteBlocks) | ||||
|         { | ||||
|             item.Value.SafeDispose(); | ||||
|         } | ||||
|         ModbusServer01ByteBlocks.Clear(); | ||||
|         ModbusServer02ByteBlocks.Clear(); | ||||
|         ModbusServer03ByteBlocks.Clear(); | ||||
|         ModbusServer04ByteBlocks.Clear(); | ||||
|         base.Dispose(); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
|  | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return new OperResult<byte[]>("地址错误"); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         var ModbusServer01ByteBlock = ModbusServer01ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer02ByteBlock = ModbusServer02ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer03ByteBlock = ModbusServer03ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer04ByteBlock = ModbusServer04ByteBlocks[mAddress.Station]; | ||||
|         int len = mAddress.ReadFunction == 2 || mAddress.ReadFunction == 1 ? length : length * RegisterByteLength; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 1: | ||||
|                 byte[] bytes0 = new byte[len]; | ||||
|                 ModbusServer01ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer01ByteBlock.Read(bytes0); | ||||
|                 return OperResult.CreateSuccessResult(bytes0); | ||||
|             case 2: | ||||
|                 byte[] bytes1 = new byte[len]; | ||||
|                 ModbusServer02ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer02ByteBlock.Read(bytes1); | ||||
|                 return OperResult.CreateSuccessResult(bytes1); | ||||
|             case 3: | ||||
|  | ||||
|                 byte[] bytes3 = new byte[len]; | ||||
|                 ModbusServer03ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer03ByteBlock.Read(bytes3); | ||||
|                 return OperResult.CreateSuccessResult(bytes3); | ||||
|             case 4: | ||||
|                 byte[] bytes4 = new byte[len]; | ||||
|                 ModbusServer04ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer04ByteBlock.Read(bytes4); | ||||
|                 return OperResult.CreateSuccessResult(bytes4); | ||||
|         } | ||||
|         return new OperResult<byte[]>("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Read(address, length)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(object socketClient) | ||||
|     { | ||||
|         if (socketClient is SocketClient client) | ||||
|         { | ||||
|             ModbusTcpServerDataHandleAdapter dataHandleAdapter = new(); | ||||
|             dataHandleAdapter.CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout); | ||||
|             client.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             foreach (var item in TcpService.GetClients()) | ||||
|             { | ||||
|                 ModbusTcpDataHandleAdapter dataHandleAdapter = new() | ||||
|                 { | ||||
|                     CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout) | ||||
|                 }; | ||||
|                 item.SetDataHandlingAdapter(dataHandleAdapter); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, byte[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new OperResult(ex); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return new OperResult("地址错误"); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|         } | ||||
|         var ModbusServer03ByteBlock = ModbusServer03ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer04ByteBlock = ModbusServer04ByteBlocks[mAddress.Station]; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 3: | ||||
|                 ModbusServer03ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer03ByteBlock.Write(value); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|             case 4: | ||||
|                 ModbusServer04ByteBlock.Pos = mAddress.AddressStart * RegisterByteLength; | ||||
|                 ModbusServer04ByteBlock.Write(value); | ||||
|                 return OperResult.CreateSuccessResult(); | ||||
|         } | ||||
|         return new OperResult("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult Write(string address, bool[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         ModbusAddress mAddress; | ||||
|         try | ||||
|         { | ||||
|             mAddress = ModbusAddress.ParseFrom(address, Station); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return (new OperResult(ex)); | ||||
|         } | ||||
|         if (MulStation) | ||||
|         { | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             if (Station != mAddress.Station) | ||||
|             { | ||||
|                 return (new OperResult("地址错误")); | ||||
|             } | ||||
|             Init(mAddress); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         var ModbusServer01ByteBlock = ModbusServer01ByteBlocks[mAddress.Station]; | ||||
|         var ModbusServer02ByteBlock = ModbusServer02ByteBlocks[mAddress.Station]; | ||||
|         switch (mAddress.ReadFunction) | ||||
|         { | ||||
|             case 1: | ||||
|                 ModbusServer01ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer01ByteBlock.Write(value.BoolArrayToByte()); | ||||
|                 return (OperResult.CreateSuccessResult()); | ||||
|             case 2: | ||||
|                 ModbusServer02ByteBlock.Pos = mAddress.AddressStart; | ||||
|                 ModbusServer02ByteBlock.Write(value.BoolArrayToByte()); | ||||
|                 return (OperResult.CreateSuccessResult()); | ||||
|         } | ||||
|         return new OperResult("功能码错误"); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, byte[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Write(address, value)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     public override Task<OperResult> WriteAsync(string address, bool[] value, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         return Task.FromResult(Write(address, value)); | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc/> | ||||
|     protected override async Task Received(SocketClient client, ReceivedDataEventArgs e) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             var requestInfo = e.RequestInfo; | ||||
|             //接收外部报文 | ||||
|             if (requestInfo is ModbusTcpServerMessage modbusServerMessage) | ||||
|             { | ||||
|                 if (modbusServerMessage.CurModbusAddress == null) | ||||
|                 { | ||||
|                     return;//无法解析直接返回 | ||||
|                 } | ||||
|                 if (!modbusServerMessage.IsSuccess) | ||||
|                 { | ||||
|                     return;//无法解析直接返回 | ||||
|                 } | ||||
|  | ||||
|                 if (modbusServerMessage.CurModbusAddress.WriteFunction == 0)//读取 | ||||
|                 { | ||||
|                     var data = Read(modbusServerMessage.CurModbusAddress.ToString(), modbusServerMessage.Length); | ||||
|                     if (data.IsSuccess) | ||||
|                     { | ||||
|                         var coreData = data.Content; | ||||
|                         if (modbusServerMessage.CurModbusAddress.ReadFunction == 1 || modbusServerMessage.CurModbusAddress.ReadFunction == 2) | ||||
|                         { | ||||
|                             coreData = data.Content.Select(m => m > 0).ToArray().BoolArrayToByte().SelectMiddle(0, (int)Math.Ceiling(modbusServerMessage.Length / 8.0)); | ||||
|                         } | ||||
|                         var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 8).SpliceArray(new byte[] { (byte)coreData.Length }, coreData); | ||||
|                         sendData[5] = (byte)(sendData.Length - 6); | ||||
|                         client.Send(sendData); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         WriteError(client, modbusServerMessage);//返回错误码 | ||||
|                     } | ||||
|                 } | ||||
|                 else//写入 | ||||
|                 { | ||||
|                     var coreData = modbusServerMessage.Content; | ||||
|                     if (modbusServerMessage.CurModbusAddress.ReadFunction == 1 || modbusServerMessage.CurModbusAddress.ReadFunction == 2) | ||||
|                     { | ||||
|                         //写入继电器 | ||||
|                         if (WriteData != null) | ||||
|                         { | ||||
|                             // 接收外部写入时,传出变量地址/写入字节组/转换规则/客户端 | ||||
|                             if ((await WriteData(modbusServerMessage.CurModbusAddress, modbusServerMessage.Content, ThingsGatewayBitConverter, client)).IsSuccess) | ||||
|                             { | ||||
|                                 var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData.ByteToBoolArray(modbusServerMessage.Length)); | ||||
|                                 if (result.IsSuccess) | ||||
|                                 { | ||||
|                                     WriteSuccess03(client, modbusServerMessage); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     WriteError(client, modbusServerMessage); | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(client, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             //写入内存区 | ||||
|                             var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData.ByteToBoolArray(modbusServerMessage.Length)); | ||||
|                             if (result.IsSuccess) | ||||
|                             { | ||||
|                                 WriteSuccess03(client, modbusServerMessage); | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(client, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         //写入寄存器 | ||||
|                         if (WriteData != null) | ||||
|                         { | ||||
|  | ||||
|                             if ((await WriteData(modbusServerMessage.CurModbusAddress, modbusServerMessage.Content, ThingsGatewayBitConverter, client)).IsSuccess) | ||||
|                             { | ||||
|                                 var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData); | ||||
|                                 if (result.IsSuccess) | ||||
|                                 { | ||||
|                                     WriteSuccess03(client, modbusServerMessage); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     WriteError(client, modbusServerMessage); | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(client, modbusServerMessage); | ||||
|                             } | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             var result = Write(modbusServerMessage.CurModbusAddress.ToString(), coreData); | ||||
|                             if (result.IsSuccess) | ||||
|                             { | ||||
|                                 WriteSuccess03(client, modbusServerMessage); | ||||
|  | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 WriteError(client, modbusServerMessage); | ||||
|  | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             Logger.LogError(ex, ToString()); | ||||
|         } | ||||
|         //返回错误码 | ||||
|         static void WriteError(SocketClient client, ModbusTcpServerMessage modbusServerMessage) | ||||
|         { | ||||
|             var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 8) | ||||
| .SpliceArray(new byte[] { (byte)1 });//01 lllegal function | ||||
|             sendData[5] = (byte)(sendData.Length - 6); | ||||
|             sendData[7] = (byte)(sendData[7] + 128); | ||||
|             client.Send(sendData); | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void WriteSuccess03(SocketClient client, ModbusTcpServerMessage modbusServerMessage) | ||||
|     { | ||||
|         var sendData = modbusServerMessage.ReceivedBytes.SelectMiddle(0, 12); | ||||
|         sendData[5] = (byte)(sendData.Length - 6); | ||||
|         client.Send(sendData); | ||||
|     } | ||||
|  | ||||
|     private void Init(ModbusAddress mAddress) | ||||
|     { | ||||
|         if (ModbusServer01ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer01ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer02ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer02ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer03ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer03ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|         if (ModbusServer04ByteBlocks.TryAdd(mAddress.Station, new(1024 * 128))) | ||||
|             ModbusServer04ByteBlocks[mAddress.Station].SetLength(1024 * 128); | ||||
|     } | ||||
| } | ||||
| @@ -15,7 +15,7 @@ using ThingsGateway.Foundation.Extension.Generic; | ||||
| namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| 
 | ||||
| /// <inheritdoc/> | ||||
| internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDataHandleAdapter<ModbusTcpServerMessage> | ||||
| public class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<ModbusTcpServerMessage> | ||||
| { | ||||
|     private readonly ThingsGatewayBitConverter ThingsGatewayBitConverter = new(EndianType.Big); | ||||
| 
 | ||||
| @@ -34,7 +34,7 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|     /// </summary> | ||||
|     /// <param name="response">返回数据</param> | ||||
|     /// <returns></returns> | ||||
|     internal OperResult<byte[], FilterResult> GetModbusData(byte[] response) | ||||
|     internal OperResult<byte[]> GetModbusData(byte[] response) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
| @@ -42,30 +42,22 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|             if (func == 1 || func == 2 || func == 3 || func == 4 || func == 5 || func == 6) | ||||
|             { | ||||
|                 if (response.Length == 6) | ||||
|                     return OperResult.CreateSuccessResult(response, FilterResult.Success); | ||||
|                     return OperResult.CreateSuccessResult(response); | ||||
|             } | ||||
|             else if (func == 15 || func == 16) | ||||
|             { | ||||
|                 var length = ThingsGatewayBitConverter.ToByte(response, 6); | ||||
|                 if (response.Length == 7 + length) | ||||
|                 { | ||||
|                     return OperResult.CreateSuccessResult(response, FilterResult.Success); | ||||
|                 } | ||||
|                 if (response.Length > 7 + length) | ||||
|                 { | ||||
|                     return new() { Content2 = FilterResult.Success, Message = $"数据长度{response.Length}错误" }; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new() { Content2 = FilterResult.Cache, Message = $"数据长度{response.Length}错误" }; | ||||
|                     return OperResult.CreateSuccessResult(response); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return new() { Content2 = FilterResult.Success, Message = $"数据长度{response.Length}错误" }; | ||||
|             return new OperResult<byte[]>() { Message = $"数据长度{response.Length}错误" }; | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             return new(ex) { Content2 = FilterResult.Success }; | ||||
|             return new OperResult<byte[]>(ex); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @@ -93,7 +85,7 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|             { | ||||
|                 if (function > 6) | ||||
|                 { | ||||
|                     request.ModbusAddress = new ModbusAddress() | ||||
|                     request.CurModbusAddress = new ModbusAddress() | ||||
|                     { | ||||
|                         Station = station, | ||||
|                         Address = addressStart.ToString(), | ||||
| @@ -105,7 +97,7 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     request.ModbusAddress = new ModbusAddress() | ||||
|                     request.CurModbusAddress = new ModbusAddress() | ||||
|                     { | ||||
|                         Station = station, | ||||
|                         Address = addressStart.ToString(), | ||||
| @@ -118,7 +110,7 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 request.ModbusAddress = new ModbusAddress() | ||||
|                 request.CurModbusAddress = new ModbusAddress() | ||||
|                 { | ||||
|                     Station = station, | ||||
|                     Address = addressStart.ToString(), | ||||
| @@ -134,7 +126,7 @@ internal class ModbusTcpServerDataHandleAdapter : ReadWriteDevicesSingleStreamDa | ||||
|         { | ||||
|             request.ErrorCode = result.ErrorCode; | ||||
|             request.Message = result.Message; | ||||
|             return result.Content2; | ||||
|             return FilterResult.Cache; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -15,12 +15,12 @@ namespace ThingsGateway.Foundation.Adapter.Modbus | ||||
|     /// <summary> | ||||
|     /// <inheritdoc/> | ||||
|     /// </summary> | ||||
|     internal class ModbusTcpServerMessage : MessageBase, IMessage, IModbusServerMessage | ||||
|     public class ModbusTcpServerMessage : MessageBase, IMessage | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// 当前关联的地址 | ||||
|         /// </summary> | ||||
|         public ModbusAddress ModbusAddress { get; set; } | ||||
|         public ModbusAddress CurModbusAddress { get; set; } | ||||
|         /// <summary> | ||||
|         /// 当前读写的数据长度 | ||||
|         /// </summary> | ||||
| @@ -39,15 +39,16 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
| 
 | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack, int defaultIntervalTime) | ||||
|     public override List<T> LoadSourceRead<T, T2>(List<T2> deviceVariables, int maxPack) | ||||
|     { | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack, defaultIntervalTime); | ||||
|         return PackHelper.LoadSourceRead<T, T2>(this, deviceVariables, maxPack); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override string GetAddressDescription() | ||||
|     { | ||||
|         return $"{base.GetAddressDescription()}{Environment.NewLine}{ModbusHelper.GetAddressDescription()}"; | ||||
|         return base.GetAddressDescription() + Environment.NewLine + ModbusHelper.GetAddressDescription(); | ||||
|     } | ||||
|     /// <inheritdoc/> | ||||
|     public override OperResult<byte[]> Read(string address, int length, CancellationToken cancellationToken = default) | ||||
| @@ -56,8 +57,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -72,8 +72,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetReadModbusCommand(address, length, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -82,7 +81,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public override void SetDataAdapter(ISocketClient socketClient = default) | ||||
|     public override void SetDataAdapter(object socketClient = null) | ||||
|     { | ||||
|         ModbusUdpDataHandleAdapter dataHandleAdapter = new() | ||||
|         { | ||||
| @@ -102,8 +101,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -118,8 +116,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             Connect(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return SendThenReturn<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return SendThenReturn(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -134,8 +131,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -150,8 +146,7 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         { | ||||
|             await ConnectAsync(cancellationToken); | ||||
|             var commandResult = ModbusHelper.GetWriteBoolModbusCommand(address, value, Station); | ||||
|             if (!commandResult.IsSuccess) return commandResult; | ||||
|             return await SendThenReturnAsync<ModbusTcpMessage>(commandResult.Content, cancellationToken); | ||||
|             return await SendThenReturnAsync(commandResult, cancellationToken); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
| @@ -159,5 +154,34 @@ public class ModbusUdp : ReadWriteDevicesUdpSessionBase | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private OperResult<byte[]> SendThenReturn(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             if (FrameTime != 0) | ||||
|                 Thread.Sleep(FrameTime); | ||||
|             var result = WaitingClientEx.SendThenResponse(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private async Task<OperResult<byte[]>> SendThenReturnAsync(OperResult<byte[]> commandResult, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (commandResult.IsSuccess) | ||||
|         { | ||||
|             var item = commandResult.Content; | ||||
|             await Task.Delay(FrameTime, cancellationToken); | ||||
|             var result = await WaitingClientEx.SendThenResponseAsync(item, TimeOut, cancellationToken); | ||||
|             return (MessageBase)result.RequestInfo; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return new OperResult<byte[]>(commandResult.Message); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -16,9 +16,9 @@ namespace ThingsGateway.Foundation.Adapter.Modbus; | ||||
| /// <summary> | ||||
| /// <inheritdoc/> | ||||
| /// </summary> | ||||
| internal class ModbusUdpDataHandleAdapter : ReadWriteDevicesUdpDataHandleAdapter<ModbusTcpMessage> | ||||
| public class ModbusUdpDataHandleAdapter : ReadWriteDevicesUdpDataHandleAdapter<ModbusTcpMessage> | ||||
| { | ||||
|     private readonly IncrementCount _incrementCount = new(ushort.MaxValue); | ||||
|     private readonly EasyIncrementCount easyIncrementCount = new(ushort.MaxValue); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 检测事务标识符 | ||||
| @@ -38,7 +38,7 @@ internal class ModbusUdpDataHandleAdapter : ReadWriteDevicesUdpDataHandleAdapter | ||||
|     /// <inheritdoc/> | ||||
|     public override byte[] PackCommand(byte[] command) | ||||
|     { | ||||
|         return ModbusHelper.AddModbusTcpHead(command, (ushort)_incrementCount.GetCurrentValue()); | ||||
|         return ModbusHelper.AddModbusTcpHead(command, (ushort)easyIncrementCount.GetCurrentValue()); | ||||
|     } | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
| @@ -26,9 +26,8 @@ public class PackHelper | ||||
|     /// <param name="device"></param> | ||||
|     /// <param name="deviceVariables"></param> | ||||
|     /// <param name="maxPack">最大打包长度</param> | ||||
|     /// <param name="defaultIntervalTime">默认间隔时间</param> | ||||
|     /// <returns></returns> | ||||
|     public static List<T> LoadSourceRead<T, T2>(IReadWrite device, List<T2> deviceVariables, int maxPack, int defaultIntervalTime) where T : IDeviceVariableSourceRead<IDeviceVariableRunTime>, new() where T2 : IDeviceVariableRunTime, new() | ||||
|     public static List<T> LoadSourceRead<T, T2>(IReadWrite device, List<T2> deviceVariables, int maxPack) where T : IDeviceVariableSourceRead<IDeviceVariableRunTime>, new() where T2 : IDeviceVariableRunTime, new() | ||||
|     { | ||||
|         if (deviceVariables == null) | ||||
|             throw new ArgumentNullException(nameof(deviceVariables)); | ||||
| @@ -38,13 +37,13 @@ public class PackHelper | ||||
|         //需要先剔除额外信息,比如dataformat等 | ||||
|         foreach (var item in deviceVariables) | ||||
|         { | ||||
|             var address = item.Address; | ||||
|             var address = item.VariableAddress; | ||||
|             IThingsGatewayBitConverter transformParameter = ByteTransformUtil.GetTransByAddress(ref address, byteConverter); | ||||
|             item.ThingsGatewayBitConverter = transformParameter; | ||||
|             //item.Address = address; | ||||
|             item.Index = device.GetBitOffset(item.Address); | ||||
|             //item.VariableAddress = address; | ||||
|             item.Index = device.GetBitOffset(item.VariableAddress); | ||||
|         } | ||||
|         var deviceVariableRunTimeGroups = deviceVariables.GroupBy(it => it.IntervalTime ?? defaultIntervalTime); | ||||
|         var deviceVariableRunTimeGroups = deviceVariables.GroupBy(it => it.IntervalTime); | ||||
|         foreach (var group in deviceVariableRunTimeGroups) | ||||
|         { | ||||
|             Dictionary<ModbusAddress, T2> map = group.ToDictionary(it => | ||||
| @@ -67,10 +66,10 @@ public class PackHelper | ||||
|                     lastLen *= it.ThingsGatewayBitConverter.Length.Value; | ||||
|                 } | ||||
| 
 | ||||
|                 var address = it.Address; | ||||
|                 var address = it.VariableAddress; | ||||
|                 if (address.IndexOf('.') > 0) | ||||
|                 { | ||||
|                     var addressSplits = address.SplitStringByDelimiter(); | ||||
|                     var addressSplits = address.SplitDot(); | ||||
|                     address = addressSplits.RemoveLast(1).ArrayToString("."); | ||||
|                 } | ||||
|                 var result = ModbusAddress.ParseFrom(address); | ||||
| @@ -134,9 +133,9 @@ public class PackHelper | ||||
| 
 | ||||
|             T sourceRead = new() | ||||
|             { | ||||
|                 IntervalTimeTick = new TimerTick(intervalTime), | ||||
|                 TimerTick = new TimerTick(intervalTime), | ||||
|                 //这里只需要根据地址排序的第一个地址,作为实际打包报文中的起始地址 | ||||
|                 Address = startAddress.ToString(), | ||||
|                 VariableAddress = startAddress.ToString(), | ||||
|                 Length = sourceLen | ||||
|             }; | ||||
|             foreach (var item in tempAddressEnd) | ||||
| @@ -19,7 +19,7 @@ namespace ThingsGateway.Foundation.Adapter.OPCDA.Discovery; | ||||
| /// <summary> | ||||
| /// OpcDiscovery | ||||
| /// </summary> | ||||
| internal class OpcDiscovery | ||||
| public class OpcDiscovery | ||||
| { | ||||
|     private static readonly Guid CATID_OPC_DA10 = new("63D5F430-CFE4-11d1-B2C8-0060083BA1FB"); | ||||
| 
 | ||||
| @@ -76,7 +76,7 @@ public class OPCDAClient : IDisposable | ||||
|     /// <summary> | ||||
|     /// 当前配置 | ||||
|     /// </summary> | ||||
|     public OPCDANode OPCNode { get; private set; } | ||||
|     public OPCNode OPCNode { get; private set; } | ||||
|     private List<OpcGroup> Groups => m_server.OpcGroups; | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -198,7 +198,7 @@ public class OPCDAClient : IDisposable | ||||
|     /// 初始化设置 | ||||
|     /// </summary> | ||||
|     /// <param name="node"></param> | ||||
|     public void Init(OPCDANode node) | ||||
|     public void Init(OPCNode node) | ||||
|     { | ||||
|         if (node != null) | ||||
|             OPCNode = node; | ||||
| @@ -16,7 +16,7 @@ namespace ThingsGateway.Foundation.Adapter.OPCDA; | ||||
| /// <summary> | ||||
| /// OPCDA连接配置项 | ||||
| /// </summary> | ||||
| public class OPCDANode | ||||
| public class OPCNode | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 是否订阅 | ||||
| @@ -0,0 +1,4 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
| 	 | ||||
| </Project> | ||||
| @@ -16,7 +16,7 @@ namespace ThingsGateway.Foundation.Adapter.OPCUA; | ||||
| /// <summary> | ||||
| /// OPCUAClient配置项 | ||||
| /// </summary> | ||||
| public class OPCUANode | ||||
| public class OPCNode | ||||
| { | ||||
|     /// <summary> | ||||
|     /// OPCUrl | ||||
| @@ -17,27 +17,26 @@ using Opc.Ua.Client; | ||||
| using Opc.Ua.Client.ComplexTypes; | ||||
| using Opc.Ua.Configuration; | ||||
| 
 | ||||
| 
 | ||||
| //修改自https://github.com/dathlin/OpcUaHelper 与OPC基金会net库 | ||||
| 
 | ||||
| namespace ThingsGateway.Foundation.Adapter.OPCUA; | ||||
| 
 | ||||
| /// <summary> | ||||
| /// 订阅委托 | ||||
| /// </summary> | ||||
| /// <param name="value"></param> | ||||
| public delegate void DataChangedEventHandler((VariableNode variableNode, DataValue dataValue, JToken jToken) value); | ||||
| 
 | ||||
| /// <summary> | ||||
| /// OPCUAClient | ||||
| /// </summary> | ||||
| public class OPCUAClient : IDisposable | ||||
| { | ||||
|     #region 属性,变量等 | ||||
| 
 | ||||
|     #region 属性,变量等 | ||||
|     /// <summary> | ||||
|     /// 当前配置 | ||||
|     /// </summary> | ||||
|     public OPCUANode OPCNode; | ||||
|     public OPCNode OPCNode; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// ProductUri | ||||
| @@ -47,37 +46,32 @@ public class OPCUAClient : IDisposable | ||||
|     /// <summary> | ||||
|     /// 当前保存的变量名称列表 | ||||
|     /// </summary> | ||||
|     public List<List<string>> Variables = new(); | ||||
|     public List<string> Variables = new(); | ||||
| 
 | ||||
|     private readonly Action<byte, object, string, Exception> _logAction; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 当前的变量名称/OPC变量节点 | ||||
|     /// </summary> | ||||
|     private readonly Dictionary<string, VariableNode> _variableDicts = new(); | ||||
| 
 | ||||
|     private readonly object checkLock = new(); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 当前的订阅组,组名称/组 | ||||
|     /// </summary> | ||||
|     private readonly Dictionary<string, Subscription> dic_subscriptions = new(); | ||||
| 
 | ||||
|     private readonly ApplicationInstance m_application = new(); | ||||
| 
 | ||||
|     private readonly ApplicationConfiguration m_configuration; | ||||
|     private SessionReconnectHandler m_reConnectHandler; | ||||
|     private EventHandler m_ReconnectComplete; | ||||
|     private EventHandler m_ReconnectStarting; | ||||
|     private EventHandler<KeepAliveEventArgs> m_KeepAliveComplete; | ||||
|     private EventHandler<bool> m_ConnectComplete; | ||||
|     private EventHandler<OpcUaStatusEventArgs> m_OpcStatusChange; | ||||
| 
 | ||||
|     private ISession m_session; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 默认的构造函数,实例化一个新的OPC UA类 | ||||
|     /// </summary> | ||||
|     public OPCUAClient() | ||||
|     public OPCUAClient(Action<byte, object, string, Exception> log) | ||||
|     { | ||||
|         _logAction = log; | ||||
|         var certificateValidator = new CertificateValidator(); | ||||
|         certificateValidator.CertificateValidation += CertificateValidation; | ||||
| 
 | ||||
| @@ -96,6 +90,7 @@ public class OPCUAClient : IDisposable | ||||
|                 MaxMessageQueueSize = 1000000, | ||||
|                 MaxNotificationQueueSize = 1000000, | ||||
|                 MaxPublishRequestCount = 10000000, | ||||
| 
 | ||||
|             }, | ||||
| 
 | ||||
|             SecurityConfiguration = new SecurityConfiguration | ||||
| @@ -138,6 +133,8 @@ public class OPCUAClient : IDisposable | ||||
|                     StoreType = CertificateStoreType.Directory, | ||||
|                     StorePath = AppContext.BaseDirectory + @"OPCUAClientCertificate\pki\trustedUser", | ||||
|                 } | ||||
| 
 | ||||
| 
 | ||||
|             }, | ||||
| 
 | ||||
|             TransportQuotas = new TransportQuotas | ||||
| @@ -163,6 +160,8 @@ public class OPCUAClient : IDisposable | ||||
| 
 | ||||
|         m_configuration.Validate(ApplicationType.Client); | ||||
|         m_application.ApplicationConfiguration = m_configuration; | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -189,52 +188,6 @@ public class OPCUAClient : IDisposable | ||||
|     /// SessionReconnectHandler | ||||
|     /// </summary> | ||||
|     public SessionReconnectHandler ReConnectHandler => m_reConnectHandler; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raised when a good keep alive from the server arrives. | ||||
|     /// </summary> | ||||
|     public event EventHandler<KeepAliveEventArgs> KeepAliveComplete | ||||
|     { | ||||
|         add { m_KeepAliveComplete += value; } | ||||
|         remove { m_KeepAliveComplete -= value; } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raised when a reconnect operation starts. | ||||
|     /// </summary> | ||||
|     public event EventHandler ReconnectStarting | ||||
|     { | ||||
|         add { m_ReconnectStarting += value; } | ||||
|         remove { m_ReconnectStarting -= value; } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raised when a reconnect operation completes. | ||||
|     /// </summary> | ||||
|     public event EventHandler ReconnectComplete | ||||
|     { | ||||
|         add { m_ReconnectComplete += value; } | ||||
|         remove { m_ReconnectComplete -= value; } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raised after successfully connecting to or disconnecing from a server. | ||||
|     /// </summary> | ||||
|     public event EventHandler<bool> ConnectComplete | ||||
|     { | ||||
|         add { m_ConnectComplete += value; } | ||||
|         remove { m_ConnectComplete -= value; } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raised after the client status change | ||||
|     /// </summary> | ||||
|     public event EventHandler<OpcUaStatusEventArgs> OpcStatusChange | ||||
|     { | ||||
|         add { m_OpcStatusChange += value; } | ||||
|         remove { m_OpcStatusChange -= value; } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 当前活动会话。 | ||||
|     /// </summary> | ||||
| @@ -278,7 +231,7 @@ public class OPCUAClient : IDisposable | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 UpdateStatus(3, DateTime.Now, $"初始化{items[i]}变量订阅失败,错误原因:{ex}"); | ||||
|                 _logAction?.Invoke(3, this, $"初始化{items[i]}变量订阅失败", ex); | ||||
|             } | ||||
|         } | ||||
|         m_subscription.AddItems(monitoredItems); | ||||
| @@ -294,9 +247,9 @@ public class OPCUAClient : IDisposable | ||||
|         var isError = m_subscription.MonitoredItems.Any(a => a.Status.Error != null && StatusCode.IsBad(a.Status.Error.StatusCode)); | ||||
|         if (isError) | ||||
|         { | ||||
|             UpdateStatus(3, DateTime.Now, $"创建以下变量订阅失败:{Environment.NewLine}{m_subscription.MonitoredItems.Where(
 | ||||
|             _logAction?.Invoke(3, this, $"创建以下变量订阅失败:{Environment.NewLine}{m_subscription.MonitoredItems.Where(
 | ||||
|                 a => a.Status.Error != null && StatusCode.IsBad(a.Status.Error.StatusCode)) | ||||
|                 .Select(a => $"{a.StartNodeId.ToString()}:{a.Status.Error.ToString()}").ToJsonString()}");
 | ||||
|                 .Select(a => $"{a.StartNodeId.ToString()}:{a.Status.Error.ToString()}").ToJsonString()}", null);
 | ||||
|         } | ||||
| 
 | ||||
|         lock (dic_subscriptions) | ||||
| @@ -328,6 +281,7 @@ public class OPCUAClient : IDisposable | ||||
|                 item.Value.Delete(true); | ||||
|                 m_session.RemoveSubscription(item.Value); | ||||
|                 try { item.Value.Dispose(); } catch { } | ||||
| 
 | ||||
|             } | ||||
|             dic_subscriptions.Clear(); | ||||
|         } | ||||
| @@ -350,40 +304,39 @@ public class OPCUAClient : IDisposable | ||||
|                 dic_subscriptions.RemoveWhere(a => a.Key == subscriptionName); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void Callback(MonitoredItem monitoreditem, MonitoredItemNotificationEventArgs monitoredItemNotificationEventArgs) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             if (m_session != null) | ||||
|             var variableNode = ReadNode(monitoreditem.StartNodeId.ToString(), false); | ||||
|             foreach (var value in monitoreditem.DequeueValues()) | ||||
|             { | ||||
|                 var variableNode = ReadNode(monitoreditem.StartNodeId.ToString(), false); | ||||
|                 foreach (var value in monitoreditem.DequeueValues()) | ||||
|                 if (value.Value != null) | ||||
|                 { | ||||
|                     if (value.Value != null) | ||||
|                     var data = JsonUtils.Encode(m_session.MessageContext, TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable), value.Value); | ||||
|                     if (data == null && value.Value != null) | ||||
|                     { | ||||
|                         var data = JsonUtils.Encode(m_session.MessageContext, TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable), value.Value); | ||||
|                         if (data == null && value.Value != null) | ||||
|                         { | ||||
|                             UpdateStatus(3, DateTime.Now, $"{monitoreditem.StartNodeId}转换出错,原始值String为{value.Value}"); | ||||
|                             var data1 = JsonUtils.Encode(m_session.MessageContext, TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable), value.Value); | ||||
|                         } | ||||
|                         DataChangedHandler?.Invoke((variableNode, value, data)); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         var data = JValue.CreateNull(); | ||||
|                         DataChangedHandler?.Invoke((variableNode, value, data)); | ||||
|                         _logAction?.Invoke(3, this, $"{monitoreditem.StartNodeId}转换出错,原始值String为{value.Value}", null); | ||||
|                         var data1 = JsonUtils.Encode(m_session.MessageContext, TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable), value.Value); | ||||
|                     } | ||||
|                     DataChangedHandler?.Invoke((variableNode, value, data)); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     var data = JValue.CreateNull(); | ||||
|                     DataChangedHandler?.Invoke((variableNode, value, data)); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             UpdateStatus(3, DateTime.Now, $"{monitoreditem.StartNodeId}订阅处理错误,错误原因:" + ex); | ||||
|             _logAction?.Invoke(3, this, $"{monitoreditem.StartNodeId}订阅处理错误", ex); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| @@ -509,16 +462,17 @@ public class OPCUAClient : IDisposable | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
|     #region 连接 | ||||
| 
 | ||||
|     #region 连接 | ||||
|     private ComplexTypeSystem typeSystem; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 连接到服务器 | ||||
|     /// </summary> | ||||
|     public async Task ConnectAsync(CancellationToken cancellationToken) | ||||
|     public async Task ConnectAsync() | ||||
|     { | ||||
|         await ConnectAsync(OPCNode.OPCUrl, cancellationToken); | ||||
|         await ConnectAsync(OPCNode.OPCUrl); | ||||
|         _logAction?.Invoke(1, this, $"连接成功", null); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -530,15 +484,15 @@ public class OPCUAClient : IDisposable | ||||
|         // disconnect any existing session. | ||||
|         if (m_session != null) | ||||
|         { | ||||
|             _logAction?.Invoke(1, this, $"主动断开连接", null); | ||||
|             m_session = null; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Creates a new session. | ||||
|     /// </summary> | ||||
|     /// <returns>The new session object.</returns> | ||||
|     private async Task<ISession> ConnectAsync(string serverUrl, CancellationToken cancellationToken) | ||||
|     private async Task<ISession> ConnectAsync(string serverUrl) | ||||
|     { | ||||
|         PrivateDisconnect(); | ||||
| 
 | ||||
| @@ -547,7 +501,6 @@ public class OPCUAClient : IDisposable | ||||
|             throw new ArgumentNullException("未初始化配置"); | ||||
|         } | ||||
|         var useSecurity = OPCNode?.IsUseSecurity ?? true; | ||||
| 
 | ||||
|         EndpointDescription endpointDescription = CoreClientUtils.SelectEndpoint(m_configuration, serverUrl, useSecurity, 10000); | ||||
|         EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(m_configuration); | ||||
|         ConfiguredEndpoint endpoint = new(null, endpointDescription, endpointConfiguration); | ||||
| @@ -563,41 +516,28 @@ public class OPCUAClient : IDisposable | ||||
|         //创建本地证书 | ||||
|         await m_application.CheckApplicationInstanceCertificate(true, 0, 1200); | ||||
|         m_session = await Opc.Ua.Client.Session.Create( | ||||
|         m_configuration, | ||||
|         endpoint, | ||||
|         false, | ||||
|         OPCNode.CheckDomain, | ||||
|         (string.IsNullOrEmpty(OPCUAName)) ? m_configuration.ApplicationName : OPCUAName, | ||||
|         60000, | ||||
|         userIdentity, | ||||
|         Array.Empty<string>(), cancellationToken | ||||
|         ).ConfigureAwait(false); | ||||
|      m_configuration, | ||||
|     endpoint, | ||||
|     false, | ||||
|     OPCNode.CheckDomain, | ||||
|     (string.IsNullOrEmpty(OPCUAName)) ? m_configuration.ApplicationName : OPCUAName, | ||||
|     60000, | ||||
|     userIdentity, | ||||
|     Array.Empty<string>()); | ||||
| 
 | ||||
|         typeSystem = new ComplexTypeSystem(m_session); | ||||
| 
 | ||||
|         m_session.KeepAliveInterval = OPCNode.KeepAliveInterval == 0 ? 60000 : OPCNode.KeepAliveInterval; | ||||
|         m_session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive); | ||||
| 
 | ||||
|         // raise an event. | ||||
|         DoConnectComplete(true); | ||||
| 
 | ||||
|         UpdateStatus(2, DateTime.UtcNow, "Connected"); | ||||
| 
 | ||||
|         //如果是订阅模式,连接时添加订阅组 | ||||
|         if (OPCNode.ActiveSubscribe) | ||||
|         { | ||||
|             foreach (var item in Variables) | ||||
|             { | ||||
|                 await AddSubscriptionAsync(Guid.NewGuid().ToString(), item.ToArray(), OPCNode.LoadType); | ||||
|             } | ||||
|         } | ||||
|             await AddSubscriptionAsync(Guid.NewGuid().ToString(), Variables.ToArray(), OPCNode.LoadType); | ||||
|         return m_session; | ||||
|     } | ||||
| 
 | ||||
|     private void PrivateDisconnect() | ||||
|     { | ||||
|         bool state = m_session?.Connected == true; | ||||
| 
 | ||||
| 
 | ||||
|         if (m_reConnectHandler != null) | ||||
|         { | ||||
|             try { m_reConnectHandler.Dispose(); } catch { } | ||||
| @@ -609,14 +549,8 @@ public class OPCUAClient : IDisposable | ||||
|             m_session.Close(10000); | ||||
|         } | ||||
| 
 | ||||
|         if (state) | ||||
|         { | ||||
|             UpdateStatus(2, DateTime.UtcNow, "Disconnected"); | ||||
|             DoConnectComplete(false); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
|     #region 读取/写入 | ||||
| @@ -659,6 +593,7 @@ public class OPCUAClient : IDisposable | ||||
|                 valuesToWrite.Add(valueToWrite); | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             var result = await m_session.WriteAsync( | ||||
|      requestHeader: null, | ||||
|      nodesToWrite: valuesToWrite, cancellationToken); | ||||
| @@ -666,6 +601,7 @@ public class OPCUAClient : IDisposable | ||||
|             ClientBase.ValidateResponse(result.Results, valuesToWrite); | ||||
|             ClientBase.ValidateDiagnosticInfos(result.DiagnosticInfos, valuesToWrite); | ||||
| 
 | ||||
| 
 | ||||
|             var keys = writeInfoLists.Keys.ToList(); | ||||
|             for (int i = 0; i < keys.Count; i++) | ||||
|             { | ||||
| @@ -688,6 +624,7 @@ public class OPCUAClient : IDisposable | ||||
|             } | ||||
|             return results; | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -746,7 +683,7 @@ public class OPCUAClient : IDisposable | ||||
|         NodeId nodeToRead = new(nodeIdStr); | ||||
|         var node = (VariableNode)await m_session.ReadNodeAsync(nodeToRead, NodeClass.Variable, false, cancellationToken); | ||||
|         if (OPCNode.LoadType) | ||||
|             await typeSystem.LoadType(node.DataType).ConfigureAwait(false); | ||||
|             await typeSystem.LoadType(node.DataType); | ||||
|         _variableDicts.AddOrUpdate(nodeIdStr, node); | ||||
|         return node; | ||||
|     } | ||||
| @@ -769,6 +706,7 @@ public class OPCUAClient : IDisposable | ||||
|         return node; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 从服务器读取节点 | ||||
|     /// </summary> | ||||
| @@ -786,19 +724,23 @@ public class OPCUAClient : IDisposable | ||||
|             if (StatusCode.IsGood(nodes.Item2[i].StatusCode)) | ||||
|             { | ||||
|                 var node = ((VariableNode)nodes.Item1[i]); | ||||
|                 await typeSystem.LoadType(node.DataType).ConfigureAwait(false); | ||||
|                 await typeSystem.LoadType(node.DataType); | ||||
|                 _variableDicts.AddOrUpdate(nodeIdStrs[i], node); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 UpdateStatus(3, DateTime.Now, $"获取服务器节点信息失败{nodes.Item2[i]}"); | ||||
|                 _logAction?.Invoke(3, this, $"获取服务器节点信息失败{nodes.Item2[i]}", null); | ||||
|             } | ||||
|         } | ||||
|         return nodes.Item1.ToList(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     #region 特性 | ||||
| 
 | ||||
|     /// <summary> | ||||
| @@ -863,6 +805,7 @@ public class OPCUAClient : IDisposable | ||||
|                 ResultMask = (uint)BrowseResultMask.All | ||||
|             }; | ||||
|             nodesToBrowse.Add(nodeToBrowse); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         return await ReadNoteAttributeAsync(nodesToBrowse, nodesToRead, cancellationToken); | ||||
| @@ -1025,9 +968,11 @@ public class OPCUAClient : IDisposable | ||||
| 
 | ||||
|         return nodeAttribute.ToArray(); | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     /// <inheritdoc/> | ||||
|     public void Dispose() | ||||
|     { | ||||
| @@ -1046,6 +991,7 @@ public class OPCUAClient : IDisposable | ||||
|             throw new Exception(string.Format("验证证书失败,错误代码:{0}: {1}", eventArgs.Error.Code, eventArgs.Error.AdditionalInfo)); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     private async Task<Dictionary<string, List<OPCNodeAttribute>>> ReadNoteAttributeAsync(BrowseDescriptionCollection nodesToBrowse, ReadValueIdCollection nodesToRead, CancellationToken cancellationToken) | ||||
|     { | ||||
|         int startOfProperties = nodesToRead.Count; | ||||
| @@ -1122,6 +1068,7 @@ public class OPCUAClient : IDisposable | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             if (nodeAttributes.ContainsKey(nodeToRead.NodeId.ToString())) | ||||
|             { | ||||
|                 nodeAttributes[nodeToRead.NodeId.ToString()].Add(item); | ||||
| @@ -1139,47 +1086,21 @@ public class OPCUAClient : IDisposable | ||||
|     /// </summary> | ||||
|     private void Server_ReconnectComplete(object sender, EventArgs e) | ||||
|     { | ||||
|         try | ||||
|         if (!Object.ReferenceEquals(sender, m_reConnectHandler)) | ||||
|         { | ||||
|             if (!Object.ReferenceEquals(sender, m_reConnectHandler)) | ||||
|             { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             m_session = m_reConnectHandler.Session; | ||||
|             m_reConnectHandler.Dispose(); | ||||
|             m_reConnectHandler = null; | ||||
| 
 | ||||
|             // raise any additional notifications. | ||||
|             m_ReconnectComplete?.Invoke(this, e); | ||||
|             return; | ||||
|         } | ||||
|         catch (Exception) | ||||
|         { | ||||
|             throw; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Report the client status | ||||
|     /// </summary> | ||||
|     /// <param name="logLevel">Whether the status represents an error. </param> | ||||
|     /// <param name="time">The time associated with the status.</param> | ||||
|     /// <param name="status">The status message.</param> | ||||
|     /// <param name="args">Arguments used to format the status message.</param> | ||||
|     private void UpdateStatus(int logLevel, DateTime time, string status, params object[] args) | ||||
|     { | ||||
|         m_OpcStatusChange?.Invoke(this, new OpcUaStatusEventArgs() | ||||
|         { | ||||
|             LogLevel = logLevel, | ||||
|             Time = time.ToLocalTime(), | ||||
|             Text = String.Format(status, args), | ||||
|         }); | ||||
|         m_session = m_reConnectHandler.Session; | ||||
|         m_reConnectHandler = null; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void Session_KeepAlive(ISession session, KeepAliveEventArgs e) | ||||
|     { | ||||
|         lock (checkLock) | ||||
|         { | ||||
| 
 | ||||
|             if (!Object.ReferenceEquals(session, m_session)) | ||||
|             { | ||||
|                 return; | ||||
| @@ -1187,39 +1108,22 @@ public class OPCUAClient : IDisposable | ||||
| 
 | ||||
|             if (ServiceResult.IsBad(e.Status)) | ||||
|             { | ||||
|                 if (m_session.KeepAliveInterval <= 0) | ||||
|                 { | ||||
|                     UpdateStatus(3, e.CurrentTime, "Communication Error ({0})", e.Status); | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 UpdateStatus(3, e.CurrentTime, "Reconnecting in {0}s", m_session.KeepAliveInterval / 1000); | ||||
|                 _logAction?.Invoke(3, this, $"心跳检测错误:{e.Status}", null); | ||||
| 
 | ||||
|                 if (m_reConnectHandler == null) | ||||
|                 { | ||||
|                     m_ReconnectStarting?.Invoke(this, e); | ||||
| 
 | ||||
|                     m_reConnectHandler = new SessionReconnectHandler(); | ||||
|                     m_reConnectHandler.BeginReconnect(m_session, m_session.KeepAliveInterval, Server_ReconnectComplete); | ||||
|                 } | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             // update status. | ||||
|             UpdateStatus(0, e.CurrentTime, "Session_KeepAlive Connected [{0}]", session.Endpoint.EndpointUrl); | ||||
| 
 | ||||
|             // raise any additional notifications. | ||||
|             m_KeepAliveComplete?.Invoke(this, e); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Raises the connect complete event on the main GUI thread. | ||||
|     /// </summary> | ||||
|     private void DoConnectComplete(bool state) | ||||
|     { | ||||
|         m_ConnectComplete?.Invoke(this, state); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     #endregion | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| #region copyright | ||||
| #region copyright | ||||
| //------------------------------------------------------------------------------ | ||||
| //  此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 | ||||
| //  此代码版权(除特别声明外的代码)归作者本人Diego所有 | ||||
| @@ -13,33 +13,6 @@ | ||||
| using Opc.Ua; | ||||
| 
 | ||||
| namespace ThingsGateway.Foundation.Adapter.OPCUA; | ||||
| 
 | ||||
| /// <summary> | ||||
| /// OPC UA的状态更新消息 | ||||
| /// </summary> | ||||
| public class OpcUaStatusEventArgs | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 日志等级,<br></br> | ||||
|     /// 更为详细的步骤型日志输出 Trace = 0,<br></br> | ||||
|     /// 调试信息日志Debug = 1,<br></br> | ||||
|     /// 消息类日志输出 Info = 2,<br></br> | ||||
|     /// 警告类日志输出 Warning = 3,<br></br> | ||||
|     /// 错误类日志输出 Error = 4,<br></br> | ||||
|     /// 不可控中断类日输出Critical = 5, | ||||
|     /// </summary> | ||||
|     public int LogLevel { get; set; } | ||||
|     /// <summary> | ||||
|     /// 时间 | ||||
|     /// </summary> | ||||
|     public DateTime Time { get; set; } | ||||
|     /// <summary> | ||||
|     /// 文本 | ||||
|     /// </summary> | ||||
|     public string Text { get; set; } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /// <summary> | ||||
| /// 读取属性过程中用于描述的 | ||||
| /// </summary> | ||||
| @@ -49,7 +22,6 @@ public class OPCNodeAttribute | ||||
|     /// 属性的名称 | ||||
|     /// </summary> | ||||
|     public string Name { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 操作结果状态描述 | ||||
|     /// </summary> | ||||
| @@ -59,9 +31,10 @@ public class OPCNodeAttribute | ||||
|     /// 属性的类型描述 | ||||
|     /// </summary> | ||||
|     public string Type { get; set; } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// 属性的值,如果读取错误,返回文本描述 | ||||
|     /// </summary> | ||||
|     public object Value { get; set; } | ||||
| } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| @@ -1,14 +1,15 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
| 	<PropertyGroup> | ||||
| 		<TargetFrameworks>net48;net6.0;net8.0;</TargetFrameworks> | ||||
| 		<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks> | ||||
| 
 | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
| 		<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||||
| 		<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.372.76" /> | ||||
| 		<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes" Version="1.4.372.76" /> | ||||
| 		<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.372.56" /> | ||||
| 		<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes" Version="1.4.372.56" /> | ||||
| 	</ItemGroup> | ||||
| 
 | ||||
| 
 | ||||
| </Project> | ||||
| @@ -35,9 +35,9 @@ internal static class CollectionExtensions | ||||
|     /// <param name="source"></param> | ||||
|     /// <param name="selector"></param> | ||||
|     /// <returns></returns> | ||||
|     internal static async Task<TResult[]> SelectAsync<T, TResult>(this IEnumerable<T> source, Func<T, Task<TResult>> selector) | ||||
|     internal static Task<TResult[]> SelectAsync<T, TResult>(this IEnumerable<T> source, Func<T, Task<TResult>> selector) | ||||
|     { | ||||
|         return await Task.WhenAll(source.Select(selector)); | ||||
|         return Task.WhenAll(source.Select(selector)); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user