Beispiel #1
0
        public void ModbusRequestRead(byte slaveAddress, UInt16 regAddress, UInt16 regNumber)
        {
            byte[] adu          = ModbusADU.CreateRequestADU03(regAddress, regNumber);
            byte[] requestFrame = ModbusSerialPDU.CreatePDU(slaveAddress, adu);

            /*if (CommunicationThread!= null)
             *  while (CommunicationThread.IsAlive) ;*/
            ModbusParam param = new ModbusParam(regNumber * 2 + 5, requestFrame);
            Thread      CommunicationThread = new Thread(ModbusSendReceive);

            CommunicationThread.Start(param);
        }
Beispiel #2
0
        public void ModbusRequestWrite(byte slaveAddress, UInt16 regAddress, Int16[] values)
        {
            ushort[] uValues = new ushort[values.Length];
            Buffer.BlockCopy(values, 0, uValues, 0, values.Length * 2);
            byte[] adu          = ModbusADU.CreateRequestADU10(regAddress, uValues);
            byte[] requestFrame = ModbusSerialPDU.CreatePDU(slaveAddress, adu);

            /*if (CommunicationThread != null)
             *  while (CommunicationThread.IsAlive) ;*/
            Thread      CommunicationThread = new Thread(ModbusSendReceive);
            ModbusParam param = new ModbusParam(8, requestFrame);

            CommunicationThread.Start(param);
        }