Exemple #1
0
 void SendCommand(UartCommand command, ushort address, Task data)
 {
     var dta = new byte[7];
     dta[0] = (byte)command;
     dta[1] = (byte)(address << 8);
     dta[2] = (byte)(address);
     if (data != null)
     {
         data.GetBytes().CopyTo(dta, 3);
     }
     port.Send(dta, 1, false);
 }
Exemple #2
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     Task task = new Task();
     task.value = (byte)cbFill.Value;
     task.start = 0;
     task.Port = (byte)(cbChannel.Value - 1);
     task.TaskType = ((KeyValuePair<string, byte>)cbType.SelectedItem).Value;
     task.IsActive = true;
     SendCommand(UartCommand.exec, 0, task);
 }
Exemple #3
0
 void port_OnReceive(byte[] data)
 {
     if ((UartCommand)data[0] == UartCommand.get)
     {
         OnDeviceStateChange(EDeviceState.Online);
         ushort addr = (ushort)(data[1] << 8);
         addr += data[2];
         if (data[3] + data[4] + data[5] + data[6] == 0)
         {
             return;
         }
         currentTask = new Task(data, 3);
         currentTask.Address = addr;
         TaskList.Add(currentTask);
         addr++;
         SendCommand(UartCommand.get, addr, null);
     }
 }