NET CORE NMODBUS4 reads the value of serial port devices

Use NModbus4 to read serial port

     public static void aget() {byte[] array = new byte[8]; using (SerialPort port = new SerialPort("COM3")) {port.BaudRate = 9600; port.DataBits = 8; port.Parity = Parity.None; port.StopBits = StopBits.One; port. Open(); array[0] = 253; array[1] = 3; array[2] = 1; array[3] = 0; array[4] = 0; array[5] = 2; array[6] = 209; array[7] = 203; port.Write(array, 0, 8); port.ReadTimeout = 1000; Thread.Sleep(800); if (port.BytesToRead> 0) {IModbusSerialMaster master = ModbusSerialMaster.CreateRtu( port); byte slaveId = 1; ushort startAddre ss = 100; ushort[] registers = new ushort[] {1, 2, 3 }; // write three registers //ushort[] shorts = master.r(slaveId, 0, 80); while (true) {ushort [] shorts2 = master.ReadHoldingRegisters(slaveId, 0, 5); double sd = double.Parse(shorts2[0].ToString()); double wd = double.Parse(shorts2[1].ToString()); Console .Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Humidity:" + sd / 10 + "%"); Console.WriteLine("Temperature:" + wd / 10 + "%"); Thread .Sleep(1000);}} //port.BytesToRead} }

  

Equipment information

High precision temperature and humidity Sensor RS485 Thermo-hygrometer Greenhouse rain-proof industrial grade 4-20ma

The value of the equipment

Share pictures

share picture

Read once every second

     public static void aget() {byte[] array = new byte[8]; using (SerialPort port = new SerialPort("COM3")) {port.BaudRate = 9600; port.DataBits = 8; port.Parity = Parity.None; port.StopBits = StopBits.One; port.Open(); array[0] = 253; array[1] = 3; array[2] = 1; array[3] = 0; array[4] = 0; array[5] = 2; array[6] = 209; array[7] = 203; port.Write(array, 0, 8); port. ReadTimeout = 1000; Thread.Sleep(800); if (port.BytesToRead> 0) { IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port); byte slaveId = 1; ushort startAddress = 100; ushort[] registers = new ushort[] {1, 2, 3 }; // write three registers //ushort[] shorts = master .r(slaveId, 0, 80); while (true) {ushort[] shorts2 = master.ReadHoldingRegisters(slaveId, 0, 5); double sd = double.Parse(shorts2[0].ToString()); double wd = double.Parse(shorts2[1].ToString()); Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Humidity:" + sd / 10 + "%"); Console.WriteLine ("Temperature:" + wd / 10 + "%"); Thread.Sleep(1000);}} //port.BytesToRead} }< /pre>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1233 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.