Ejemplo n.º 1
0
        //Lettura dati da inverter tramite RS485 utilizzando un convertirore RS485-Eth con rete di polarizzazione
        public static void Test07()
        {
            ModbusRtu _inverter = new ModbusRtu("172.20.48.40", 4001);

            byte[] send     = new byte[6];
            byte   _cmd     = 0x02;
            ushort _strAddr = 0x3001;
            ushort _nr      = 0x80;
            byte   idDevice = 0x02;

            _inverter.sendRequest(idDevice, _cmd, _strAddr, _nr);
            _inverter.ReadModbusMsg();

            _cmd     = 0x02;
            _strAddr = 0x4001;
            _nr      = 0xF0;
            idDevice = 0x02;

            _inverter.sendRequest(idDevice, _cmd, _strAddr, _nr);
            _inverter.ReadModbusMsg();
        }
Ejemplo n.º 2
0
        public static void Lab13()
        {
            bool   _loop = true;
            string _r;

            Serial485 com = new Serial485("COM3", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            ModbusRtu net = new ModbusRtu("192.168.0.237", 4001);

            com.sendRequest(0x01, 0x03, 0x131, 0x1);
            net.ReadModbusMsg();
//
            net.sendRequest(0x01, 0x03, 0x131, 0x1);
            com.ReadModbusMsg(); // OCCHIO!!! sembra che al messaggio ricevudo venda messo in testa un byte di indirizzo e in coda ricalcolato il CRC!!!



//   Console.WriteLine("Press 1 key to send Request usb->net \n Press 2 to send Request net->usb. \nPress X to exit");
//   while( _loop==true)
//   {
//       _r=Console.ReadLine();
//       switch (_r.ToUpper())
//       {
//           case "X":
//             _loop=false;
//             break;
//           case "1": _loop=false;
//                 com.sendRequest(0x01,0x03,0x131,0x1);
//                break;
//           case "2": _loop=false;
//                 net.sendRequest(0x01,0x03,0x131,0x1);
//                break;
//           default:
//                 Console.WriteLine(_r + "Comando non riconosciuto");
//                 break;
//       }
//    }
            Console.WriteLine("exiting....");
        }