Skip to content

.NET 9 Web API for receiving, validating, and storing lab data over TCP. Includes in-memory caching, USB backup, and a status monitoring endpoint.

Notifications You must be signed in to change notification settings

Om-Suryawanshi/LabReportAPI

Repository files navigation

LabReportAPI - TCP Listener + Web API for Lab Data Logging

LabReportAPI is a .NET 9 WebAPI application that listens for lab machine data over TCP using a custom STX/ETX protocol. Valid lab data is parsed and saved to a USB drive as a JSON file. The Web API provides endpoints to monitor status and trigger data saving.


🧠 How the Code Works

✅ TCP Listener (TcpListenerService)

  • Listens on 0.0.0.0:12377 for incoming TCP messages.
  • Each message must be wrapped in STX (0x02) and ETX (0x03) characters.
  • Valid messages are in the format: PATIENT123|GLUCOSE|120|mg/dL
  • Parsed data is stored in-memory as LabMessage objects. If the system has been idle (no TCP messages) for 30+ seconds, it saves data.
  • Data is appended to LabData.json on the USB drive.
  • Works even if the USB path is not explicitly configured (auto-detects removable drives).

✅ Web API Endpoints (LabDataController)

  • /api/labdata/status: Shows the server IP, port, last message time, and write status.
  • /api/labdata/save: Manually triggers a save to USB.

How to Build

You can build using the .NET CLI:

dotnet publish -c Release -r win-x64 --self-contained true

Config USB Path (Optional)

Edit appsettings.json:

{
  "LabSettings": {
    "UsbPath": "E:\"
  }
}

If left empty, the app will try to auto-detect the first available removable USB drive.


📩 Need Help?

If you're unsure how to send TCP messages or need help testing, please reach out to me.


About

.NET 9 Web API for receiving, validating, and storing lab data over TCP. Includes in-memory caching, USB backup, and a status monitoring endpoint.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published