コード例 #1
0
        public async Task <bool> send_relative_move(int SpeedAZ, int SpeedEL, ushort ACCELERATION, int positionTranslationAZ, int positionTranslationEL)
        {
            bool Sucess = true;
            await MCUModbusMaster.WriteMultipleRegistersAsync(1024, MESSAGE_CONTENTS_CLEAR_MOVE);   //write a no-op to the mcu

            if (!is_test)
            {
                Task  task = Task.Delay(100); //wait to ensure it is porcessed
                await task;
            }
            ushort[] data =
            {
                0x0002, 0x0003, (ushort)((positionTranslationAZ & 0xFFFF0000) >> 16), (ushort)(positionTranslationAZ & 0xFFFF), (ushort)((SpeedAZ & 0xFFFF0000) >> 16), (ushort)(SpeedAZ & 0xFFFF), ACCELERATION, ACCELERATION, 0, 0,
                0x0002, 0x0003, (ushort)((positionTranslationEL & 0xFFFF0000) >> 16), (ushort)(positionTranslationEL & 0xFFFF), (ushort)((SpeedEL & 0xFFFF0000) >> 16), (ushort)(SpeedEL & 0xFFFF), ACCELERATION, ACCELERATION, 0, 0
            };
            await MCUModbusMaster.WriteMultipleRegistersAsync(1024, data);

            return(Sucess);
        }
コード例 #2
0
 public async Task <bool> WriteRegistersAsync(int address, ushort[] values)
 {
     if (this.CheckConnection())
     {
         try {
             using TcpClient client = new TcpClient(this.IpAddress, this.Port);
             ModbusIpMaster master = ModbusIpMaster.CreateIp(client);
             if (this.SlaveAddress != 0)
             {
                 await master.WriteMultipleRegistersAsync(this.SlaveAddress, (ushort)address, values);
             }
             else
             {
                 await master.WriteMultipleRegistersAsync((ushort)address, values);
             }
             client.Close();
             master.Dispose();
             return(true);
         } catch {
             return(false);
         }
     }
     return(false);
 }