This commit is contained in:
parent
3df79378b7
commit
a4e9300e63
|
@ -126,6 +126,7 @@ namespace DM_Weight.Port
|
|||
DrawerNo = 0;
|
||||
ColNos = new int[] { };
|
||||
Stocks = new int[] { };
|
||||
logger.Info($"重新设置串口数据状态结束");
|
||||
}
|
||||
|
||||
public async void Start()
|
||||
|
@ -146,6 +147,7 @@ namespace DM_Weight.Port
|
|||
if (r[4] != 0)
|
||||
{
|
||||
logger.Info($"储物箱使能成功");
|
||||
Thread.Sleep(50);
|
||||
// 查询锁状态
|
||||
GetBackDoorState();
|
||||
}
|
||||
|
@ -669,13 +671,13 @@ namespace DM_Weight.Port
|
|||
}
|
||||
if (_length != length)
|
||||
{
|
||||
if(_length!=0)
|
||||
if (_length != 0)
|
||||
{
|
||||
byte[] _buffer = new byte[_length];
|
||||
byte[] _buffer = new byte[_length];
|
||||
serialPort.Read(_buffer, 0, _length);
|
||||
logger.Info($"交互超时回复:{Convert.ToHexString(buffer)}");
|
||||
}
|
||||
throw new TimeoutException($"串口【{serialPort.PortName}】交互超时");
|
||||
throw new TimeoutException($"串口【{serialPort.PortName}】交互超时");
|
||||
}
|
||||
serialPort.Read(buffer, 0, length);
|
||||
//}
|
||||
|
@ -685,7 +687,7 @@ namespace DM_Weight.Port
|
|||
//}
|
||||
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];
|
||||
//try
|
||||
|
@ -696,6 +698,18 @@ namespace DM_Weight.Port
|
|||
while (_length != length && end.Subtract(start).TotalMilliseconds < timeout)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
if (_length != length)
|
||||
|
@ -722,10 +736,10 @@ namespace DM_Weight.Port
|
|||
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();
|
||||
|
@ -812,7 +826,9 @@ namespace DM_Weight.Port
|
|||
canBusSerial.Write(buffer, 0, 8);
|
||||
logger.Info($"OpenStorage:{Convert.ToHexString(buffer)}");
|
||||
|
||||
return await GetBufferByPort(canBusSerial, 8,"开储物箱");
|
||||
|
||||
|
||||
return await GetBufferByPort(canBusSerial, 8, "开储物箱");
|
||||
}
|
||||
// 关闭电控门储物箱(有灯失能)
|
||||
public void CloseStorage()
|
||||
|
@ -1160,7 +1176,7 @@ namespace DM_Weight.Port
|
|||
buffer[5] = (byte)(quantity >> 8);
|
||||
buffer[6] = (byte)(quantity & 0xff);
|
||||
canBusSerial.Write(buffer, 0, 8);
|
||||
byte[] bufferReturn=await GetBufferByPort(canBusSerial, 8);
|
||||
byte[] bufferReturn = await GetBufferByPort(canBusSerial, 8);
|
||||
logger.Info($"写入数量返回:" + Convert.ToHexString(bufferReturn));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Reference in New Issue