I-7017Z是一個類比輸入模組,包括10個差動或20個單端類比輸入通道。
class I7017Z
{
public static bool SetMode(SerialPort _SerialPort, string _Id, string _Chanel, string _ChannelType)
{
string Cmd = "$" + _Id + "7C" + _Chanel + "R" + _ChannelType;
string Receive = string.Empty;
if (!DCON.HandShake(_SerialPort, Cmd, ref Receive)) return false;
if (Receive != ("!" + _Id)) return false;
return true;
}
public static bool ReadAllValue(SerialPort _SerialPort, string _Id, ref double[] _Value)
{
string Cmd = "#" + _Id;
string Receive = string.Empty;
if (!DCON.HandShake(_SerialPort, Cmd, ref Receive)) return false;
if (Receive[0] != '>') return false;
if (!ValueReorgnize(Receive, ref _Value)) return false;
return true;
}
public static bool ReadValue(SerialPort _SerialPort, string _Id, string _Chanel, ref double _Value)
{
string Cmd = "#" + _Id + _Chanel;
string Receive = string.Empty;
if (!DCON.HandShake(_SerialPort, Cmd, ref Receive)) return false;
if (Receive[0] != '>') return false;
try
{
_Value = Convert.ToDouble(Receive.Substring(2));
}
catch
{
_Value = 0x00;
}
return true;
}
public static bool ValueReorgnize(string _Value, ref double[] _RecValue)
{
int i = 0;
string[] _Temp = null;
//string minus frist char ">" and "+"
_Value = _Value.Substring(2);
_Temp = _Value.Split('+');
_RecValue = new double[_Temp.Length];
foreach (string item in _Temp)
{
_RecValue[i++] = Convert.ToDouble(item);
}
return true;
}
}

沒有留言:
張貼留言