@ -4,6 +4,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq ;
using OpenTK.Graphics.ES11 ;
using ScottPlot.Palettes ;
using ScottPlot.TickGenerators.TimeUnits ;
using SunlightCentralizedControlManagement_SCCM_.EX.Exchange ;
using SunlightCentralizedControlManagement_SCCM_.Properties ;
using SunlightCentralizedControlManagement_SCCM_.UserClass ;
@ -26,6 +27,7 @@ using System.Threading;
using System.Threading.Tasks ;
using System.Timers ;
using System.Windows.Controls ;
using System.Windows.Documents ;
using System.Windows.Forms ;
using System.Windows.Markup ;
using System.Windows.Media ;
@ -38,8 +40,6 @@ using static MaterialDesignThemes.Wpf.Theme;
using static SunlightCentralizedControlManagement_SCCM_ . UserClass . SqliteHelper ;
using static SunlightCentralizedControlManagement_SCCM_ . View . MachinesView ;
using static SunlightCentralizedControlManagement_SCCM_ . ViewModel . ManualDyelotModel ;
using static System . Net . WebRequestMethods ;
using static System . Windows . Forms . AxHost ;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
@ -78,7 +78,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static string SN_KEY ;
public static bool DyelotsDispenser ;
public static SqlConnection conn_SC = new SqlConnection ( ) ; //数据库
private SQLiteHelper SQLiteHelpers = null ; //定义数据库
public static SQLiteHelper SQLiteHelpers = null ; //定义数据库
private BDC_SQL . BDCSqlHelper bDCSqlHelper = new BDC_SQL . BDCSqlHelper ( ) ;
private readonly string DBAddress = Environment . CurrentDirectory + "\\DataBase\\SCCM.db" ; //数据库路径
public static DataTable Machines = new DataTable ( ) ; //设备表缓存
@ -86,7 +86,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static DataTable USER_data = new DataTable ( ) ;
public static DataTable Dyelot_CALL = new DataTable ( ) ;
public static DataTable Whole_dat = new DataTable ( ) ;
public static UserControls . info [ ] inf = new UserControls . info [ 9 9 9 ] ; //定义总览信息卡
public static UserControls . info [ ] inf = new UserControls . info [ 2 0 0 ] ; //定义总览信息卡
public static int ERR_c = 0 ; //错误计数器
public bool UPort1 , UPort2 , UPort3 ;
public static bool [ ] USER_Capacity { set ; get ; } = new bool [ 9 9 ] ;
@ -111,19 +111,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
Machines = SQLiteHelpers . ExecuteDataSet ( "select * from Machines Order by id" , null ) . Tables [ 0 ] ; //读取表写入缓存
USER_data = SQLiteHelpers . ExecuteDataSet ( "select * from USER order by Name desc" , null ) . Tables [ 0 ] ;
Dyelot_CALL = SQLiteHelpers . ExecuteDataSet ( "select * from Dyelot" , null ) . Tables [ 0 ] . Clone ( ) ;
SQLiteHelpers . Close ( ) ;
Whole_dat . Columns . Add ( "Machine" , Type . GetType ( "System.String" ) ) ;
Whole_dat . Columns . Add ( "DateTime" , Type . GetType ( "System.DateTime" ) ) ;
Whole_dat . Columns . Add ( "DAT" , Type . GetType ( "System.Double" ) ) ;
USERCapacity ( App . USER_Purview ) ; //App.USER_Purview);
UPort ( ) ; //启动串口
CountDown ( ) ;
USERCapacity ( App . USER_Purview ) ; //App.USER_Purview);
ClientNEW ( ) ;
TcpClientNEW ( ) ;
PortClientNEW ( ) ;
SQL_LINK ( ) ;
CountDown ( ) ;
}
public static void USERCapacity ( string user ) //权限
{
@ -150,148 +148,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
public static SerialPort port1 = new SerialPort ( ) ; //创建串口
public static SerialPort port2 = new SerialPort ( ) ; //创建串口
public static SerialPort port3 = new SerialPort ( ) ; //创建串口
void UPort ( )
{
try
{
int Ba = 9 6 0 0 ;
try { Ba = Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD1" ) ) ; }
catch ( Exception ) { Ba = 9 6 0 0 ; }
port1 . PortName = Configini . IniReadvalue ( "SYS" , "COMP1" ) ;
port1 . BaudRate = Ba ; //配置
port1 . DataBits = 8 ;
port1 . Parity = Parity . Even ;
port1 . StopBits = StopBits . One ;
port1 . ReadTimeout = 5 0 0 ;
port1 . WriteTimeout = 5 0 0 ;
port1 . Encoding = Encoding . GetEncoding ( "ASCII" ) ;
port1 . Open ( ) ; //打开串口
port1 . DataReceived + = new SerialDataReceivedEventHandler ( SerialPort1_DataReceived ) ;
UPort1 = true ;
}
catch ( Exception e )
{
UPort1 = false ;
LogGing . LogGingDATA ( e . Message ) ;
}
try
{
int Ba2 = 9 6 0 0 ;
try { Ba2 = Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD1" ) ) ; }
catch ( Exception ) { Ba2 = 9 6 0 0 ; }
port2 . PortName = Configini . IniReadvalue ( "SYS" , "COMP2" ) ;
port2 . BaudRate = Ba2 ; //配置
port2 . DataBits = 8 ;
port2 . Parity = Parity . Even ;
port2 . StopBits = StopBits . One ;
port2 . ReadTimeout = 5 0 0 ;
port2 . WriteTimeout = 5 0 0 ;
port2 . Encoding = Encoding . GetEncoding ( "ASCII" ) ;
port2 . Open ( ) ; //打开串口
port2 . DataReceived + = new SerialDataReceivedEventHandler ( SerialPort2_DataReceived ) ;
UPort2 = true ;
}
catch ( Exception e )
{
UPort2 = false ;
LogGing . LogGingDATA ( e . Message ) ;
}
try
{
int Ba3 = 9 6 0 0 ;
try { Ba3 = Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD1" ) ) ; }
catch ( Exception ) { Ba3 = 9 6 0 0 ; }
port3 . PortName = Configini . IniReadvalue ( "SYS" , "COMP3" ) ;
port3 . BaudRate = Ba3 ; //配置
port3 . DataBits = 8 ;
port3 . Parity = Parity . Even ;
port3 . StopBits = StopBits . One ;
port3 . ReadTimeout = 5 0 0 ;
port3 . WriteTimeout = 5 0 0 ;
port3 . Encoding = Encoding . GetEncoding ( "ASCII" ) ;
port3 . Open ( ) ; //打开串口
port3 . DataReceived + = new SerialDataReceivedEventHandler ( SerialPort3_DataReceived ) ;
UPort3 = true ;
}
catch ( Exception e )
{
UPort3 = false ;
LogGing . LogGingDATA ( e . Message ) ;
}
} //ck
// 事件处理函数
private void SerialPort1_DataReceived ( object sender , SerialDataReceivedEventArgs e )
{
int bytesToRead = port1 . BytesToRead ;
byte [ ] buffer = new byte [ bytesToRead ] ;
port1 . Read ( buffer , 0 , bytesToRead ) ; // 读取数据
// 将字节数据转换为字符串(注意编码方式)
string receivedData = Encoding . ASCII . GetString ( buffer ) ; // 根据实际情况调整编码
} // 事件处理函数
private void SerialPort2_DataReceived ( object sender , SerialDataReceivedEventArgs e )
{
int bytesToRead = port2 . BytesToRead ;
byte [ ] buffer = new byte [ bytesToRead ] ;
port2 . Read ( buffer , 0 , bytesToRead ) ; // 读取数据
// 将字节数据转换为字符串(注意编码方式)
string receivedData = Encoding . ASCII . GetString ( buffer ) ; // 根据实际情况调整编码
} // 事件处理函数
private void SerialPort3_DataReceived ( object sender , SerialDataReceivedEventArgs e )
{
int bytesToRead = port3 . BytesToRead ;
byte [ ] buffer = new byte [ bytesToRead ] ;
port3 . Read ( buffer , 0 , bytesToRead ) ; // 读取数据
// 将字节数据转换为字符串(注意编码方式)
string receivedData = Encoding . ASCII . GetString ( buffer ) ; // 根据实际情况调整编码
}
private async void Port_link ( )
{
await Task . Run ( ( ) = >
{
try
{
if ( stringQueueSerial . Count > 0 ) //信息发送队列
{
QueueSerial t = stringQueueSerial . Dequeue ( ) ;
if ( t . ID = = "PORT1" )
{
if ( UPort1 )
{
port1 . Write ( t . DAT ) ;
}
}
else if ( t . ID = = "PORT2" )
{
if ( UPort2 )
{
port2 . Write ( t . DAT ) ;
}
}
else if ( t . ID = = "PORT3" )
{
if ( UPort3 )
{
port3 . Write ( t . DAT ) ;
}
}
}
}
catch ( Exception ex )
{
}
finally
{
Port_link ( ) ;
}
} ) ;
} //发送
public async void SQL_LINK ( ) //连接dbc数据库
{
if ( conn_SC . State = = ConnectionState . Open ) conn_SC . Close ( ) ;
@ -342,7 +199,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
int Time5 = 0 , Time30 = 0 ;
void DisTimer_50MS ( object sender , EventArgs e ) //Tick_Event周期执行事件50MS
{
int _ id = - 1 ;
int _ id = - 1 ;
if ( stringQueue . Count > 0 ) //信息发送队列
{
QueueString t = stringQueue . Dequeue ( ) ;
@ -354,13 +211,16 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
QueueString inf = stringQueueinf . Dequeue ( ) ;
if ( _ id ! = inf . ID ) MachiensTcpClient [ inf . ID ] . SendAsync ( inf . DAT ) ;
}
/ * if ( stringQueueSerial . Count > 0 ) //ck信息发送队列
{
QueueSerial t = stringQueueSerial . Dequeue ( ) ;
MachiensPortClient [ t . ID ] . Send ( t . DAT ) ;
} * /
}
void Tick_Main_1S ( object sender , EventArgs e ) //Tick_Event周期执行事件1S
{
/*下传工单信息*/
SQLiteHelper WorkOrderSQL = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
WorkOrderSQL . Open ( ) ; //打开数据库
DataTable WorkOrderstepdata = WorkOrderSQL . ExecuteDataSet ( "select * from WorkOrder where (State='111' or State='112') AND EndTime >'" +
DataTable WorkOrderstepdata = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrder where (State='111' or State='112') AND EndTime >'" +
DateTime . Now . AddHours ( - 8 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) + "'" , null ) . Tables [ 0 ] ; //读取表写入缓存
for ( int k = 0 ; k < WorkOrderstepdata . Rows . Count ; k + + )
{ //网络
@ -369,7 +229,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
if ( Convert . ToBoolean ( Selet_Machines ( Machines , "Type" , "Name='" + WorkOrderdata_m + "'" ) ) )
{
//string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field<object>("Machines").ToString();
DataTable dataTable = WorkOrder SQL. ExecuteDataSet ( "select * from WorkorderSteps where WorkOrder='" +
DataTable dataTable = SQLiteHelpers . ExecuteDataSet ( "select * from WorkorderSteps where WorkOrder='" +
WorkOrderstepdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) . Tables [ 0 ] ;
int index = Convert . ToInt16 ( Selet_Machines ( Machines , "ID" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) ) ;
stringQueue . Enqueue ( new QueueString
@ -377,7 +237,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
ID = index ,
DAT = "SC811" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + dataTable . ToJsonString ( )
} ) ;
WorkOrder SQL. Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 2 } } ,
SQLiteHelpers . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 2 } } ,
"WorkOrder ='" + WorkOrderstepdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
}
else
@ -386,7 +246,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
/*下传工单总览*/
DataTable WorkOrderdata = WorkOrder SQL. ExecuteDataSet ( "select * from WorkOrder where (State='100' or State='110') AND EndTime >'" +
DataTable WorkOrderdata = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrder where (State='100' or State='110') AND EndTime >'" +
DateTime . Now . AddHours ( - 8 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) + "'" , null ) . Tables [ 0 ] ; //读取表写入缓存
for ( int k = 0 ; k < WorkOrderdata . Rows . Count ; k + + )
{
@ -412,8 +272,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
ID = index ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
WorkOrder SQL. Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
} ) ;
SQLiteHelpers . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
"WorkOrder ='" + WorkOrderdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
}
}
@ -421,7 +281,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{ //串口
//string WorkOrderdata_m = WorkOrderdata.Select()[k].Field<object>("Machines").ToString();
string State = Selet_Machines ( Machines , "State" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) ;
string POR = Selet_Machines ( Machines , "Serial" , "ID='" + k + "'" ) . ToString ( ) ;
if ( ( State = = "101" ) | | ( State = = "201" ) | | ( State = = "202" ) | | ( State = = "309" ) )
{
@ -434,18 +293,46 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dataTable . Rows . Add ( dt_temp . ItemArray ) ;
int index = Convert . ToInt16 ( Selet_Machines ( Machines , "ID" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) ) ;
stringQueueSerial . Enqueue ( new QueueSerial
if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) = = "PORT1" )
{
ID = POR ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
WorkOrderSQL . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
"WorkOrder ='" + WorkOrderdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) = = "PORT2" )
{
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) = = "PORT3" )
{
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderdata_m + "'" ) . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC810" + Selet_Machines ( Machines , "SYSKEY" , "ID='" + index + "'" ) + DataTableToDictionary ( dataTable ) . ToJsonString ( )
} ) ;
}
SQLiteHelpers . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
"WorkOrder ='" + WorkOrderdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
}
}
}
/*下传工单设置*/
DataTable WorkOrderset_ = WorkOrderSQL . ExecuteDataSet ( "select * from WorkOrder where State='113' AND EndTime >'" +
DataTable WorkOrderset_ = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrder where State='113' AND EndTime >'" +
DateTime . Now . AddHours ( - 8 ) . ToString ( "yyyy/MM/dd HH:mm:ss" ) + "'" , null ) . Tables [ 0 ] ; //读取表写入缓存
for ( int k = 0 ; k < WorkOrderset_ . Rows . Count ; k + + )
{
@ -457,7 +344,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
string WorkOrderset_w = WorkOrderset_ . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) ;
int index = Convert . ToInt16 ( Selet_Machines ( Machines , "ID" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) ) ;
DataTable WorkOrder_set = WorkOrder SQL. ExecuteDataSet ( "select * from WorkOrderSet where WorkOrder='" +
DataTable WorkOrder_set = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrderSet where WorkOrder='" +
WorkOrderset_w + "'" , null ) . Tables [ 0 ] ; //读取表写入缓存
if ( WorkOrder_set . Rows . Count > 0 )
{
@ -468,33 +355,65 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
} ) ;
}
WorkOrder SQL. Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
SQLiteHelpers . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
"WorkOrder ='" + WorkOrderdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
}
else
{ //串口
//string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
string WorkOrderset_w = WorkOrderset_ . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) ;
string POR = Selet_Machines ( Machines , "Serial" , "ID='" + k + "'" ) . ToString ( ) ;
DataTable WorkOrder_set = WorkOrderSQL . ExecuteDataSet ( "select * from WorkOrderSet where WorkOrder='" +
DataTable WorkOrder_set = SQLiteHelpers . ExecuteDataSet ( "select * from WorkOrderSet where WorkOrder='" +
WorkOrderset_w + "'" , null ) . Tables [ 0 ] ; //读取表写入缓存
if ( WorkOrder_set . Rows . Count > 0 )
{
stringQueueSerial . Enqueue ( new QueueSerial
int index = Convert . ToInt16 ( Selet_Machines ( Machines , "ID" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) ) ;
if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) = = "PORT1" )
{
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC812[" +
Selet_Machines ( Machines , "Station" , "ID='" + k + "'" ) + "]" +
DataTableToDictionary ( WorkOrder_set ) . ToJsonString ( )
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) = = "PORT2" )
{
ID = POR ,
DAT = "SC812[" +
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC812[" +
Selet_Machines ( Machines , "Station" , "ID='" + k + "'" ) + "]" +
DataTableToDictionary ( WorkOrder_set ) . ToJsonString ( )
} ) ;
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) = = "PORT3" )
{
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC812[" +
Selet_Machines ( Machines , "Station" , "ID='" + k + "'" ) + "]" +
DataTableToDictionary ( WorkOrder_set ) . ToJsonString ( )
} ) ;
}
else if ( Selet_Machines ( Machines , "Serial" , "Name='" + WorkOrderset_m + "'" ) . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = index ,
DAT = "SC812[" +
Selet_Machines ( Machines , "Station" , "ID='" + k + "'" ) + "]" +
DataTableToDictionary ( WorkOrder_set ) . ToJsonString ( )
} ) ;
}
}
WorkOrderSQL . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
SQLiteHelpers . Update ( "WorkOrder" , new Dictionary < string , object > { { "State" , 1 1 0 } } ,
"WorkOrder ='" + WorkOrderdata . Select ( ) [ k ] . Field < object > ( "WorkOrder" ) . ToString ( ) + "'" , null ) ;
}
}
WorkOrderSQL . Close ( ) ;
//系统时间
Sys_Time = DateTime . Now . ToString ( "yyyy/MM/dd HH:mm:ss" ) ;
@ -559,34 +478,98 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
else
{
if ( MachinesRow [ "State" ] . ToString ( ) = = "800" )
{ //串口发送
string POR = MachinesRow [ "Serial" ] . ToString ( ) ;
{ //串口发送
if ( MachinesRow [ "State" ] . ToString ( ) = = "802" )
{
if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT1" )
{
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
stringQueueSerial . Enqueue ( new QueueSerial
bool mode = Convert . ToBoolean ( MachinesRow [ "LOCK" ] ) ; //发送锁定状态
if ( mode )
{
Dictionary < string , object > dat_829 = new Dictionary < string , object > ( ) ;
dat_829 . Clear ( ) ;
dat_829 . Add ( "NAME" , "LOCK" ) ;
dat_829 . Add ( "VALUE" , "True" ) ;
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC829[" + MachinesRow [ "Station" ] + "]" + dat_829 . ToJsonString ( )
} ) ;
}
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT2" )
{
ID = POR ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
bool mode = Convert . ToBoolean ( MachinesRow [ "LOCK" ] ) ; //发送锁定状态
if ( mode )
bool mode = Convert . ToBoolean ( MachinesRow [ "LOCK" ] ) ; //发送锁定状态
if ( mode )
{
Dictionary < string , object > dat_829 = new Dictionary < string , object > ( ) ;
dat_829 . Clear ( ) ;
dat_829 . Add ( "NAME" , "LOCK" ) ;
dat_829 . Add ( "VALUE" , "True" ) ;
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC829[" + MachinesRow [ "Station" ] + "]" + dat_829 . ToJsonString ( )
} ) ;
}
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT3" )
{
Dictionary < string , object > dat_829 = new Dictionary < string , object > ( ) ;
dat_829 . Clear ( ) ;
dat_829 . Add ( "NAME" , "LOCK" ) ;
dat_829 . Add ( "VALUE" , "True" ) ;
stringQueueSerial . Enqueue ( new QueueSerial
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = POR ,
DAT = "SC829[" + MachinesRow [ "Station" ] + "]" + dat_829 . ToJsonString ( )
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
bool mode = Convert . ToBoolean ( MachinesRow [ "LOCK" ] ) ; //发送锁定状态
if ( mode )
{
Dictionary < string , object > dat_829 = new Dictionary < string , object > ( ) ;
dat_829 . Clear ( ) ;
dat_829 . Add ( "NAME" , "LOCK" ) ;
dat_829 . Add ( "VALUE" , "True" ) ;
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC829[" + MachinesRow [ "Station" ] + "]" + dat_829 . ToJsonString ( )
} ) ;
}
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
// Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "800");
bool mode = Convert . ToBoolean ( MachinesRow [ "LOCK" ] ) ; //发送锁定状态
if ( mode )
{
Dictionary < string , object > dat_829 = new Dictionary < string , object > ( ) ;
dat_829 . Clear ( ) ;
dat_829 . Add ( "NAME" , "LOCK" ) ;
dat_829 . Add ( "VALUE" , "True" ) ;
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC829[" + MachinesRow [ "Station" ] + "]" + dat_829 . ToJsonString ( )
} ) ;
}
}
}
int m_run = Convert . ToInt16 ( MachinesRow [ "WORK_RUN" ] ) ;
if ( m_run = = 0 )
{
@ -609,12 +592,38 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
string mac_s = MachinesRow [ "State" ] . ToString ( ) ;
if ( ( mac_s = = "101" ) | | ( mac_s = = "201" ) | | ( mac_s = = "202" ) | | ( mac_s = = "301" ) | | ( mac_s = = "309" ) ) //获取信息
{
string POR = MachinesRow [ "Serial" ] . ToString ( ) ;
stringQueueSerial . Enqueue ( new QueueSerial
if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT1" )
{
ID = POR ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT2" )
{
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT3" )
{
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC830[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
}
}
}
@ -678,14 +687,38 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
else
{ //串口
string POR = MachinesRow [ "Serial" ] . ToString ( ) ;
stringQueueSerial . Enqueue ( new QueueSerial
if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT1" )
{
ID = POR ,
DAT = "SC827[" + MachinesRow [ "Station" ] + "]"
} ) ;
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC827[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT2" )
{
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC827[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT3" )
{
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC827[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC827[" + MachinesRow [ "Station" ] + "]"
} ) ;
}
}
}
}
@ -709,13 +742,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
Dictionary < string , object > dat_ = new Dictionary < string , object > ( ) ; //缓存函数
dat_ . Add ( "State" , 2 0 3 ) ;
SQLiteHelpers = new SQLiteHelper ( DBAddress ) ; //数据库连接路径
SQLiteHelpers . Open ( ) ; //打开数据库
SQLiteHelpers . Update ( "DyelotHistory" , dat_ ,
"Dyelot='" + row . Field < string > ( "Dyelot" ) +
"' and Redye='" + row . Field < int > ( "Redye" ) +
"' and Step='" + row . Field < int > ( "Step" ) + "'" , null ) ; // 执行插入
SQLiteHelpers . Close ( ) ;
"' and Step='" + row . Field < int > ( "Step" ) + "'" , null ) ; // 执行插入
}
}
}
@ -893,42 +923,72 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{ //301列表发送完成至染机(203=>301)
foreach ( DataRow row in Dyelot_CALL . Select ( "State='301' OR State='309'" ) )
{
if ( Convert . ToBoolean ( MachinesRow [ "Type" ] ) )
{ //网络
Dictionary < string , object > Product_ = new Dictionary < string , object > ( ) ; //缓存函数
Product_ . Add ( "State" , row . Field < int > ( "State" ) ) ;
Product_ . Add ( "Step" , row . Field < int > ( "Step" ) ) ;
Product_ . Add ( "Dyelot" , row . Field < string > ( "Dyelot" ) ) ;
Product_ . Add ( "ProductCode" , row . Field < string > ( "ProductCode" ) ) ;
Product_ . Add ( "Amount" , row . Field < object > ( "Amount" ) ) ;
Product_ . Add ( "DispenseEndTime" , row . Field < object > ( "DispenseEndTime" ) ) ;
Dictionary < string , object > Product_ = new Dictionary < string , object > ( ) ; //缓存函数
Product_ . Add ( "State" , row . Field < int > ( "State" ) ) ;
Product_ . Add ( "Step" , row . Field < int > ( "Step" ) ) ;
Product_ . Add ( "Dyelot" , row . Field < string > ( "Dyelot" ) ) ;
Product_ . Add ( "ProductCode" , row . Field < string > ( "ProductCode" ) ) ;
Product_ . Add ( "Amount" , row . Field < object > ( "Amount" ) ) ;
Product_ . Add ( "DispenseEndTime" , row . Field < object > ( "DispenseEndTime" ) ) ;
if ( Convert . ToBoolean ( MachinesRow [ "Type" ] ) )
{ //网络
stringQueue . Enqueue ( new QueueString
{
ID = Convert . ToInt16 ( Selet_Machines ( Machines ,
"ID" , "Name='" + row . Field < string > ( "Machine" ) + "'" ) ) ,
DAT = "SC828" + Selet_Machines ( Machines ,
"SYSKEY" , "Name='" + row . Field < string > ( "Machine" ) + "'" ) + Product_ . ToJsonString ( )
} ) ;
if ( row [ "State" ] . ToString ( ) = = "309" )
} ) ;
}
else
{ //串口
if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT1" )
{
stringQueueSerial_1 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC828[" + MachinesRow [ "Station" ] + "]" + Product_ . ToJsonString ( )
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT2" )
{
stringQueueSerial_2 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC828[" + MachinesRow [ "Station" ] + "]" + Product_ . ToJsonString ( )
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT3" )
{
MainWindow . InfData . Rows . Add ( new object [ ] { row [ "Machine" ] ,
stringQueueSerial_3 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC828[" + MachinesRow [ "Station" ] + "]" + Product_ . ToJsonString ( )
} ) ;
}
else if ( MachinesRow [ "Serial" ] . ToString ( ) = = "PORT4" )
{
stringQueueSerial_4 . Enqueue ( new QueueSerial
{
ID = Convert . ToInt16 ( MachinesRow [ "ID" ] ) ,
DAT = "SC828[" + MachinesRow [ "Station" ] + "]" + Product_ . ToJsonString ( )
} ) ;
}
}
if ( row [ "State" ] . ToString ( ) = = "309" )
{
MainWindow . InfData . Rows . Add ( new object [ ] { row [ "Machine" ] ,
Resources . Step + row [ "Step" ] + Resources . DispenseException ,
Selet_Machines ( Machines , "SYSKEY" , "Name='" + row [ "Machine" ] + "'" ) ,
Selet_Machines ( Machines , "ID" , "Name='" + row [ "Machine" ] + "'" ) } ) ;
}
Dyelot_CALL . Rows . Remove ( row ) ;
}
else
{ //串口
}
Dyelot_CALL . Rows . Remove ( row ) ;
}
}
catch ( Exception EX ) { LogGing . ERRDATA ( EX ) ; }
}
}
void Tick_Event_30S ( )
@ -948,7 +1008,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
public static TcpClient [ ] MachiensTcpClient = new TcpClient [ 9 9 ] ;
public static SerialPortClient [ ] MachiensPortClient = new SerialPortClient [ 9 9 ] ;
public static SerialPortClient [ ] MachiensPortClient = new SerialPortClient [ 4 ] ;
//public static DataRow[] machinesdata = new DataRow[999];
public void ClientNEW ( )
{
@ -980,38 +1040,175 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
}
}
public void PortClientNEW ( )
public async void PortClientNEW ( )
{
foreach ( DataRow dataRow in Machines . Rows )
if ( Machines . Select ( "Type='false' AND Serial='PORT1'" ) . Length > 0 )
{
if ( ! Convert . ToBoolean ( dataRow [ "Type" ] ) )
MachiensPortClient [ 0 ] = new SerialPortClient ( ) ;
await AsyncSerialPortClient . PortClient ( MachiensPortClient [ 0 ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP1" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD1" ) ) ) ;
Port1_link ( ) ;
}
if ( Machines . Select ( "Type='false' AND Serial='PORT2'" ) . Length > 0 )
{
MachiensPortClient [ 1 ] = new SerialPortClient ( ) ;
await AsyncSerialPortClient . PortClient ( MachiensPortClient [ 1 ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP2" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD2" ) ) ) ;
Port2_link ( ) ;
}
if ( Machines . Select ( "Type='false' AND Serial='PORT3'" ) . Length > 0 )
{
MachiensPortClient [ 2 ] = new SerialPortClient ( ) ;
await AsyncSerialPortClient . PortClient ( MachiensPortClient [ 2 ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP3" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD3" ) ) ) ;
Port3_link ( ) ;
}
if ( Machines . Select ( "Type='false' AND Serial='PORT4'" ) . Length > 0 )
{
MachiensPortClient [ 3 ] = new SerialPortClient ( ) ;
await AsyncSerialPortClient . PortClient ( MachiensPortClient [ 3 ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP4" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD4" ) ) ) ;
Port4_link ( ) ;
}
}
private void Port1_link ( )
{
Task . Run ( ( ) = >
{
try
{
string Serial_ = dataRow [ "Serial" ] . ToString ( ) ;
foreach ( DataRow MachinesRow in Machines . Select ( "Type='false' AND Serial='PORT1'" ) )
{
if ( stringQueueSerial_1 . Count > 0 ) //信息发送队列
{
QueueSerial t = stringQueueSerial_1 . Dequeue ( ) ;
if ( Serial_ = = "PORT1" )
AsyncSerialPortClient . SendCommandAndWait ( MachiensPortClient [ 0 ] , t . DAT ) ;
//MachiensPortClient[t.ID].Send(t.DAT);
}
if ( MachinesRow [ "State" ] . ToString ( ) = = "800" )
{
AsyncSerialPortClient . SendCommandAndWait (
MachiensPortClient [ 0 ] ,
"SC800[" + MachinesRow [ "Station" ] + "]" ) ;
}
}
}
catch ( Exception )
{
}
finally
{
// if (stringQueueSerial.Count == 0) return;
Port1_link ( ) ; //回调
}
} ) ;
} //发送
private void Port2_link ( )
{
Task . Run ( ( ) = >
{
try
{
foreach ( DataRow MachinesRow in Machines . Select ( "Type='false' AND Serial='PORT2'" ) )
{
MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] = new SerialPortClient ( ) ;
_ = AsyncSerialPortClient . PortClient ( MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP1" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD1" ) ) ) ;
if ( stringQueueSerial_2 . Count > 0 ) //信息发送队列
{
QueueSerial t = stringQueueSerial_2 . Dequeue ( ) ;
AsyncSerialPortClient . SendCommandAndWait ( MachiensPortClient [ 1 ] , t . DAT ) ;
//MachiensPortClient[t.ID].Send(t.DAT);
}
if ( MachinesRow [ "State" ] . ToString ( ) = = "800" )
{
AsyncSerialPortClient . SendCommandAndWait (
MachiensPortClient [ 1 ] ,
"SC800[" + MachinesRow [ "Station" ] + "]" ) ;
}
}
else if ( Serial_ = = "PORT2" )
}
catch ( Exception )
{
}
finally
{
// if (stringQueueSerial.Count == 0) return;
Port2_link ( ) ; //回调
}
} ) ;
} //发送
private void Port3_link ( )
{
Task . Run ( ( ) = >
{
try
{
foreach ( DataRow MachinesRow in Machines . Select ( "Type='false' AND Serial='PORT3'" ) )
{
MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] = new SerialPortClient ( ) ;
_ = AsyncSerialPortClient . PortClient ( MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP2" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD2" ) ) ) ;
if ( stringQueueSerial_3 . Count > 0 ) //信息发送队列
{
QueueSerial t = stringQueueSerial_3 . Dequeue ( ) ;
AsyncSerialPortClient . SendCommandAndWait ( MachiensPortClient [ 2 ] , t . DAT ) ;
//MachiensPortClient[t.ID].Send(t.DAT);
}
if ( MachinesRow [ "State" ] . ToString ( ) = = "800" )
{
DataTable Workorddr = SQLiteHelpers . ExecuteDataSet ( "select * from Dyelot " , null ) . Tables [ 0 ] ; //读取表写入缓存
AsyncSerialPortClient . SendCommandAndWait (
MachiensPortClient [ 2 ] ,
"SC800[" + MachinesRow [ "Station" ] + "]" + Workorddr . ToJsonString ( ) ) ;
}
}
else if ( Serial_ = = "PORT3" )
}
catch ( Exception )
{
}
finally
{
// if (stringQueueSerial.Count == 0) return;
Port3_link ( ) ; //回调
}
} ) ;
} //发送
private void Port4_link ( )
{
Task . Run ( ( ) = >
{
try
{
foreach ( DataRow MachinesRow in Machines . Select ( "Type='false' AND Serial='PORT4'" ) )
{
MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] = new SerialPortClient ( ) ;
_ = AsyncSerialPortClient . PortClient ( MachiensPortClient [ Convert . ToInt16 ( dataRow [ "ID" ] ) ] //建立连接
, Configini . IniReadvalue ( "SYS" , "COMP3" )
, Convert . ToInt32 ( Configini . IniReadvalue ( "SYS" , "BAUD3" ) ) ) ;
if ( stringQueueSerial_4 . Count > 0 ) //信息发送队列
{
QueueSerial t = stringQueueSerial_4 . Dequeue ( ) ;
AsyncSerialPortClient . SendCommandAndWait ( MachiensPortClient [ 3 ] , t . DAT ) ;
//MachiensPortClient[t.ID].Send(t.DAT);
}
if ( MachinesRow [ "State" ] . ToString ( ) = = "800" )
{
AsyncSerialPortClient . SendCommandAndWait (
MachiensPortClient [ 3 ] ,
"SC800[" + MachinesRow [ "Station" ] + "]" ) ;
}
}
}
}
}
catch ( Exception )
{
}
finally
{
// if (stringQueueSerial.Count == 0) return;
Port4_link ( ) ; //回调
}
} ) ;
} //发送
public static string SYS_WorkNumder ; //工单号
public static int SYS_AT1 ; //附缸1-3
@ -1092,7 +1289,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static UInt32 TX = 0 ;
public class QueueSerial
{
public string ID { get ; set ; }
public int ID { get ; set ; }
public string DAT { get ; set ; }
}
public class QueueString
@ -1100,15 +1297,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public int ID { get ; set ; }
public string DAT { get ; set ; }
}
public static class Queue
{
public static int ID { get ; set ; }
public static string DAT { get ; set ; }
}
// 创建一个字符串类型的队列
public static Queue < QueueString > stringQueue = new Queue < QueueString > ( ) ;
public static Queue < QueueString > stringQueueinf = new Queue < QueueString > ( ) ;
public static Queue < QueueSerial > stringQueueSerial = new Queue < QueueSerial > ( ) ;
public static Queue < QueueSerial > stringQueueSerial_1 = new Queue < QueueSerial > ( ) ;
public static Queue < QueueSerial > stringQueueSerial_2 = new Queue < QueueSerial > ( ) ;
public static Queue < QueueSerial > stringQueueSerial_3 = new Queue < QueueSerial > ( ) ;
public static Queue < QueueSerial > stringQueueSerial_4 = new Queue < QueueSerial > ( ) ;
/// <summary>
/// 将 DataTable 转换为 Dictionary 类型数据