- #1
- 68,275
- 21,968
I'm using C# to write some code for a manufacturing test of an embedded system device. It will access several instruments that are making measurements on the device, including some National Instruments MIO channels and a Tektronix power analyzer.
I'm most familiar with C and Tck/Tk, and am learning C# as I go. I see that there is no mechanism for #include files in C#, and have been reading about the alternatives like here:
https://forum.unity3d.com/threads/c-and-the-best-equivalent-of-include-from-c-c.258241/
I definitely need to be able to pull my configuration information out into separate files, preferably with separate files for each instrument that I'll be controlling. What would you recommend as the best/easiest way to do this in C#?
Here is an example of a single C# console app file that controls some power relays that are part of the test setup. I put the configuration information into the main file for now, until I learn how to break that info out into a separate file. Thanks for your help.
I'm most familiar with C and Tck/Tk, and am learning C# as I go. I see that there is no mechanism for #include files in C#, and have been reading about the alternatives like here:
https://forum.unity3d.com/threads/c-and-the-best-equivalent-of-include-from-c-c.258241/
I definitely need to be able to pull my configuration information out into separate files, preferably with separate files for each instrument that I'll be controlling. What would you recommend as the best/easiest way to do this in C#?
Here is an example of a single C# console app file that controls some power relays that are part of the test setup. I put the configuration information into the main file for now, until I learn how to break that info out into a separate file. Thanks for your help.
C:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Threading;
namespace SimpleRelayControl1
{
class Program
{
static SerialPort serialPort2;
static Byte[] r1on = new Byte[6] { 0xAA, 0x03, 0xFE, 0x6C, 0x01, 0x18 };
static Byte[] r1off = new Byte[6] { 0xAA, 0x03, 0xFE, 0x64, 0x01, 0x10 };
static Byte[] r2on = new Byte[6] { 0xAA, 0x03, 0xFE, 0x6D, 0x01, 0x19 };
static Byte[] r2off = new Byte[6] { 0xAA, 0x03, 0xFE, 0x65, 0x01, 0x11 };
static Byte[] r3on = new Byte[6] { 0xAA, 0x03, 0xFE, 0x6E, 0x01, 0x1A };
static Byte[] r3off = new Byte[6] { 0xAA, 0x03, 0xFE, 0x66, 0x01, 0x12 };
static Byte[] r4on = new Byte[6] { 0xAA, 0x03, 0xFE, 0x6F, 0x01, 0x1B };
static Byte[] r4off = new Byte[6] { 0xAA, 0x03, 0xFE, 0x67, 0x01, 0x13 };
static Byte[] allon = new Byte[6] { 0xAA, 0x03, 0xFE, 0x82, 0x01, 0x2E };
static Byte[] alloff = new Byte[6] { 0xAA, 0x03, 0xFE, 0x81, 0x01, 0x2D };
static string inputString = "";
static void Main(string[] args)
{
// Define COM port for Relay control
serialPort2 = new SerialPort();
serialPort2.Close();
serialPort2.PortName="COM4";
serialPort2.Encoding = System.Text.Encoding.GetEncoding("Windows-1252");
serialPort2.BaudRate=115200;
serialPort2.DataBits = 8;
serialPort2.Parity = Parity.None;
serialPort2.StopBits= StopBits.One;
serialPort2.Handshake= Handshake.None;
serialPort2.Open();
while(inputString != "exit")
{
Console.Write("Relay> ");
inputString = Console.ReadLine();
switch(inputString)
{
case "r1on" :
serialPort2.Write(r1on, 0, 6);
break;
case "r1off" :
serialPort2.Write(r1off, 0, 6);
break;
case "r2on":
serialPort2.Write(r2on, 0, 6);
break;
case "r2off":
serialPort2.Write(r2off, 0, 6);
break;
case "r3on":
serialPort2.Write(r3on, 0, 6);
break;
case "r3off":
serialPort2.Write(r3off, 0, 6);
break;
case "r4on":
serialPort2.Write(r4on, 0, 6);
break;
case "r4off":
serialPort2.Write(r4off, 0, 6);
break;
case "allon":
serialPort2.Write(allon, 0, 6);
break;
case "alloff":
serialPort2.Write(alloff, 0, 6);
break;
}
}
serialPort2.Close();
}
}
}