TriggerBox CLI
Manages Ethernet socket communication with the CoSANLab TriggerBox device for Unity projects. Provides async/await support for connecting to hardware triggers, sending trigger signals to specific pins, and monitoring device state with configurable logging levels. Requires Unity 2022.3 or later.
com.cosanlab.trgen Unity Compatibility
Unity 6 Supported
2023.2 Supported
2023.1 Supported
2022.3 LTS Supported
2021.3 LTS Unsupported
2020.3 LTS Unsupported
2019.4 LTS Unsupported

Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/trgen.git README Markdown
Copy this to your project's README.md
## Installation
Add **TriggerBox CLI** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/trgen.git
```
[](https://www.pkglnk.dev/pkg/trgen)README
TriggerBox CLI
A Unity library that manages Ethernet socket communication with the CoSANLab TriggerBox device
Installation
You can install TRGen via OpenUPM using one of the following methods:
Using the OpenUPM CLI
If you have openupm-cli installed:
openupm add com.cosanlab.trgen
## Getting started
To install this package add this package inside the `Packages/manifest.json` file
```json
{
"name": "OpenUPM",
"url": "https://package.openupm.com",
"scopes": [
"com.cosanlab.trgen"
]
}
Example
using System;
using System.Collections;
using Trgen;
using UnityEngine;
public class TrgenExample : MonoBehaviour
{
// TriggerClient instance is to be kept alive as long as you need it
TriggerClient client;
private String timeStr = "";
private bool isTimerGoing;
private string timePlaying_Str;
private TimeSpan timePlaying;
private float sectionCurrentTime;
public void StopTimer()
{
isTimerGoing = false;
timeStr = "00:00.0";
}
public async void TriggerConnect()
{
if (client != null && client.Connected)
throw new InvalidOperationException("Already connected");
else
{
client = new TriggerClient();
//client.Connect();
client.Verbosity = LogLevel.Debug;
await client.ConnectAsync();
}
}
public void TriggerSend()
{
if (!client.Connected)
throw new InvalidOperationException("Connection failed");
// Connected! (:
client.StartTrigger(TriggerPin.NS5);
// opzionalmente reset
client.ResetAll(TriggerPin.AllNs);
}
public void TriggerSendLoop()
{
StartCoroutine(SendLoop());
}
private IEnumerator SendLoop()
{
if (!client.Connected)
throw new InvalidOperationException("Connection failed");
while (isTimerGoing)
{
sectionCurrentTime += Time.deltaTime;
timePlaying = TimeSpan.FromSeconds(sectionCurrentTime);
timePlaying_Str = timePlaying.ToString("mm':'ss'.'f");
timeStr = timePlaying_Str;
client.StartTrigger(TriggerPin.NS5);
// opzionalmente reset
client.ResetAll(TriggerPin.AllNs);
yield return new WaitForSeconds (1);
}
}
}
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In