|
|
@ -23,6 +23,41 @@ namespace DyeingComputer.UserClass |
|
|
|
/// </summary>
|
|
|
|
public class AsyncTcpServer |
|
|
|
{ |
|
|
|
//设置系统时间的API函数
|
|
|
|
[DllImport("kernel32.dll")] |
|
|
|
private static extern bool SetLocalTime(ref SYSTEMTIME time); |
|
|
|
[StructLayout(LayoutKind.Sequential)] |
|
|
|
private struct SYSTEMTIME |
|
|
|
{ |
|
|
|
public short year; |
|
|
|
public short month; |
|
|
|
public short dayOfWeek; |
|
|
|
public short day; |
|
|
|
public short hour; |
|
|
|
public short minute; |
|
|
|
public short second; |
|
|
|
public short milliseconds; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 设置系统时间
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dt">需要设置的时间</param>
|
|
|
|
/// <returns>返回系统时间设置状态,true为成功,false为失败</returns>
|
|
|
|
private static bool SetLocalDateTime(DateTime dt) |
|
|
|
{ |
|
|
|
SYSTEMTIME st; |
|
|
|
st.year = (short)dt.Year; |
|
|
|
st.month = (short)dt.Month; |
|
|
|
st.dayOfWeek = (short)dt.DayOfWeek; |
|
|
|
st.day = (short)dt.Day; |
|
|
|
st.hour = (short)dt.Hour; |
|
|
|
st.minute = (short)dt.Minute; |
|
|
|
st.second = (short)dt.Second; |
|
|
|
st.milliseconds = (short)dt.Millisecond; |
|
|
|
bool rt = SetLocalTime(ref st); |
|
|
|
return rt; |
|
|
|
} |
|
|
|
|
|
|
|
public static async Task Main() |
|
|
|
{ |
|
|
|
TcpService service = new TcpService(); |
|
|
@ -33,21 +68,29 @@ namespace DyeingComputer.UserClass |
|
|
|
service.Received = (client, e) => |
|
|
|
{ |
|
|
|
string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0,5); |
|
|
|
LogGing.LogSQLDATA("800", "TcpServer", "API:"+ SYSAPI); |
|
|
|
string SYSDAT = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5); |
|
|
|
//LogGing.LogSQLDATA("800", "TcpServer", "API:"+ SYSAPI);
|
|
|
|
if (SYSAPI == "SC800") client.SendAsync(MainWindowViewModel.S01); |
|
|
|
if (SYSAPI == "SC801") client.SendAsync(MainWindowViewModel.S16.ToString()); |
|
|
|
if (SYSAPI == "SC802") client.SendAsync(MainWindowViewModel.S03); |
|
|
|
if (SYSAPI == "SC803") client.SendAsync(MainWindowViewModel.S05); |
|
|
|
if (SYSAPI == "SC804") client.SendAsync(MainWindowViewModel.S06); |
|
|
|
if (SYSAPI == "SC810") |
|
|
|
else if (SYSAPI == "SC801") client.SendAsync(MainWindowViewModel.S16.ToString()); |
|
|
|
else if (SYSAPI == "SC802") client.SendAsync(MainWindowViewModel.S03); |
|
|
|
else if (SYSAPI == "SC803") client.SendAsync(MainWindowViewModel.S05); |
|
|
|
else if (SYSAPI == "SC804") client.SendAsync(MainWindowViewModel.S06); |
|
|
|
else if (SYSAPI == "SC810") |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
if (SYSAPI == "SC820") |
|
|
|
else if (SYSAPI == "SC820") |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
if (SYSAPI == "SC830")//当前信息
|
|
|
|
if (SYSDAT.Length == 21) |
|
|
|
{ |
|
|
|
SYSDAT = SYSDAT.Substring(1,19); |
|
|
|
DateTime dt; |
|
|
|
if(DateTime.TryParse(SYSDAT,out dt)) |
|
|
|
SetLocalDateTime(dt); |
|
|
|
} |
|
|
|
client.SendAsync("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")+"]"); |
|
|
|
}//设置系统时间
|
|
|
|
else if (SYSAPI == "SC830") |
|
|
|
{ |
|
|
|
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
|
|
|
|
Chart_new.Add("DYELOT", MainWindowViewModel.WorkNumder); |
|
|
@ -63,11 +106,20 @@ namespace DyeingComputer.UserClass |
|
|
|
Chart_new.Add("STLB", MainWindowViewModel.Selet_dtm("1018")); |
|
|
|
Chart_new.Add("STTC", MainWindowViewModel.Selet_dtm("1014")); |
|
|
|
Chart_new.Add("STLC", MainWindowViewModel.Selet_dtm("1019")); |
|
|
|
client.SendAsync(Chart_new.ToJsonString()); |
|
|
|
} |
|
|
|
if (SYSAPI == "SC851") client.SendAsync(MainWindowViewModel.dt_d.ToJsonString());//数字开关信息
|
|
|
|
if (SYSAPI == "SC852") client.SendAsync(MainWindowViewModel.dt_a.ToJsonString());//寄存器信息
|
|
|
|
if (SYSAPI == "SC853") client.SendAsync(MainWindowViewModel.dt_m.ToJsonString());//缓存信息
|
|
|
|
client.SendAsync("["+ MainWindowViewModel.S01 + "]"+Chart_new.ToJsonString()); |
|
|
|
}//当前信息
|
|
|
|
else if (SYSAPI == "SC851") |
|
|
|
{ |
|
|
|
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_d.ToJsonString());//数字开关信息
|
|
|
|
}//数字开关表
|
|
|
|
else if (SYSAPI == "SC852") |
|
|
|
{ |
|
|
|
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_a.ToJsonString());//寄存器信息
|
|
|
|
}//寄存器表
|
|
|
|
else if (SYSAPI == "SC853") |
|
|
|
{ |
|
|
|
client.SendAsync("[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_m.ToJsonString());//缓存信息
|
|
|
|
}//缓存表
|
|
|
|
|
|
|
|
return EasyTask.CompletedTask; |
|
|
|
}; |
|
|
|