You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using Rs.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.MotionPlat.Commom
|
|
{
|
|
public class QifuManager
|
|
{
|
|
public ModbusTcp modbusLeft = new ModbusTcp("192.168.1.22", 502);
|
|
|
|
private static QifuManager instance;
|
|
public static QifuManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
instance = new QifuManager();
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private QifuManager()
|
|
{
|
|
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
modbusLeft.Connect();
|
|
}
|
|
|
|
public bool Write(float value)
|
|
{
|
|
ModbusErrorCode err = modbusLeft.WriteMultiHoldRegister(1, 0, new ushort[] { (ushort)(4550 * value) });
|
|
if (err == ModbusErrorCode.OK)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool Read()
|
|
{
|
|
modbusLeft.ReadUshortArr(1, FunCode.ReadMultiInputRegister, 0, 2, out int[] result);
|
|
double Channel1Value = (0.9f * result[0] - 900) / 4000.0f;
|
|
double Channel2Value = (0.9f * result[1] - 900) / 4000.0f;
|
|
return true;
|
|
}
|
|
}
|
|
}
|