This commit is contained in:
gongxh
2022-05-05 15:15:53 +08:00
parent 43fa85e6e8
commit 74afdf00f9
4 changed files with 65 additions and 50 deletions

View File

@@ -30,6 +30,8 @@
<add key="StopBits" value="1"/> <add key="StopBits" value="1"/>
<!--奇偶校验。0:无校验;1:奇校验;2:偶校验;--> <!--奇偶校验。0:无校验;1:奇校验;2:偶校验;-->
<add key="ParityMsg" value="2"/> <add key="ParityMsg" value="2"/>
<add key="ModbusPattern" value="0" />
<!--托盘序列号前缀--> <!--托盘序列号前缀-->
<add key="PalletIndexPrefix" value="Pallet"/> <add key="PalletIndexPrefix" value="Pallet"/>
<!--托盘序列号生成日期--> <!--托盘序列号生成日期-->

View File

@@ -30,7 +30,7 @@ namespace CleanMachineHMI
static KeyboardAutoPopUp() static KeyboardAutoPopUp()
{ {
hasKeyboard = GetKeyboardPresent(); // hasKeyboard = GetKeyboardPresent();

View File

@@ -7,7 +7,7 @@
//启用心跳检查 //启用心跳检查
#if RELEASE #if RELEASE
#define UseHeartbeat #define UseHeartbeat
#endif #endif
using CleanMachine.Model; using CleanMachine.Model;
using LeadDataBaseUtility; using LeadDataBaseUtility;
@@ -90,45 +90,58 @@ namespace CleanMachineHMI
public bool PlcInit() public bool PlcInit()
{ {
#if RELEASE
try try
{ {
#endif
string portname = GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'PortName'")[0]["PARAMETER_VALUE"].ToString(); string portname = ConfigurationManager.AppSettings["PortName"];
int baudrate = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'BaudRate'")[0]["PARAMETER_VALUE"]); int baudrate = int.Parse(ConfigurationManager.AppSettings["BaudRate"]);
int databits = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'DataBits'")[0]["PARAMETER_VALUE"]); int databits = int.Parse(ConfigurationManager.AppSettings["DataBits"]);
StopBits stopbis = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 0 ? StopBits.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 1 ? StopBits.One : StopBits.Two); StopBits stopbis = (StopBits)int.Parse(ConfigurationManager.AppSettings["StopBits"]);
Parity paritymsg = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 0 ? Parity.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 1 ? Parity.Odd : Parity.Even); Parity paritymsg = (Parity)int.Parse(ConfigurationManager.AppSettings["ParityMsg"]);
int modbusPattern = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ModbusPattern'")[0]["PARAMETER_VALUE"]); int modbusPattern = int.Parse(ConfigurationManager.AppSettings["ModbusPattern"]);
//string portname = GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'PortName'")[0]["PARAMETER_VALUE"].ToString();
//int baudrate = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'BaudRate'")[0]["PARAMETER_VALUE"]);
//int databits = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'DataBits'")[0]["PARAMETER_VALUE"]);
//StopBits stopbis = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 0 ? StopBits.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 1 ? StopBits.One : StopBits.Two);
//Parity paritymsg = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 0 ? Parity.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 1 ? Parity.Odd : Parity.Even);
//int modbusPattern = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ModbusPattern'")[0]["PARAMETER_VALUE"]);
#if USE_LOCAL_TCP_DEBUG #if USE_LOCAL_TCP_DEBUG
port = new System.Net.Sockets.TcpClient(); port = new System.Net.Sockets.TcpClient();
var adaptet = new NModbus.IO.TcpClientAdapter(port); var adaptet = new NModbus.IO.TcpClientAdapter(port);
#else #else
port = new SerialPort(portname, baudrate, paritymsg, databits, stopbis); port = new SerialPort(portname, baudrate, paritymsg, databits, stopbis);
var adaptet = new NModbus.Serial.SerialPortAdapter(port); var adaptet = new NModbus.Serial.SerialPortAdapter(port);
adaptet.ReadTimeout = 200;
#endif #endif
var factory = new ModbusFactory(); var factory = new ModbusFactory();
if (modbusPattern == 0) if (modbusPattern == 0)
{ {
master = factory.CreateRtuMaster(adaptet);
}
else
{
master = factory.CreateAsciiMaster(adaptet);
}
master = factory.CreateRtuMaster(adaptet);
}
else
{
master = factory.CreateAsciiMaster(adaptet);
}
#if USE_LOCAL_TCP_DEBUG #if USE_LOCAL_TCP_DEBUG
port.Connect("10.0.0.95", 5002); port.Connect("10.0.0.95", 5002);
this._isConn = true; this._isConn = true;
return true;
#else #else
port.Open(); port.Open();
return port.IsOpen;
#endif #endif
return true;
#if RELEASE
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -136,7 +149,7 @@ namespace CleanMachineHMI
isConn = false; isConn = false;
return false; return false;
} }
#endif
} }
public void ClosePlcConn() public void ClosePlcConn()
{ {
@@ -170,7 +183,7 @@ namespace CleanMachineHMI
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
{ {
//string PlcItemId = item.PlcItemId.ToString(); //string PlcItemId = item.PlcItemId.ToString();
// string plcdatatype = item.PlcItemDataType.ToString(); // string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
item.PlcItemValue = readBytArr_M[plcItemDeviationAddress].ToString(); item.PlcItemValue = readBytArr_M[plcItemDeviationAddress].ToString();
GlobalHelper.ShowSensorStatus(item, new EventArgs()); GlobalHelper.ShowSensorStatus(item, new EventArgs());
@@ -216,7 +229,7 @@ namespace CleanMachineHMI
{ {
string PlcItemId = item.PlcItemId.ToString(); string PlcItemId = item.PlcItemId.ToString();
// string plcdatatype = item.PlcItemDataType.ToString(); // string plcdatatype = item.PlcItemDataType.ToString();
int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress);
if (Convert.ToInt32(item.PlcItemPriAddress) < 409) if (Convert.ToInt32(item.PlcItemPriAddress) < 409)
{ {

View File

@@ -192,36 +192,36 @@ namespace CleanMachineHMI
isPlcConnStatus = true; isPlcConnStatus = true;
GlobalHelper.SysThIsRunFlag = true; GlobalHelper.SysThIsRunFlag = true;
Thread th = new Thread(RefreshPlcItem) //Thread th = new Thread(RefreshPlcItem)
{
IsBackground = true
};
th.Start();
//Thread th = new Thread(RefreshPlcItem_M)
//{ //{
// IsBackground = true // IsBackground = true
//}; //};
//th.Start(); //th.Start();
//Thread th1 = new Thread(RefreshPlcItem_D)
//{
// IsBackground = true
//};
//th1.Start();
//Thread th2 = new Thread(RefreshPlcItem_X) Thread th = new Thread(RefreshPlcItem_M)
//{ {
// IsBackground = true IsBackground = true
//}; };
//th2.Start(); th.Start();
//Thread th3 = new Thread(RefreshPlcItem_Y) Thread th1 = new Thread(RefreshPlcItem_D)
//{ {
// IsBackground = true IsBackground = true
//}; };
//th3.Start(); th1.Start();
Thread th2 = new Thread(RefreshPlcItem_X)
{
IsBackground = true
};
th2.Start();
Thread th3 = new Thread(RefreshPlcItem_Y)
{
IsBackground = true
};
th3.Start();
Thread th4 = new Thread(MainThRunFunc) Thread th4 = new Thread(MainThRunFunc)
{ {