Files
htolhast/HTOLHAST/ScpiInstrument.cs
Wesley Hofman 14e8e2f267 Various updates
2025-09-15 20:24:09 +02:00

67 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ivi.Visa;
using Ivi.Visa.Interop;
namespace HTOLHAST
{
// Base class for SCPI instruments
public abstract class SCPIInstrument
{
protected ResourceManager resourceManager;
protected Ivi.Visa.Interop.FormattedIO488 instrument;
public abstract Sample CreateSample(string response, string unit);
protected SCPIInstrument(string resourceString)
{
resourceManager = new ResourceManager();
instrument = new FormattedIO488();
instrument.IO = (IMessage)resourceManager.Open(resourceString, AccessMode.NO_LOCK, 2000, "");
}
public void WriteCommand(string command)
{
try
{
instrument.WriteString(command, true);
}
catch (Exception ex)
{
Console.WriteLine($"Error writing command: {ex.Message}");
}
}
public string ReadResponse()
{
try
{
string response = instrument.ReadString(); // Read from the instrument
return response;
}
catch (Exception ex)
{
Console.WriteLine($"Error reading response: {ex.Message}");
return string.Empty;
}
}
public string GetID()
{
WriteCommand("*IDN?");
return ReadResponse();
}
public void Reset()
{
WriteCommand("*RST");
}
public void Close()
{
instrument.IO.Close();
}
}
}