Commit 275d3c03 刘韬

1

1 个父辈 0bf0be36
正在显示 37 个修改的文件 包含 819 行增加37 行删除
此文件类型无法预览
...@@ -15,5 +15,6 @@ ...@@ -15,5 +15,6 @@
bool ReadData(out string value, short length); bool ReadData(out string value, short length);
void TriggerMode(bool auto); void TriggerMode(bool auto);
bool WriteData(string id); bool WriteData(string id);
bool WriteData(byte[] data);
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -175,7 +175,13 @@ namespace Asa.RFID ...@@ -175,7 +175,13 @@ namespace Asa.RFID
{ {
if (_fullCmd[7] == 0x03) if (_fullCmd[7] == 0x03)
{ {
value = (char)_fullCmd[10] + _fullCmd[11].ToString(); if (length > 4)
{
var b = _fullCmd.GetRange(10, length).ToArray();
value = Encoding.ASCII.GetString(b);
}
else
value = (char)_fullCmd[10] + _fullCmd[11].ToString();
rtn = true; rtn = true;
} }
else else
...@@ -589,7 +595,72 @@ namespace Asa.RFID ...@@ -589,7 +595,72 @@ namespace Asa.RFID
//Common.log.Error(string.Format("Write[{0}] ERROR", IP), ex); //Common.log.Error(string.Format("Write[{0}] ERROR", IP), ex);
} }
} }
public bool WriteData(byte[] data)
{
_dataMode = false;
bool rtn = false;
Write(data);
if (Wait())
{
var a=("Write[" + IP + "] " + HexBuff(_fullCmd.ToArray()));
if (_fullCmd[7] == 0x10)
rtn = true;
//else
// Common.log.Info("0x10功能码不匹配");
}
return rtn;
}
private void Write(byte[] value)
{
if (!IsConn) return;
int registercount = (int)Math.Ceiling(value.Length / 2d);
//int registercount = (int)value.Length;
//int valuelen = registercount * 2;
byte[] temp;
byte[] buffer = new byte[13];
GetMark();
temp = BitConverter.GetBytes(_mark); //事务处理标识
buffer[0] = temp[1]; //高位
buffer[1] = temp[0]; //低位
buffer[2] = 0;
buffer[3] = 0; //协议标识
buffer[4] = 0;
buffer[5] = 15; //后面字节数
buffer[6] = 0xFF; //主设备
buffer[7] = 0x10; //功能码
buffer[8] = 0x00;
buffer[9] = 0x20; //地址
buffer[10] = 0;
buffer[11] = (byte)registercount; //寄存器个数
buffer[12] = (byte)(registercount*2); //数据长度
var ab = buffer.ToList();
ab.AddRange(value);
if (value.Length < registercount * 2)
ab.Add(0x00);
buffer = ab.ToArray();
buffer[5] = (byte)(7 + registercount * 2);
try
{
_total = false;
//Common.log.Debug("Write[" + IP + "] " + HexBuff(buffer));
if (_client != null)
_client.Send(buffer);
}
catch (Exception ex)
{
IsConn = false;
//Common.log.Error(string.Format("Write[{0}] ERROR", IP), ex);
}
}
private void GetMark() private void GetMark()
{ {
if (_mark == short.MaxValue) if (_mark == short.MaxValue)
......
...@@ -9,6 +9,7 @@ using System.Threading.Tasks; ...@@ -9,6 +9,7 @@ using System.Threading.Tasks;
public class PuYueRFID_C2S public class PuYueRFID_C2S
{ {
byte station = 1; byte station = 1;
bool Automode;
public string IP; public string IP;
TcpClient tcpClient = new TcpClient(); TcpClient tcpClient = new TcpClient();
Thread iomonitorThread; Thread iomonitorThread;
...@@ -19,10 +20,10 @@ public class PuYueRFID_C2S ...@@ -19,10 +20,10 @@ public class PuYueRFID_C2S
/// 连接状态变化, 手动连接不触发 /// 连接状态变化, 手动连接不触发
/// </summary> /// </summary>
public event EventHandler<bool> ConnectionState_Event; public event EventHandler<bool> ConnectionState_Event;
public PuYueRFID_C2S(string ip) public PuYueRFID_C2S(string ip, bool automode = false)
{ {
this.IP = ip; this.IP = ip;
Automode = automode;
//DOdata[0] = 0x00; //DOdata[0] = 0x00;
//DOdata[1] = 0x00; //DOdata[1] = 0x00;
//if (autoread) //if (autoread)
...@@ -57,9 +58,12 @@ public class PuYueRFID_C2S ...@@ -57,9 +58,12 @@ public class PuYueRFID_C2S
{ {
Init(); Init();
systemrun = true; systemrun = true;
iomonitorrun = true; if (Automode)
iomonitorThread = new Thread(new ThreadStart(iomonitor)); {
iomonitorThread.Start(); iomonitorrun = true;
iomonitorThread = new Thread(new ThreadStart(iomonitor));
iomonitorThread.Start();
}
ConnectionState_Event?.Invoke(this, true); ConnectionState_Event?.Invoke(this, true);
return true; return true;
} }
...@@ -81,11 +85,11 @@ public class PuYueRFID_C2S ...@@ -81,11 +85,11 @@ public class PuYueRFID_C2S
void Init() void Init()
{ {
//0设备地址,1波特率,2蜂鸣器状态,4天线盘存次数,6工作模式,7操作标签模式,8盘存标签超时时间,9自动触发间隔时间,10配置自动输出格式,11ASCII数据帧帧头,12标签记录保存时间
short[] value = new short[] { 1, 2, 1, 0, 1, 0, 1, 2, 20, 20, 0x81, 0x1234, 20 };
//设备地址1,波特率,禁止AFI,盘点超时时间(100*5ms),命令触发,操作模式,寄存器地址,寄存器数量,触发时间(10*5ms),输出格式,数据帧枕头,记录保持时间(9*5ms) //设备地址1,波特率,禁止AFI,盘点超时时间(100*5ms),命令触发,操作模式,寄存器地址,寄存器数量,触发时间(10*5ms),输出格式,数据帧枕头,记录保持时间(9*5ms)
short[] address = new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; short[] address = new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
//short[] value = new short[] { 1, 2, 0, 100, 1, 1, 0x20, 4, 20, 1, 0x1234, 19 }; short[] value = new short[] { 1, 2, 0, 100, 1, 1, 0x20, 4, 20, 1, 0x1234, 19 };
for (int i = 0; i < address.Length; i++) for (int i = 0; i < address.Length; i++)
{ {
WriteDO(address[i], value[i]); WriteDO(address[i], value[i]);
...@@ -335,6 +339,7 @@ public class PuYueRFID_C2S ...@@ -335,6 +339,7 @@ public class PuYueRFID_C2S
} }
catch catch
{ {
Open();
return -1; return -1;
} }
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
public class PuYueRFID_FR540SP_C2S
{
byte station = 1;
bool Automode;
public string IP;
TcpClient tcpClient = new TcpClient();
Thread iomonitorThread;
ushort seq = 0;
public event EventHandler<string> ID_Changed_Event;
/// <summary>
/// 连接状态变化, 手动连接不触发
/// </summary>
public event EventHandler<bool> ConnectionState_Event;
public PuYueRFID_FR540SP_C2S(string ip, bool automode = false)
{
this.IP = ip;
Automode = automode;
//DOdata[0] = 0x00;
//DOdata[1] = 0x00;
//if (autoread)
// iomonitorThread = new Thread(new ThreadStart(iomonitor));
}
/// <summary>
/// 销毁
/// </summary>
~PuYueRFID_FR540SP_C2S()
{
iomonitorrun = false;
Close();
}
bool systemrun = false;
/// <summary>
/// 打开IO
/// </summary>
/// <returns></returns>
public bool Open()
{
tcpClient.Dispose();
tcpClient = new TcpClient();
tcpClient.ReceiveTimeout = 1000;
tcpClient.SendTimeout = 100;
lock (tcpClient)
{
try
{
var connectResult = tcpClient.ConnectAsync(IP, 502);
if (connectResult.Wait(1000))
{
Init();
systemrun = true;
if (Automode)
{
iomonitorrun = true;
iomonitorThread = new Thread(new ThreadStart(iomonitor));
iomonitorThread.Start();
}
ConnectionState_Event?.Invoke(this, true);
return true;
}
else
{
tcpClient.EndConnect(connectResult);
tcpClient.Close();
return false;
}
}
catch
{
return false;
}
}
}
void Init()
{
//0设备地址,1波特率,2蜂鸣器状态,4天线盘存次数,6工作模式,7操作标签模式,8盘存标签超时时间,9自动触发间隔时间,10配置自动输出格式,11ASCII数据帧帧头,12标签记录保存时间
short[] value = new short[] { 1, 2, 1, 0, 1, 0, 1, 2, 20, 20, 0x81, 0x1234, 20 };
//设备地址1,波特率,禁止AFI,盘点超时时间(100*5ms),命令触发,操作模式,寄存器地址,寄存器数量,触发时间(10*5ms),输出格式,数据帧枕头,记录保持时间(9*5ms)
short[] address = new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
//short[] value = new short[] { 1, 2, 0, 100, 1, 1, 0x20, 4, 20, 1, 0x1234, 19 };
for (int i = 0; i < address.Length; i++)
{
WriteDO(address[i], value[i]);
}
}
/// <summary>
/// 设置天线功率dBm
/// </summary>
public short AntennaPower
{
set{
if (this.IsConn)
WriteDO(0x0100, value);
}
}
/// <summary>
/// 关闭IO
/// </summary>
public void Close()
{
try
{
systemrun = false;
iomonitorrun = false;
if (tcpClient.Connected)
tcpClient.Close();
}
catch { }
}
/// <summary>
/// 连接状态
/// </summary>
public bool IsConn
{
get => iomonitorrun && systemrun && tcpClient.Connected;
}
bool iomonitorrun = false;
/// <summary>
/// 循环读全部IO
/// </summary>
void iomonitor()
{
iomonitorrun = true;
while (iomonitorrun && systemrun)
{
try
{
if (ID_Changed_Event != null)
ReadDO();
else
Thread.Sleep(1000);
}
catch (SocketException)
{
if (tcpClient.Connected)
tcpClient.Close();
ConnectionState_Event?.Invoke(this, false);
iomonitorrun = false;
}
}
if (systemrun)
{
do
{
Thread.Sleep(1000);
} while (systemrun && !Open());
}
}
/// <summary>
/// 写寄存器
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool WriteDO(short address, short value)
{
byte funCode = 0x10;
byte[] startAddress = BitConverter.GetBytes(address); //寄存器起始地址;
byte[] data = BitConverter.GetBytes(value); //寄存器起始地址;
byte startLength = 1;
var seqhead = BitConverter.GetBytes(seq);
byte[] by = new byte[]
{
//事物标识符
seqhead[0],
seqhead[1],
//协议标识符 固定值
0x00,
0x00,
//长度
0x00,
0x06,
//从站地址
station,
//功能码
funCode,
startAddress[1],//起始地址高位
startAddress[0], //起始地址低位
0x00,
startLength, //读个数
0x02,
data[1],
data[0]
};
by[5] = (byte)(by.Length - 6);
bool check = true;
lock (tcpClient)
{
try
{
seqadd();
tcpClient.Client.Send(by);
byte[] result = new byte[100];
var ulength = tcpClient.Client.Receive(result);
var newResult = result.ToList().Take(ulength).ToArray();
if (newResult[0] == seqhead[0] && newResult[1] == seqhead[1])
{
check = true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
/*
var newResult = result.ToList().Take(ulength).ToArray();
//输出报文
var output = string.Join(" ", newResult.Select(x => x.ToString("X2")));
*/
return check;
}
string currentID = "";
bool hasID = false;
DateTime currentIDdate = DateTime.MinValue;
string lastID = "";
/// <summary>
/// 读全部IO
/// </summary>
void ReadDO()
{
byte funCode = 0x03;
byte[] startAddress = BitConverter.GetBytes((short)0x0255);
byte startLength = 2;
var seqhead = BitConverter.GetBytes(seq);
byte[] by = new byte[]
{
//事物标识符
seqhead[0],
seqhead[1],
//协议标识符 固定值
0x00,
0x00,
//长度
0x00,
0x06,
//从站地址
station,
//功能码
funCode,
startAddress[1],
startAddress[0], //起始地址
0x00,
startLength, //读个数
};
by[5] = (byte)(by.Length - 6);
byte[] result = new byte[100];
int ulength = 0;
lock (tcpClient)
{
try
{
seqadd();
tcpClient.Client.Send(by);
Thread.Sleep(5);
ulength = tcpClient.Client.Receive(result);
}
catch (SocketException se)
{
throw se;
}
finally {
Thread.Sleep(20);
}
}
var newResult = result;//.ToList().Take(ulength).ToArray();
//aa = BitConverter.ToString(newResult);
//Console.WriteLine(aa);
if (newResult[0] == seqhead[0] && newResult[1] == seqhead[1])
{
if (newResult[7] == 0x03)
{
hasID = true;
currentID = (char)newResult[10] + newResult[11].ToString();
currentIDdate = DateTime.Now;
if (currentID != lastID)
{
ID_Changed_Event?.Invoke(this, currentID);
lastID = currentID;
}
}else if (newResult[7] == 0x83)
{
hasID = false;
}
}
else
{
Thread.Sleep(20);
if (tcpClient.Client.Available>0)
_ = tcpClient.Client.Receive(result);
}
//输出报文
//var output = string.Join(" ", newResult.Select(x => x.ToString("X2")));
}
/// <summary>
/// 读取rfid
/// </summary>
/// <param name="id">读取到的id</param>
/// <param name="ms">最后读到的时间ms</param>
/// <returns>读取成功状态-1读取失败,0没有读到,1读取成功</returns>
public int TryRead(out string id,out double ms) {
id = "";
ms = 0;
try
{
ReadDO();
id = lastID;
ms = (DateTime.Now - currentIDdate).TotalMilliseconds;
if (hasID)
return 1;
else
return 0;
}
catch
{
Open();
return -1;
}
}
public bool ReadByte(short address,short length,out byte[] data) {
if (length > 64)
throw new Exception("最大读取64个字节");
data = null;
byte funCode = 0x03;
byte[] startAddress = BitConverter.GetBytes(address);//0x0255
byte[] startLength = BitConverter.GetBytes((short)Math.Ceiling(length / 2d));//2
var seqhead = BitConverter.GetBytes(seq);
byte[] by = new byte[]
{
//事物标识符
seqhead[0],
seqhead[1],
//协议标识符 固定值
0x00,
0x00,
//长度
0x00,
0x06,
//从站地址
station,
//功能码
funCode,
startAddress[1],
startAddress[0], //起始地址
startLength[1],
startLength[0], //读个数
};
by[5] = (byte)(by.Length - 6);
byte[] result = new byte[1000];
int ulength = 0;
lock (tcpClient)
{
try
{
if (tcpClient.Client.Available > 0)
tcpClient.Client.Receive(result);
seqadd();
tcpClient.Client.Send(by);
Thread.Sleep(5);
ulength = tcpClient.Client.Receive(result);
}
catch (SocketException se)
{
return false;
}
}
var newResult = result.ToList().Take(ulength).ToList();
//aa = BitConverter.ToString(newResult);
//Console.WriteLine(aa);
if (newResult.Count>6 && newResult[0] == seqhead[0] && newResult[1] == seqhead[1])
{
if (newResult[7] == 0x03)
{
var recvlen = BitConverter.ToInt16(new byte[] { newResult[5], newResult[4] },0);
if ((recvlen + 6) <= newResult.Count) {
data= newResult.GetRange(9, recvlen-3).ToArray();
Console.WriteLine(BitConverter.ToString(newResult.ToArray()));
return true;
}
}
else if (newResult[7] == 0x83)
{
return false;
}
}
else
{
Thread.Sleep(20);
if (tcpClient.Client.Available > 0)
_ = tcpClient.Client.Receive(result);
}
return false;
}
/// <summary>
/// 写入字节最大 64字
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
/// <returns></returns>
public bool WriteByte(short address, byte[] data)
{
if (data.Length > 64)
throw new Exception("最大写入64个字节");
byte funCode = 0x10;
byte[] startAddress = BitConverter.GetBytes(address); //寄存器起始地址;
short registerlength=(short)Math.Ceiling(data.Length / 2d);
byte[] registerAddress = BitConverter.GetBytes(registerlength);
var seqhead = BitConverter.GetBytes(seq);
byte[] by = new byte[]
{
//事物标识符
seqhead[0],
seqhead[1],
//协议标识符 固定值
0x00,
0x00,
//长度
0x00,
0x06,
//从站地址
station,
//功能码
funCode,
startAddress[1],//起始地址高位
startAddress[0], //起始地址低位
registerAddress[1],
registerAddress[0], //寄存器数量
(byte)(registerlength * 2)
};
var ab = by.ToList();
ab.AddRange(data);
if (registerlength * 2 > data.Length)
{
ab.Add(0x0);
}
short datalength = (short)(ab.Count() - 6);
var dl = BitConverter.GetBytes(datalength);
ab[4] = dl[1];
ab[5] = dl[0];
by = ab.ToArray();
lock (tcpClient)
{
try
{
byte[] result = new byte[100];
if (tcpClient.Client.Available > 0)
tcpClient.Client.Receive(result);
seqadd();
tcpClient.Client.Send(by);
var ulength = tcpClient.Client.Receive(result);
var newResult = result.ToList().Take(ulength).ToArray();
if (newResult[0] == seqhead[0] && newResult[1] == seqhead[1])
{
Console.WriteLine(BitConverter.ToString(newResult));
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
}
void seqadd()
{
seq++;
if (seq >= ushort.MaxValue - 10)
seq = 0;
}
}
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
...@@ -44,6 +48,7 @@ ...@@ -44,6 +48,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="IPuYue.cs" /> <Compile Include="IPuYue.cs" />
<Compile Include="ModuleEnum.cs" /> <Compile Include="ModuleEnum.cs" />
<Compile Include="PuYueRFID_FR540SP_C2S.cs" />
<Compile Include="PuYueRFID_C2S.cs" /> <Compile Include="PuYueRFID_C2S.cs" />
<Compile Include="PuYue_FR540SP.cs" /> <Compile Include="PuYue_FR540SP.cs" />
<Compile Include="PuYue.cs" /> <Compile Include="PuYue.cs" />
......
...@@ -229,6 +229,71 @@ ...@@ -229,6 +229,71 @@
<param name="address"></param> <param name="address"></param>
<param name="value"></param> <param name="value"></param>
</member> </member>
<member name="E:PuYueRFID_FR540SP_C2S.ConnectionState_Event">
<summary>
连接状态变化, 手动连接不触发
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Finalize">
<summary>
销毁
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Open">
<summary>
打开IO
</summary>
<returns></returns>
</member>
<member name="P:PuYueRFID_FR540SP_C2S.AntennaPower">
<summary>
设置天线功率dBm
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Close">
<summary>
关闭IO
</summary>
</member>
<member name="P:PuYueRFID_FR540SP_C2S.IsConn">
<summary>
连接状态
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.iomonitor">
<summary>
循环读全部IO
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.WriteDO(System.Int16,System.Int16)">
<summary>
写寄存器
</summary>
<param name="address"></param>
<param name="value"></param>
<returns></returns>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.ReadDO">
<summary>
读全部IO
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.TryRead(System.String@,System.Double@)">
<summary>
读取rfid
</summary>
<param name="id">读取到的id</param>
<param name="ms">最后读到的时间ms</param>
<returns>读取成功状态-1读取失败,0没有读到,1读取成功</returns>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.WriteByte(System.Int16,System.Byte[])">
<summary>
写入字节最大 64字
</summary>
<param name="address"></param>
<param name="data"></param>
<returns></returns>
</member>
<member name="E:PuYueRFID_C2S.ConnectionState_Event"> <member name="E:PuYueRFID_C2S.ConnectionState_Event">
<summary> <summary>
连接状态变化, 手动连接不触发 连接状态变化, 手动连接不触发
......
此文件类型无法预览
此文件的差异太大,无法显示。
5644c7488f7eac6c22e01d03f244c400a4a0f511 edd42431a59bd4fbe4c83f05fb8307780e858553
...@@ -12,3 +12,6 @@ D:\rick\vs\RFID\RFID_PuYue\obj\Debug\RFID_PuYue.csproj.AssemblyReference.cache ...@@ -12,3 +12,6 @@ D:\rick\vs\RFID\RFID_PuYue\obj\Debug\RFID_PuYue.csproj.AssemblyReference.cache
D:\rick\vs\RFID\RFID_PuYue\obj\Debug\RFID_PuYue.csproj.CoreCompileInputs.cache D:\rick\vs\RFID\RFID_PuYue\obj\Debug\RFID_PuYue.csproj.CoreCompileInputs.cache
D:\rick\vs\RFID\RFID_PuYue\obj\Debug\Asa.RFID.PuYue.dll D:\rick\vs\RFID\RFID_PuYue\obj\Debug\Asa.RFID.PuYue.dll
D:\rick\vs\RFID\RFID_PuYue\obj\Debug\Asa.RFID.PuYue.pdb D:\rick\vs\RFID\RFID_PuYue\obj\Debug\Asa.RFID.PuYue.pdb
D:\rick\vs\RFID\RFID_PuYue\bin\Debug\log4net.dll
D:\rick\vs\RFID\RFID_PuYue\bin\Debug\log4net.xml
D:\rick\vs\RFID\RFID_PuYue\obj\Debug\RFID_PuYue.csproj.CopyComplete
...@@ -35,7 +35,6 @@ namespace RFID_PuYue_Debug ...@@ -35,7 +35,6 @@ namespace RFID_PuYue_Debug
this.BtnInit = new System.Windows.Forms.Button(); this.BtnInit = new System.Windows.Forms.Button();
this.BtnAutoMode = new System.Windows.Forms.Button(); this.BtnAutoMode = new System.Windows.Forms.Button();
this.BtnManual = new System.Windows.Forms.Button(); this.BtnManual = new System.Windows.Forms.Button();
this.CboLetter = new System.Windows.Forms.ComboBox();
this.NudNumber = new System.Windows.Forms.NumericUpDown(); this.NudNumber = new System.Windows.Forms.NumericUpDown();
this.BtnWrite = new System.Windows.Forms.Button(); this.BtnWrite = new System.Windows.Forms.Button();
this.LblMode = new System.Windows.Forms.Label(); this.LblMode = new System.Windows.Forms.Label();
...@@ -43,6 +42,7 @@ namespace RFID_PuYue_Debug ...@@ -43,6 +42,7 @@ namespace RFID_PuYue_Debug
this.LblRfid = new System.Windows.Forms.Label(); this.LblRfid = new System.Windows.Forms.Label();
this.ChkAutoAdd = new System.Windows.Forms.CheckBox(); this.ChkAutoAdd = new System.Windows.Forms.CheckBox();
this.TxtRead = new System.Windows.Forms.TextBox(); this.TxtRead = new System.Windows.Forms.TextBox();
this.textBox_start = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.NudNumber)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NudNumber)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -111,19 +111,10 @@ namespace RFID_PuYue_Debug ...@@ -111,19 +111,10 @@ namespace RFID_PuYue_Debug
this.BtnManual.UseVisualStyleBackColor = true; this.BtnManual.UseVisualStyleBackColor = true;
this.BtnManual.Click += new System.EventHandler(this.BtnManual_Click); this.BtnManual.Click += new System.EventHandler(this.BtnManual_Click);
// //
// CboLetter
//
this.CboLetter.Font = new System.Drawing.Font("宋体", 11F);
this.CboLetter.FormattingEnabled = true;
this.CboLetter.Location = new System.Drawing.Point(178, 84);
this.CboLetter.Name = "CboLetter";
this.CboLetter.Size = new System.Drawing.Size(77, 23);
this.CboLetter.TabIndex = 6;
//
// NudNumber // NudNumber
// //
this.NudNumber.Font = new System.Drawing.Font("宋体", 10F); this.NudNumber.Font = new System.Drawing.Font("宋体", 10F);
this.NudNumber.Location = new System.Drawing.Point(261, 84); this.NudNumber.Location = new System.Drawing.Point(279, 84);
this.NudNumber.Maximum = new decimal(new int[] { this.NudNumber.Maximum = new decimal(new int[] {
255, 255,
0, 0,
...@@ -135,7 +126,7 @@ namespace RFID_PuYue_Debug ...@@ -135,7 +126,7 @@ namespace RFID_PuYue_Debug
0, 0,
0}); 0});
this.NudNumber.Name = "NudNumber"; this.NudNumber.Name = "NudNumber";
this.NudNumber.Size = new System.Drawing.Size(77, 23); this.NudNumber.Size = new System.Drawing.Size(59, 23);
this.NudNumber.TabIndex = 7; this.NudNumber.TabIndex = 7;
this.NudNumber.Value = new decimal(new int[] { this.NudNumber.Value = new decimal(new int[] {
1, 1,
...@@ -213,19 +204,27 @@ namespace RFID_PuYue_Debug ...@@ -213,19 +204,27 @@ namespace RFID_PuYue_Debug
this.TxtRead.Size = new System.Drawing.Size(308, 202); this.TxtRead.Size = new System.Drawing.Size(308, 202);
this.TxtRead.TabIndex = 13; this.TxtRead.TabIndex = 13;
// //
// textBox_start
//
this.textBox_start.Location = new System.Drawing.Point(178, 84);
this.textBox_start.Name = "textBox_start";
this.textBox_start.Size = new System.Drawing.Size(95, 21);
this.textBox_start.TabIndex = 14;
this.textBox_start.Text = "AA0000";
//
// FrmMain // FrmMain
// //
this.AcceptButton = this.BtnWrite; this.AcceptButton = this.BtnWrite;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(664, 226); this.ClientSize = new System.Drawing.Size(664, 226);
this.Controls.Add(this.textBox_start);
this.Controls.Add(this.TxtRead); this.Controls.Add(this.TxtRead);
this.Controls.Add(this.ChkAutoAdd); this.Controls.Add(this.ChkAutoAdd);
this.Controls.Add(this.LblRfid); this.Controls.Add(this.LblRfid);
this.Controls.Add(this.BtnRead); this.Controls.Add(this.BtnRead);
this.Controls.Add(this.LblMode); this.Controls.Add(this.LblMode);
this.Controls.Add(this.BtnWrite); this.Controls.Add(this.BtnWrite);
this.Controls.Add(this.CboLetter);
this.Controls.Add(this.NudNumber); this.Controls.Add(this.NudNumber);
this.Controls.Add(this.BtnAutoMode); this.Controls.Add(this.BtnAutoMode);
this.Controls.Add(this.BtnManual); this.Controls.Add(this.BtnManual);
...@@ -254,7 +253,6 @@ namespace RFID_PuYue_Debug ...@@ -254,7 +253,6 @@ namespace RFID_PuYue_Debug
private System.Windows.Forms.Button BtnInit; private System.Windows.Forms.Button BtnInit;
private System.Windows.Forms.Button BtnAutoMode; private System.Windows.Forms.Button BtnAutoMode;
private System.Windows.Forms.Button BtnManual; private System.Windows.Forms.Button BtnManual;
private System.Windows.Forms.ComboBox CboLetter;
private System.Windows.Forms.NumericUpDown NudNumber; private System.Windows.Forms.NumericUpDown NudNumber;
private System.Windows.Forms.Button BtnWrite; private System.Windows.Forms.Button BtnWrite;
private System.Windows.Forms.Label LblMode; private System.Windows.Forms.Label LblMode;
...@@ -262,6 +260,7 @@ namespace RFID_PuYue_Debug ...@@ -262,6 +260,7 @@ namespace RFID_PuYue_Debug
private System.Windows.Forms.Label LblRfid; private System.Windows.Forms.Label LblRfid;
private System.Windows.Forms.CheckBox ChkAutoAdd; private System.Windows.Forms.CheckBox ChkAutoAdd;
private System.Windows.Forms.TextBox TxtRead; private System.Windows.Forms.TextBox TxtRead;
private System.Windows.Forms.TextBox textBox_start;
} }
} }
...@@ -44,11 +44,11 @@ namespace RFID_PuYue_Debug ...@@ -44,11 +44,11 @@ namespace RFID_PuYue_Debug
private void FrmMain_Load(object sender, EventArgs e) private void FrmMain_Load(object sender, EventArgs e)
{ {
string[] letter = new string[26]; //string[] letter = new string[26];
for (int i = 0; i < letter.Length; i++) //for (int i = 0; i < letter.Length; i++)
letter[i] = ((char)(65 + i)).ToString(); // letter[i] = ((char)(65 + i)).ToString();
CboLetter.Items.AddRange(letter); //CboLetter.Items.AddRange(letter);
CboLetter.SelectedIndex = 0; //CboLetter.SelectedIndex = 0;
Frm_moduleselect frm_Moduleselect = new Frm_moduleselect(); Frm_moduleselect frm_Moduleselect = new Frm_moduleselect();
frm_Moduleselect.ShowDialog(); frm_Moduleselect.ShowDialog();
if (frm_Moduleselect.Module == Asa.RFID.ModuleEnum.FR540SP) if (frm_Moduleselect.Module == Asa.RFID.ModuleEnum.FR540SP)
...@@ -114,8 +114,12 @@ namespace RFID_PuYue_Debug ...@@ -114,8 +114,12 @@ namespace RFID_PuYue_Debug
private void BtnWrite_Click(object sender, EventArgs e) private void BtnWrite_Click(object sender, EventArgs e)
{ {
string id = CboLetter.Text + NudNumber.Value; var format = textBox_start.Text;
bool rtn = rfid.WriteData(id); var nf = format.TrimEnd('0');
var num = format.Substring(nf.Length);
string id = nf + NudNumber.Value.ToString(num);
bool rtn = rfid.WriteData(Encoding.ASCII.GetBytes(id));
if (rtn) if (rtn)
{ {
LblRfid.Text = "Write:" + id; LblRfid.Text = "Write:" + id;
...@@ -128,7 +132,7 @@ namespace RFID_PuYue_Debug ...@@ -128,7 +132,7 @@ namespace RFID_PuYue_Debug
private void BtnRead_Click(object sender, EventArgs e) private void BtnRead_Click(object sender, EventArgs e)
{ {
bool rtn = rfid.ReadData(out string id); bool rtn = rfid.ReadData(out string id,20);
if (rtn) if (rtn)
LblRfid.Text = "Read:" + id; LblRfid.Text = "Read:" + id;
else else
......
...@@ -229,11 +229,81 @@ ...@@ -229,11 +229,81 @@
<param name="address"></param> <param name="address"></param>
<param name="value"></param> <param name="value"></param>
</member> </member>
<member name="E:PuYueRFID_FR540SP_C2S.ConnectionState_Event">
<summary>
连接状态变化, 手动连接不触发
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Finalize">
<summary>
销毁
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Open">
<summary>
打开IO
</summary>
<returns></returns>
</member>
<member name="P:PuYueRFID_FR540SP_C2S.AntennaPower">
<summary>
设置天线功率dBm
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.Close">
<summary>
关闭IO
</summary>
</member>
<member name="P:PuYueRFID_FR540SP_C2S.IsConn">
<summary>
连接状态
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.iomonitor">
<summary>
循环读全部IO
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.WriteDO(System.Int16,System.Int16)">
<summary>
写寄存器
</summary>
<param name="address"></param>
<param name="value"></param>
<returns></returns>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.ReadDO">
<summary>
读全部IO
</summary>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.TryRead(System.String@,System.Double@)">
<summary>
读取rfid
</summary>
<param name="id">读取到的id</param>
<param name="ms">最后读到的时间ms</param>
<returns>读取成功状态-1读取失败,0没有读到,1读取成功</returns>
</member>
<member name="M:PuYueRFID_FR540SP_C2S.WriteByte(System.Int16,System.Byte[])">
<summary>
写入字节最大 64字
</summary>
<param name="address"></param>
<param name="data"></param>
<returns></returns>
</member>
<member name="E:PuYueRFID_C2S.ConnectionState_Event"> <member name="E:PuYueRFID_C2S.ConnectionState_Event">
<summary> <summary>
连接状态变化, 手动连接不触发 连接状态变化, 手动连接不触发
</summary> </summary>
</member> </member>
<member name="M:PuYueRFID_C2S.Finalize">
<summary>
销毁
</summary>
</member>
<member name="M:PuYueRFID_C2S.Open"> <member name="M:PuYueRFID_C2S.Open">
<summary> <summary>
打开IO 打开IO
...@@ -281,5 +351,13 @@ ...@@ -281,5 +351,13 @@
<param name="ms">最后读到的时间ms</param> <param name="ms">最后读到的时间ms</param>
<returns>读取成功状态-1读取失败,0没有读到,1读取成功</returns> <returns>读取成功状态-1读取失败,0没有读到,1读取成功</returns>
</member> </member>
<member name="M:PuYueRFID_C2S.WriteByte(System.Int16,System.Byte[])">
<summary>
写入字节最大 64字
</summary>
<param name="address"></param>
<param name="data"></param>
<returns></returns>
</member>
</members> </members>
</doc> </doc>
此文件类型无法预览
[2021-06-18 13:03:48,977][1][HiStation:60]INFO =====Init=====
[2021-03-18 15:15:53,132][1][HiStation:60]INFO =====Init=====
[2021-04-09 19:08:02,697][1][HiStation:60]INFO =====Init=====
[2021-06-17 10:01:00,549][1][HiStation:60]INFO =====Init=====
...@@ -34,6 +34,7 @@ namespace Test ...@@ -34,6 +34,7 @@ namespace Test
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBox1 // textBox1
...@@ -70,12 +71,23 @@ namespace Test ...@@ -70,12 +71,23 @@ namespace Test
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// button3
//
this.button3.Location = new System.Drawing.Point(87, 367);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(567, 450); this.ClientSize = new System.Drawing.Size(567, 450);
this.Controls.Add(this.button2); this.Controls.Add(this.button2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1); this.Controls.Add(this.textBox1);
this.Name = "Form1"; this.Name = "Form1";
...@@ -93,6 +105,7 @@ namespace Test ...@@ -93,6 +105,7 @@ namespace Test
private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
} }
} }
...@@ -103,5 +103,33 @@ namespace Test ...@@ -103,5 +103,33 @@ namespace Test
} }
textBox1.Text += Encoding.ASCII.GetString(data); textBox1.Text += Encoding.ASCII.GetString(data);
} }
private void button3_Click(object sender, EventArgs e)
{
i++;
txtdata += i.ToString();
var d = Encoding.ASCII.GetBytes(txtdata);
byte[] data;
while (!py.ReadByte(0x200, 1, out data))
{
textBox1.Text += "1";
Thread.Sleep(100);
}
textBox1.Text = "get tag;";
while (!py.WriteByte(0x20, d))
{
textBox1.Text += "e";
Thread.Sleep(100);
}
Thread.Sleep(500);
while (!py.ReadByte(0x255, (short)d.Length, out data))
{
textBox1.Text += "1";
Thread.Sleep(100);
}
textBox1.Text += Encoding.ASCII.GetString(data);
}
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!