|
1 | | -## Bug fix : Current position always read wrong motion group |
| 1 | +## New Feature: Current Task Status Reading via SNPX |
2 | 2 |
|
3 | | -`ReadWorldPosition()` and `ReadUserFramePosition()` were silently targeting motion group 0, which does not exist on Fanuc controllers, causing the robot to return wrong position data. Both methods now correctly default to **group 1** (the first motion group). |
| 3 | +The SDK now provides the ability to read the current task status from the robot controller via the SNPX protocol. This allows you to monitor the execution state of programs running on different tasks. |
4 | 4 |
|
5 | | -Multi-group robots can still target a specific group explicitly: |
| 5 | +### Property Added |
6 | 6 |
|
7 | | -```csharp |
8 | | -// Read world position : group 1 (default, fixed) |
9 | | -Position pos = robot.Snpx.CurrentPosition.ReadWorldPosition(); |
10 | | - |
11 | | -// Read in user frame 3 : group 1 (default, fixed) |
12 | | -Position pos = robot.Snpx.CurrentPosition.ReadUserFramePosition(3); |
13 | | - |
14 | | -// Read world position on group 2 (multi-group robots) |
15 | | -Position pos = robot.Snpx.CurrentPosition.ReadWorldPosition(2); |
16 | | - |
17 | | -// Read in user frame 3 on group 2 |
18 | | -Position pos = robot.Snpx.CurrentPosition.ReadUserFramePosition(3, 2); |
19 | | -``` |
20 | | - |
21 | | ---- |
| 7 | +- **`CurrentTaskStatus`**: Provides access to the status of running tasks on the robot controller (now public, previously private) |
22 | 8 |
|
23 | | -## SNPX Numeric Registers : Int16 and Int32 support |
| 9 | +### What You Can Read |
24 | 10 |
|
25 | | -Numeric registers (`R[]`) can now be read and written as **16-bit** or **32-bit integers** in addition to the existing float format. Two new accessors are available on the SNPX client: `NumericRegistersInt32` and `NumericRegistersInt16`. |
| 11 | +For each task, you can access: |
26 | 12 |
|
27 | | -This is useful when a Fanuc program stores integer values in numeric registers and you want to avoid float conversion artifacts. |
| 13 | +- **`ProgramName`**: Name of the currently executing program |
| 14 | +- **`LineNumber`**: Current line number being executed |
| 15 | +- **`State`**: Execution state (Stopped, Paused, or Running) |
| 16 | +- **`Caller`**: Name of the calling program |
28 | 17 |
|
29 | | -### Single register read / write |
| 18 | +### Quick Example |
30 | 19 |
|
31 | 20 | ```csharp |
32 | | -// Float (existing) |
33 | | -float f = robot.Snpx.NumericRegisters.Read(1); |
34 | | -robot.Snpx.NumericRegisters.Write(1, 3.14f); |
35 | | - |
36 | | -// 32-bit integer |
37 | | -int i32 = robot.Snpx.NumericRegistersInt32.Read(1); |
38 | | -robot.Snpx.NumericRegistersInt32.Write(1, 1234567); |
39 | | - |
40 | | -// 16-bit integer |
41 | | -short i16 = robot.Snpx.NumericRegistersInt16.Read(1); |
42 | | -robot.Snpx.NumericRegistersInt16.Write(1, 42); |
43 | | -``` |
44 | | - |
45 | | -### Batch read / write |
46 | | - |
47 | | -Batch assignments let you read a contiguous range of registers in a single network round-trip. |
48 | | - |
49 | | -```csharp |
50 | | -// Float (existing) |
51 | | -var batchF = robot.Snpx.NumericRegisters.CreateBatchAssignment(1, 10); |
52 | | -float[] floats = batchF.Read(); |
53 | | - |
54 | | -// 32-bit integer |
55 | | -var batchI32 = robot.Snpx.NumericRegistersInt32.CreateBatchAssignment(1, 10); |
56 | | -int[] ints = batchI32.Read(); |
57 | | - |
58 | | -// 16-bit integer |
59 | | -var batchI16 = robot.Snpx.NumericRegistersInt16.CreateBatchAssignment(1, 10); |
60 | | -short[] shorts = batchI16.Read(); |
| 21 | +using UnderAutomation.Fanuc; |
| 22 | +using UnderAutomation.Fanuc.Common; |
| 23 | +using UnderAutomation.Fanuc.Snpx.Internal; |
| 24 | + |
| 25 | +// Create and connect to robot |
| 26 | +FanucRobot robot = new FanucRobot(); |
| 27 | +ConnectionParameters parameters = new ConnectionParameters("192.168.0.1"); |
| 28 | +parameters.Snpx.Enable = true; |
| 29 | +robot.Connect(parameters); |
| 30 | + |
| 31 | +// Read task status for task 1 (index starts from 1) |
| 32 | +RobotTaskStatus task1Status = robot.Snpx.CurrentTaskStatus.Read(1); |
| 33 | + |
| 34 | +// Display task information |
| 35 | +Console.WriteLine($"Program: {task1Status.ProgramName}"); |
| 36 | +Console.WriteLine($"Line: {task1Status.LineNumber}"); |
| 37 | +Console.WriteLine($"State: {task1Status.State}"); |
| 38 | +Console.WriteLine($"Caller: {task1Status.Caller}"); |
| 39 | + |
| 40 | +// Check task state |
| 41 | +switch (task1Status.State) |
| 42 | +{ |
| 43 | + case RobotTaskState.Running: |
| 44 | + Console.WriteLine($"Task 1 is running {task1Status.ProgramName} at line {task1Status.LineNumber}"); |
| 45 | + break; |
| 46 | + case RobotTaskState.Paused: |
| 47 | + Console.WriteLine("Task 1 is paused"); |
| 48 | + break; |
| 49 | + case RobotTaskState.Stopped: |
| 50 | + Console.WriteLine("Task 1 is stopped"); |
| 51 | + break; |
| 52 | +} |
| 53 | + |
| 54 | +// Monitor multiple tasks |
| 55 | +for (int i = 1; i <= 4; i++) |
| 56 | +{ |
| 57 | + var taskStatus = robot.Snpx.CurrentTaskStatus.Read(i); |
| 58 | + Console.WriteLine($"Task {i}: {taskStatus}"); |
| 59 | +} |
61 | 60 | ``` |
0 commit comments