This commit is contained in:
maqiao 2024-02-26 18:02:16 +08:00
parent 3df79378b7
commit a4e9300e63
1 changed files with 24 additions and 8 deletions

View File

@ -126,6 +126,7 @@ namespace DM_Weight.Port
DrawerNo = 0; DrawerNo = 0;
ColNos = new int[] { }; ColNos = new int[] { };
Stocks = new int[] { }; Stocks = new int[] { };
logger.Info($"重新设置串口数据状态结束");
} }
public async void Start() public async void Start()
@ -146,6 +147,7 @@ namespace DM_Weight.Port
if (r[4] != 0) if (r[4] != 0)
{ {
logger.Info($"储物箱使能成功"); logger.Info($"储物箱使能成功");
Thread.Sleep(50);
// 查询锁状态 // 查询锁状态
GetBackDoorState(); GetBackDoorState();
} }
@ -669,7 +671,7 @@ namespace DM_Weight.Port
} }
if (_length != length) if (_length != length)
{ {
if(_length!=0) if (_length != 0)
{ {
byte[] _buffer = new byte[_length]; byte[] _buffer = new byte[_length];
serialPort.Read(_buffer, 0, _length); serialPort.Read(_buffer, 0, _length);
@ -685,7 +687,7 @@ namespace DM_Weight.Port
//} //}
return buffer; return buffer;
} }
private byte[] GetBufferByPort(SerialPort serialPort, int length, int timeout,string operation) private byte[] GetBufferByPort(SerialPort serialPort, int length, int timeout, string operation)
{ {
byte[] buffer = new byte[length]; byte[] buffer = new byte[length];
//try //try
@ -696,6 +698,18 @@ namespace DM_Weight.Port
while (_length != length && end.Subtract(start).TotalMilliseconds < timeout) while (_length != length && end.Subtract(start).TotalMilliseconds < timeout)
{ {
_length = serialPort.BytesToRead; _length = serialPort.BytesToRead;
if (_length == 0&& operation.Equals("开储物箱"))
{
_length = serialPort.BytesToRead;
if (_length == 0)
{
Thread.Sleep(500);
byte[] bufferWrite = new byte[] { 0xaa, (byte)(_doorAddr), 0x01, (byte)_storageBoxAddr, 0x00, 0x00, 0x00, 0xee };
canBusSerial.Write(bufferWrite, 0, 8);
logger.Info($"再次发送OpenStorage:{Convert.ToHexString(bufferWrite)};{end}");
}
}
end = DateTime.Now; end = DateTime.Now;
} }
if (_length != length) if (_length != length)
@ -722,10 +736,10 @@ namespace DM_Weight.Port
return Task.Run(() => GetBufferByPort(serialPort, length, 3000)); return Task.Run(() => GetBufferByPort(serialPort, length, 3000));
} }
private Task<byte[]> GetBufferByPort(SerialPort serialPort, int length,string operation) private Task<byte[]> GetBufferByPort(SerialPort serialPort, int length, string operation)
{ {
return Task.Run(() => GetBufferByPort(serialPort, length, 3000,operation)); return Task.Run(() => GetBufferByPort(serialPort, length, 3000, operation));
} }
public static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); public static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
@ -812,7 +826,9 @@ namespace DM_Weight.Port
canBusSerial.Write(buffer, 0, 8); canBusSerial.Write(buffer, 0, 8);
logger.Info($"OpenStorage:{Convert.ToHexString(buffer)}"); logger.Info($"OpenStorage:{Convert.ToHexString(buffer)}");
return await GetBufferByPort(canBusSerial, 8,"开储物箱");
return await GetBufferByPort(canBusSerial, 8, "开储物箱");
} }
// 关闭电控门储物箱(有灯失能) // 关闭电控门储物箱(有灯失能)
public void CloseStorage() public void CloseStorage()
@ -1160,7 +1176,7 @@ namespace DM_Weight.Port
buffer[5] = (byte)(quantity >> 8); buffer[5] = (byte)(quantity >> 8);
buffer[6] = (byte)(quantity & 0xff); buffer[6] = (byte)(quantity & 0xff);
canBusSerial.Write(buffer, 0, 8); canBusSerial.Write(buffer, 0, 8);
byte[] bufferReturn=await GetBufferByPort(canBusSerial, 8); byte[] bufferReturn = await GetBufferByPort(canBusSerial, 8);
logger.Info($"写入数量返回:" + Convert.ToHexString(bufferReturn)); logger.Info($"写入数量返回:" + Convert.ToHexString(bufferReturn));
} }
catch (Exception ex) catch (Exception ex)