GetCDMState 10s

This commit is contained in:
thuannd88
2024-09-17 22:47:57 +07:00
parent 04c1e400db
commit cdf3ab64f9
2 changed files with 29 additions and 22 deletions
+4 -17
View File
@@ -1579,27 +1579,20 @@
public class Com232C public class Com232C
{ {
SerialPort serialPort = null; SerialPort serialPort = null;
public static int prevState = 0;
public Com232C(SerialPort _serialPort) public Com232C(SerialPort _serialPort)
{ {
this.serialPort = _serialPort; this.serialPort = _serialPort;
} }
public byte send_dat(byte[] buf, int size) public byte send_dat(byte[] buf, int size)
{ {
//Debug.WriteLine(DE70_CMD.ByteArrayToString(buf, 0, size));
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.NORMAL;
//AppData.CDMSTATE.CDMStatus = "DE: OK";
byte bResult = Constants.E_NG;
try try
{ {
serialPort.Write(buf, 0, size); serialPort.Write(buf, 0, size);
bResult= Constants.E_OK; return Constants.E_OK;
} }
catch (Exception e) catch (Exception e)
{ {
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT;
AppData.CDMSTATE.CDMStatus = "DE: LỖI";
try try
{ {
Log.Fatal(e, "DE70_send_dat"); Log.Fatal(e, "DE70_send_dat");
@@ -1611,16 +1604,10 @@
{ {
Log.Fatal(e2, "DE70_send_dat2"); Log.Fatal(e2, "DE70_send_dat2");
} }
}
if(AppData.DeviceStatus.CDMStatus!=prevState)
{
APIModels.SendEvent(AppData.DeviceStatus);
prevState = AppData.DeviceStatus.CDMStatus;
}
}
// Implement serial communication send function // Implement serial communication send function
return Constants.E_NG;
return bResult;
} }
public int rcv_dat(byte[] buf, int pos, int size) public int rcv_dat(byte[] buf, int pos, int size)
+24 -4
View File
@@ -384,6 +384,7 @@ namespace SafeBagDE70
} }
int prevPrinterStatus = -1; int prevPrinterStatus = -1;
int prevSensorStatus = -1; int prevSensorStatus = -1;
int prevCDMState = -1;
private void SensorTimer_Tick(object? sender, EventArgs e) private void SensorTimer_Tick(object? sender, EventArgs e)
{ {
sensorTimer.IsEnabled = false; sensorTimer.IsEnabled = false;
@@ -394,10 +395,7 @@ namespace SafeBagDE70
if (countSensorTimer % 10 == 0) if (countSensorTimer % 10 == 0)
{ {
GetPrinterStatus(); GetPrinterStatus();
if(!AppData.IsInTransaction) GetCDMStatus();
{
AppData.GetCDMState();
}
AppData.DeviceStatus.Description = AppData.CDMSTATE.CDMStatus; AppData.DeviceStatus.Description = AppData.CDMSTATE.CDMStatus;
AppData.DeviceStatus.DeviceTime = DateTime.Now; AppData.DeviceStatus.DeviceTime = DateTime.Now;
@@ -423,6 +421,28 @@ namespace SafeBagDE70
sensorTimer.IsEnabled = true; sensorTimer.IsEnabled = true;
} }
private void GetCDMStatus()
{
if (!AppData.IsInTransaction)
{
AppData.GetCDMState();
if (cCmdRsp.recv_dat.ret != Constants.E_OK)
{
AppData.CDMSTATE.CDMStatus = "CDM: LỖI";
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT;
}
else
{
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.NORMAL;
}
if (AppData.DeviceStatus.CDMStatus != prevCDMState)
{
prevCDMState = AppData.DeviceStatus.CDMStatus;
APIModels.SendEvent(AppData.DeviceStatus);
}
}
}
private void GetPrinterStatus() private void GetPrinterStatus()
{ {
var status = printerManager.GetStatus(); var status = printerManager.GetStatus();