Initial commit
This commit is contained in:
156
srcs/RobotNet10/RobotApp/Communication/Sick.ColaB/README.md
Normal file
156
srcs/RobotNet10/RobotApp/Communication/Sick.ColaB/README.md
Normal file
@@ -0,0 +1,156 @@
|
||||
# Sick.Tim781s.Colab
|
||||
|
||||
Thư viện C# để giao tiếp với SICK TiM781s LiDAR scanner sử dụng ColaB protocol (binary SOPAS).
|
||||
|
||||
## Tổng quan
|
||||
|
||||
Thư viện này cung cấp giao tiếp với SICK TiM781s scanner thông qua ColaB protocol (binary SOPAS). ColaB là protocol binary được sử dụng bởi các scanner SICK cũ hơn như TiM781s.
|
||||
|
||||
## Cấu trúc
|
||||
|
||||
- **ColaB/ColaBSession.cs**: Quản lý session và giao tiếp với scanner
|
||||
- **Commands/**: Các command classes (ReadCommand, WriteCommand, MethodCommand)
|
||||
- **Helpers/ColaBHelper.cs**: Helper functions để encode/decode ColaB frames
|
||||
- **Communication/TcpClient.cs**: TCP client implementation
|
||||
- **Tim781sScanner.cs**: Main class để sử dụng scanner
|
||||
|
||||
## Cách sử dụng
|
||||
|
||||
### Kết nối và đọc thông tin cơ bản
|
||||
|
||||
```csharp
|
||||
using Sick.Tim781s.Colab;
|
||||
|
||||
// Tạo scanner instance
|
||||
var scanner = new Tim781sScanner("192.168.1.1", 2112);
|
||||
|
||||
// Kết nối
|
||||
scanner.Connect();
|
||||
|
||||
// Đọc device identification
|
||||
var deviceIdent = scanner.ReadDeviceIdent();
|
||||
Console.WriteLine($"Device: {deviceIdent}");
|
||||
|
||||
// Đọc serial number
|
||||
var serialNumber = scanner.ReadSerialNumber();
|
||||
Console.WriteLine($"Serial: {serialNumber}");
|
||||
|
||||
// Đọc firmware version
|
||||
var firmwareVersion = scanner.ReadFirmwareVersion();
|
||||
Console.WriteLine($"Firmware: {firmwareVersion}");
|
||||
|
||||
// Ngắt kết nối
|
||||
scanner.Disconnect();
|
||||
```
|
||||
|
||||
### Thực thi các lệnh tùy chỉnh
|
||||
|
||||
```csharp
|
||||
// Đọc một biến
|
||||
var value = scanner.ExecuteRead("VariableName");
|
||||
|
||||
// Ghi một biến
|
||||
var success = scanner.ExecuteWrite("VariableName", "value");
|
||||
|
||||
// Gọi một method
|
||||
var result = scanner.ExecuteMethod("MethodName", "param1", "param2");
|
||||
```
|
||||
|
||||
### Sử dụng trực tiếp ColaBSession
|
||||
|
||||
```csharp
|
||||
using Sick.Tim781s.Colab;
|
||||
using Sick.Tim781s.Colab.Commands;
|
||||
using Sick.Tim781s.Colab.Communication;
|
||||
|
||||
// Tạo TCP client và session
|
||||
var tcpClient = new TcpClient("192.168.1.1", 2112);
|
||||
var session = new ColaBSession(tcpClient);
|
||||
|
||||
// Mở session
|
||||
session.Open();
|
||||
|
||||
// Tạo và thực thi command
|
||||
var readCmd = new ReadCommand("DeviceIdent");
|
||||
session.ExecuteCommand(readCmd);
|
||||
|
||||
if (readCmd.WasSuccessful)
|
||||
{
|
||||
Console.WriteLine($"Value: {readCmd.ReplyValue}");
|
||||
}
|
||||
|
||||
// Đóng session
|
||||
session.Close();
|
||||
```
|
||||
|
||||
## ColaB Protocol Format
|
||||
|
||||
ColaB frame format:
|
||||
```
|
||||
[STX STX STX STX] [Length (4 bytes BE)] ['s'] [Command Data] [Checksum (1 byte)]
|
||||
```
|
||||
|
||||
- **STX**: 0x02 0x02 0x02 0x02 (4 bytes)
|
||||
- **Length**: 4 bytes Big Endian - độ dài của payload ('s' + command data)
|
||||
- **'s'**: 1 byte character 's'
|
||||
- **Command Data**: SOPAS command string (ASCII)
|
||||
- **Checksum**: XOR của tất cả bytes từ length field đến end of command data
|
||||
|
||||
## SOPAS Commands
|
||||
|
||||
### Read Command (sRN)
|
||||
```
|
||||
sRN <VariableName>
|
||||
Reply: sAN <VariableName> <Value>
|
||||
```
|
||||
|
||||
### Write Command (sWN)
|
||||
```
|
||||
sWN <VariableName> <Value>
|
||||
Reply: sWA <VariableName>
|
||||
```
|
||||
|
||||
### Method Command (sMN)
|
||||
```
|
||||
sMN <MethodName> <Parameters>
|
||||
Reply: sAN <MethodName> <Result>
|
||||
```
|
||||
|
||||
## Ví dụ
|
||||
|
||||
### Đọc device information
|
||||
```csharp
|
||||
var scanner = new Tim781sScanner("192.168.1.1");
|
||||
scanner.Connect();
|
||||
|
||||
var deviceIdent = scanner.ReadDeviceIdent();
|
||||
var serialNumber = scanner.ReadSerialNumber();
|
||||
var firmwareVersion = scanner.ReadFirmwareVersion();
|
||||
|
||||
Console.WriteLine($"Device: {deviceIdent}");
|
||||
Console.WriteLine($"Serial: {serialNumber}");
|
||||
Console.WriteLine($"Firmware: {firmwareVersion}");
|
||||
```
|
||||
|
||||
### Start/Stop measurement
|
||||
```csharp
|
||||
// Start measurement (mode 1)
|
||||
scanner.StartMeasurement();
|
||||
|
||||
// Stop measurement (mode 0)
|
||||
scanner.StopMeasurement();
|
||||
```
|
||||
|
||||
## Lưu ý
|
||||
|
||||
- ColaB protocol sử dụng Big Endian byte order
|
||||
- Checksum được tính bằng XOR của tất cả bytes từ length field đến end of command data
|
||||
- Tất cả commands phải được đóng gói trong ColaB frame format
|
||||
- Scanner mặc định sử dụng port 2112
|
||||
|
||||
## Tham khảo
|
||||
|
||||
- SICK TiM781s Manual
|
||||
- SOPAS Protocol Documentation
|
||||
- sick_scan_xd C++ implementation
|
||||
|
||||
Reference in New Issue
Block a user