Browse Source

udpate daservice

master
Gavin 9 years ago
parent
commit
3709de4402
  1. BIN
      SCADA/Example/BatchCoreTest.exe
  2. 144
      SCADA/Program/BatchCoreService/DAService.cs

BIN
SCADA/Example/BatchCoreTest.exe

Binary file not shown.

144
SCADA/Program/BatchCoreService/DAService.cs

@ -1362,80 +1362,84 @@ namespace BatchCoreService
for (int i = 0; i < data.Count; i++) for (int i = 0; i < data.Count; i++)
{ {
short id = data[i].ID; short id = data[i].ID;
byte[] dt = BitConverter.GetBytes(id); var propid = GetItemProperties(id);
sendBuffer[j++] = dt[0]; if (propid >= 0 && propid < _list.Count)
sendBuffer[j++] = dt[1];
switch (_list[GetItemProperties(id)].DataType)
{ {
case DataType.BOOL: byte[] dt = BitConverter.GetBytes(id);
sendBuffer[j++] = 1; sendBuffer[j++] = dt[0];
sendBuffer[j++] = data[i].Value.Boolean ? (byte)1 : (byte)0; sendBuffer[j++] = dt[1];
break; switch (_list[propid].DataType)
case DataType.BYTE: {
sendBuffer[j++] = 1; case DataType.BOOL:
sendBuffer[j++] = data[i].Value.Byte; sendBuffer[j++] = 1;
break; sendBuffer[j++] = data[i].Value.Boolean ? (byte)1 : (byte)0;
case DataType.WORD: break;
{ case DataType.BYTE:
sendBuffer[j++] = 2; sendBuffer[j++] = 1;
byte[] bt = BitConverter.GetBytes(data[i].Value.Word); sendBuffer[j++] = data[i].Value.Byte;
sendBuffer[j++] = bt[0]; break;
sendBuffer[j++] = bt[1]; case DataType.WORD:
}
break;
case DataType.SHORT:
{
sendBuffer[j++] = 2;
byte[] bt = BitConverter.GetBytes(data[i].Value.Int16);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
}
break;
case DataType.DWORD:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.DWord);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.INT:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.Int32);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.FLOAT:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.Single);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.STR:
{
byte[] bt = Encoding.ASCII.GetBytes(this[data[i].ID].ToString());
sendBuffer[j++] = (byte)bt.Length;
for (int k = 0; k < bt.Length; k++)
{ {
sendBuffer[j++] = bt[k]; sendBuffer[j++] = 2;
byte[] bt = BitConverter.GetBytes(data[i].Value.Word);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
} }
} break;
break; case DataType.SHORT:
default: {
break; sendBuffer[j++] = 2;
byte[] bt = BitConverter.GetBytes(data[i].Value.Int16);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
}
break;
case DataType.DWORD:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.DWord);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.INT:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.Int32);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.FLOAT:
{
sendBuffer[j++] = 4;
byte[] bt = BitConverter.GetBytes(data[i].Value.Single);
sendBuffer[j++] = bt[0];
sendBuffer[j++] = bt[1];
sendBuffer[j++] = bt[2];
sendBuffer[j++] = bt[3];
}
break;
case DataType.STR:
{
byte[] bt = Encoding.ASCII.GetBytes(this[data[i].ID].ToString());
sendBuffer[j++] = (byte)bt.Length;
for (int k = 0; k < bt.Length; k++)
{
sendBuffer[j++] = bt[k];
}
}
break;
default:
break;
}
Array.Copy(BitConverter.GetBytes((data[i].TimeStamp == DateTime.MinValue ? DateTime.Now : data[i].TimeStamp).ToFileTime()), 0, sendBuffer, j, 8);
j += 8;
} }
Array.Copy(BitConverter.GetBytes((data[i].TimeStamp == DateTime.MinValue ? DateTime.Now : data[i].TimeStamp).ToFileTime()), 0, sendBuffer, j, 8);
j += 8;
} }
byte[] dt1 = BitConverter.GetBytes(j); byte[] dt1 = BitConverter.GetBytes(j);
sendBuffer[3] = dt1[0]; sendBuffer[3] = dt1[0];

Loading…
Cancel
Save