Files
mharb 0f4609e5d3 Implement Basic Logging to File
Attempt at dumping values from memory into a CSV file for post-processing

Signed-off-by: mharb <mharb@noreply.localhost>
2025-11-11 22:12:27 +00:00
..
2025-11-11 22:12:27 +00:00
2025-08-23 20:01:45 -04:00

ProtosX Bus Coupler Demo (PX-TCP1)

Abstract

The ProtosX Demo Application is designed to interface with the PX-TCP1 bus coupler, allowing users to read and control digital and analog inputs and outputs. This application is structured to provide a way to manage machine states and display input readings.

Table of Contents

Requirements

  • .NET SDK: Ensure you have the .NET 8 SDK installed on your machine. You can download it from the official .NET website.
  • Modbus Device: A Modbus-compatible PX-TCP1 device connected to your network.
  • Network Access: Ensure that your application can access the device over the network.

Installation

  1. Clone the Repository:

    git clone <repository-url>
    cd ProtosXDemo
    
  2. Restore Dependencies:

    dotnet restore
    
  3. Build the Application:

    dotnet build
    

Configuration

Before running the application, you may need to configure the following parameters in the Program.cs file:

  • IP Address: Set the IpAddress variable to the IP address of your Modbus device.
  • Port: The default Modbus TCP port is 502. Change it if your device uses a different port.
  • Recipe Name: Optionally, specify a recipe name for data processing.

Running the Application

To run the application, use the following command in your terminal:

dotnet run [recipeName] [timesToRepeat]
  • recipeName: (Optional) The name of the recipe to run.
  • timesToRepeat: (Optional) The number of times to repeat the execution. If not specified, the application will run once.

Example Command

dotnet run MyRecipe 5

Code Structure

The application is organized into several classes, each responsible for specific functionalities:

  • ChannelCache: Manages the counts of digital and analog inputs and outputs.
  • CommandLineParser: Parses command-line arguments for the application.
  • ConsoleSetup: Configures the console appearance.
  • Data: Contains the machine state and input/output definitions.
  • InputReader: Reads digital inputs from the Modbus device.
  • FailureCodes: Initializes failure codes for error handling.
  • LoadMachineStateDigital: Randomly sets the digital output states.
  • MainEventLoop: Manages the main execution loop of the application.
  • MakeHardStop: Safely stops all outputs.
  • OutputExerciser: Provides methods to turn outputs on and off.
  • RegisterReader: Reads analog input values from the Modbus device.
  • WriteMachineDigitalStateToIO: Writes the machine state to the Modbus device.

Functionality

The application performs the following key functions:

  • Reading Inputs: It reads digital and analog inputs from the Modbus device and displays their states.
  • Controlling Outputs: It allows users to turn digital outputs on and off.
  • Error Handling: The application includes mechanisms to handle various errors, such as connection issues and invalid input.

Error Handling

The application uses predefined failure codes to manage errors effectively. Common error scenarios include:

  • Connection Errors: If the application cannot connect to the Modbus device, it will display an error message and exit.
  • Input/Output Errors: If reading or writing to the device fails, appropriate error messages will be shown.

Exit Codes

  • 0 Success
  • 1 Write-error to hardware
  • 2 Too many command-line arguments
  • 255 Other fatal error

Target Hardware

Visual Aid

Warning

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

TL;DR: Not my problem

License

The GPL V2 license applies to this project. All copyrights belong to their respective copyright holders and all trademarks belong to their trademark holders.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.)