修改plc读取写入的问题
This commit is contained in:
1 parent
47f9d58ad1
commit
18dfe4f807
3 files changed
+15
-2
No files matched your search
@@ -240,6 +240,8 @@ namespace WindowsFormsApp1
|
|||||||
{
|
{
|
||||||
string returnValue = scanForm.ReturnValue;
|
string returnValue = scanForm.ReturnValue;
|
||||||
otherdata.JS_SN = returnValue;
|
otherdata.JS_SN = returnValue;
|
||||||
|
|
||||||
|
Init.ScanString = returnValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ namespace WindowsFormsApp1
|
|||||||
public static List<t_lineplc> t_Lineplcs;
|
public static List<t_lineplc> t_Lineplcs;
|
||||||
public static List<ThreadHelp> threadHelps;
|
public static List<ThreadHelp> threadHelps;
|
||||||
|
|
||||||
|
public static string ScanString;
|
||||||
//PLC状态存储
|
//PLC状态存储
|
||||||
public static short Plcstatus = -1;
|
public static short Plcstatus = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using WindowsFormsApp1.mod;
|
|||||||
using WindowsFormsApp1.mod.server;
|
using WindowsFormsApp1.mod.server;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WindowsFormsApp1.server
|
namespace WindowsFormsApp1.server
|
||||||
{
|
{
|
||||||
@@ -177,7 +178,7 @@ namespace WindowsFormsApp1.server
|
|||||||
List<t_plcaddress> writeaddress = new List<t_plcaddress>();
|
List<t_plcaddress> writeaddress = new List<t_plcaddress>();
|
||||||
|
|
||||||
//address = address.FindAll(a => a.code != "Write_Heartbeat");
|
//address = address.FindAll(a => a.code != "Write_Heartbeat");
|
||||||
foreach (var add in address)
|
foreach (var add in address.Where(a=>a.type == "write"))
|
||||||
{
|
{
|
||||||
foreach (var p in PlcData.GetType().GetProperties())
|
foreach (var p in PlcData.GetType().GetProperties())
|
||||||
{
|
{
|
||||||
@@ -328,7 +329,16 @@ namespace WindowsFormsApp1.server
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "string":
|
case "string":
|
||||||
byte[] tochar = Encoding.ASCII.GetBytes(((string)value).PadRight(address[i].addresstypelegth, ' '));
|
byte[] tochar = new byte[address[i].addresstypelegth];
|
||||||
|
|
||||||
|
var byte1 = Convert.ToByte((address[i].addresstypelegth - 2).ToString());
|
||||||
|
var byte2 = Convert.ToByte( (((string)value).Length).ToString() );
|
||||||
|
var byte3 = Encoding.ASCII.GetBytes((string)value);
|
||||||
|
|
||||||
|
tochar[0] = byte1;
|
||||||
|
tochar[1] = byte2;
|
||||||
|
|
||||||
|
Array.Copy(byte3, 0, tochar, 2, byte3.Length);
|
||||||
tochar.CopyTo(writebyte, index);
|
tochar.CopyTo(writebyte, index);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user