Browse Source

update panasonic driver

master
Gavin 9 years ago
parent
commit
6c228c5935
  1. 23
      SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs
  2. BIN
      SCADA/dll/PanasonicDriver.dll

23
SCADA/Program/PanasonicDriver/PanasonicSerialReader.cs

@ -5,7 +5,6 @@ using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.IO.Ports; using System.IO.Ports;
using System.Net;
using System.Text; using System.Text;
namespace PanasonicPLCriver namespace PanasonicPLCriver
@ -43,7 +42,7 @@ namespace PanasonicPLCriver
_server = server; _server = server;
_id = id; _id = id;
//spare1 = {COM3,9600,Odd,8,One} //spare1 = {COM3,9600,Odd,8,One}
_serialPort = new SerialPort("COM2",57600,Parity.Odd,8,StopBits.One); _serialPort = new SerialPort("COM2", 57600, Parity.Odd, 8, StopBits.One);
_devId = byte.Parse(spare2); _devId = byte.Parse(spare2);
} }
public bool IsClosed public bool IsClosed
@ -330,7 +329,7 @@ namespace PanasonicPLCriver
{ {
if (!isBool(startAddress.Area))//读寄存器的情况 if (!isBool(startAddress.Area))//读寄存器的情况
{ {
cmd = CreateRDCmd(startAddress.Start,size,out respBeginStr); cmd = CreateRDCmd(startAddress.Start, size, out respBeginStr);
} }
else //读触点的情况 else //读触点的情况
{ {
@ -340,7 +339,8 @@ namespace PanasonicPLCriver
} }
catch (Exception e) catch (Exception e)
{ {
OnClose?.Invoke(this, new ShutdownRequestEventArgs(e.Message)); if (OnClose != null)
OnClose(this, new ShutdownRequestEventArgs(e.Message));
return null; return null;
} }
} }
@ -359,14 +359,16 @@ namespace PanasonicPLCriver
} }
catch (Exception) catch (Exception)
{ {
OnClose?.Invoke(this, new ShutdownRequestEventArgs("读取超时")); if (OnClose != null)
OnClose(this, new ShutdownRequestEventArgs("读取超时"));
return null; return null;
} }
} }
if (recv.Substring(3, 1) == "!")//返回为错误代码 if (recv.Substring(3, 1) == "!")//返回为错误代码
{ {
string err = recv.Substring(4, 2); string err = recv.Substring(4, 2);
OnClose?.Invoke(this, new ShutdownRequestEventArgs(daveStrerror(err))); if (OnClose != null)
OnClose(this, new ShutdownRequestEventArgs(daveStrerror(err)));
return null; return null;
} }
string needXorStr = recv.Substring(0, recv.Length - 2);//需要进行xor校验的字符串 string needXorStr = recv.Substring(0, recv.Length - 2);//需要进行xor校验的字符串
@ -374,7 +376,8 @@ namespace PanasonicPLCriver
string checkStr = Utility.XorCheck(needXorStr); string checkStr = Utility.XorCheck(needXorStr);
if (checkStr != recvCheck) if (checkStr != recvCheck)
{ {
OnClose?.Invoke(this, new ShutdownRequestEventArgs("校验失败")); if (OnClose != null)
OnClose(this, new ShutdownRequestEventArgs("校验失败"));
return null; return null;
} }
else else
@ -391,7 +394,7 @@ namespace PanasonicPLCriver
{ {
switch (code) switch (code)
{ {
case "20":return "未定义"; case "20": return "未定义";
case "21": return "远程单元无法被正确识别,或者发生了数据错误."; case "21": return "远程单元无法被正确识别,或者发生了数据错误.";
case "22": return "用于远程单元的接收缓冲区已满."; case "22": return "用于远程单元的接收缓冲区已满.";
case "23": return "远程单元编号(01 至16)设置与本地单元重复."; case "23": return "远程单元编号(01 至16)设置与本地单元重复.";
@ -476,7 +479,7 @@ namespace PanasonicPLCriver
public int WriteBit(DeviceAddress address, bool bit) public int WriteBit(DeviceAddress address, bool bit)
{ {
string respBeginStr = string.Empty; string respBeginStr = string.Empty;
string cmd = CreateWCSCmd(address.Start,address.Bit,address.Area,bit,out respBeginStr); string cmd = CreateWCSCmd(address.Start, address.Bit, address.Area, bit, out respBeginStr);
WriteSyncData(respBeginStr, cmd); WriteSyncData(respBeginStr, cmd);
return 0; return 0;
} }
@ -499,7 +502,7 @@ namespace PanasonicPLCriver
public int WriteInt16(DeviceAddress address, short value) public int WriteInt16(DeviceAddress address, short value)
{ {
string respBeginStr = string.Empty; string respBeginStr = string.Empty;
string cmd = CreateWDCmd(address.Start, new short[1] {value}, out respBeginStr); string cmd = CreateWDCmd(address.Start, new short[1] { value }, out respBeginStr);
WriteSyncData(respBeginStr, cmd); WriteSyncData(respBeginStr, cmd);
return 0; return 0;
} }

BIN
SCADA/dll/PanasonicDriver.dll

Binary file not shown.
Loading…
Cancel
Save