当前位置:网站首页>Atlas atlas torque gun USB communication tutorial based on mtcom
Atlas atlas torque gun USB communication tutorial based on mtcom
2022-07-03 15:18:00 【11eleven】
It's impossible to make children's shoes in the automation industry without the tool of torque gun , Then it involves the data collection of torque gun , Generally, the torque and angle values are collected , The torque gun industry is open protocol agreement , be based on WEBSCOKET Collect response data . What I want to introduce to you today is atalas Of USB Communications , be based on MTCOM DLL Function instruction communication .
MTCOM yes atlas Official DLL The function library provides some function instructions about controller data collection , Generally speaking, we only collect torque angles , One thing to note here is that the program needs to use the read function to read in a short time after tightening the station , Otherwise, it cannot be read , That is to say, the reading action needs to be started before tightening , Close after reading , Read by polling . First find it on the controller SN code , Then initialize the connection Turn on the device , Finally, poll the data on demand . The code is as follows ,SDKDLL Download path MTCOM DLL
Look directly at the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TestTool.Utility;
namespace TestTool.ToolForm
{
public partial class Atlas400Form : Form
{
#region Initialize the library
/*
* MT_Init
* This function initializes MTCom DLL, Must be in MTCom Before any other function of • Use API
*/
[DllImport("MTCom.dll", EntryPoint = "MT_Init")]
public static extern bool MT_Init();
/*
* MT_GetVersion
* This function is used to retrieve MTCom DLL Version number of . If the function call succeeds , Then the version will contain null The ending version number string .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_GetDllVersion")]
public static extern bool MT_GetDllVersion([MarshalAs(UnmanagedType.LPStr)] StringBuilder version);
/*
* MT_GetDeviceList
* This function is used to retrieve the serial number of the currently connected microring device . If the function call succeeds ,oDevices Will contain a semicolon separated list of serial numbers ,oDeviceCount The number of connected devices will be included
*/
[DllImport("MTCom.dll", EntryPoint = "MT_GetDeviceList")]
public static extern bool MT_GetDeviceList([MarshalAs(UnmanagedType.LPStr)] StringBuilder devices, out int deviceCount);
/*
* MT_GetDeviceInfo
* This function is used to retrieve the information of the device with the given serial number . If the function calll success ,oDevicestatus Will remain connected ,oDevicetype The type of device that will remain connected . Please refer to the following table for the list of valid values of the two parameters
*/
public enum DeviceStatusEnum : int { MT_DEVICE_NOT_FOUND = 0, MT_DEVICE_PRESENT, MT_DEVICE_CONNECTED, MT_DEVICE_READY }
public enum DeviceTypeEnum : int { MT_DEVICE_UNKNOWN = 0, MT_DEVICE_MICROTEST_MC, MT_DEVICE_MICROTORQUE_G4, MT_DEVICE_ACTA_MT4, MT_DEVICE_MTF400_BASIC, MT_DEVICE_MTF400_ADVANCED }
[DllImport("MTCom.dll", EntryPoint = "MT_GetDeviceInfo")]
public static extern bool MT_GetDeviceInfo([MarshalAs(UnmanagedType.LPStr)] string serial, [MarshalAs(UnmanagedType.I4)] out DeviceStatusEnum deviceStatus, [MarshalAs(UnmanagedType.I4)] out DeviceTypeEnum deviceType);
/*
* MT_Open
* This function opens the connection to the device with the given serial number , And return the handle of the open device . If it cannot open the connection to the device , It will return an invalid handle value . Reserved for future use , And should be set to 0) Retain
*/
public readonly static IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
[DllImport("MTCom.dll", EntryPoint = "MT_Open")]
public static extern IntPtr MT_Open([MarshalAs(UnmanagedType.LPStr)] string serial, int reserved);
/*
* MT_Close
* This function closes the open connection to the device , It doesn't return anything .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_Close")]
public static extern IntPtr MT_Close(ref IntPtr client);
/*
*MT_Clear
* This function clears all previously received data sets on the specified channel . If channel number is used 13 or 14 call , It can be used to clear the summary data and summary serial number of the device .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_Clear")]
public static extern bool MT_Clear(IntPtr client, int channel);
/*
*MT_WriteSet
* This function writes the data set to the device . The application can choose to build the entire data set , Include control characters , Channel number and checksum , And pass it on to MT WriteSet Or it can choose the command , Give Way MTCom Constructed dat
*/
[DllImport("MTCom.dll", EntryPoint = "MT_WriteSet")]
public static extern bool MT_WriteSet(IntPtr client, int channel, [MarshalAs(UnmanagedType.LPArray)] byte[] dataset, int noBytes);
/*
*MT_ReadSet
* This function reads the data set from the device . If an actual error occurs , This function will only indicate failure ( return FALSE). If it times out waiting for the data set , It will return TRUE And will oBytesRead Set to zero .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_ReadSet")]
public static extern bool MT_ReadSet(IntPtr client, int channel, [MarshalAs(UnmanagedType.LPArray)][Out] byte[] buffer, [MarshalAs(UnmanagedType.I4)] out int noBytes, int timeOut);
/*
* MT_GetSummary
* This function retrieves MTCom The last summary received ( The last joint result ). When a joint is finished , Micro torque device in channel 13 and 14 Automatically send summary protocol data on . Because this function only returns MTCom The last summary received , Therefore, applications that rely on this function to retrieve summary data should track serial numbers , To ensure that the retrieved summary is correct . See the example in the next chapter . As oSummary The size of the byte array passed must be equal to or greater than 1kb
*/
[DllImport("MTCom.dll", EntryPoint = "MT_GetSummary")]
public static extern bool MT_GetSummary(IntPtr client, [MarshalAs(UnmanagedType.LPArray)][Out] byte[] summary, [MarshalAs(UnmanagedType.I4)] out int noBytes, [MarshalAs(UnmanagedType.I4)] out int sequenceNo);
/*
* MT_GetNoTraceChannels
* This function is used to obtain the maximum number of tracking channels of the micro torque device .
*/
[DllImport(@"MTCom.dll", EntryPoint = "MT_GetNoTraceChannels")]
public static extern bool MT_GetNoTraceChannels(IntPtr client, [MarshalAs(UnmanagedType.I4)] out int noTraceChannels);
/*
* MT_GetTraceInfo
* This function is used to get information about MTCom Tracking information of the last buffered joint in . I will retrieve the points in the trace 、 Sampling rate ( To sample / Seconds per unit ) And torque unit
*/
public enum UnitEnum : int { MTU_mNm = 0, MTU_cNm, MTU_Nm, MTU_mN, MTU_N, MTU_kN, MTU_inlbf, MTU_lbf, MTU_inozf, MTU_gcm, MTU_kgm, MTU_ftlbf, MTU_ozf, MTU_kgf, MTU_gf, MTU_INVALID = -1, }
[DllImport("MTCom.dll", EntryPoint = "MT_GetTraceInfo")]
public static extern bool MT_GetTraceInfo(IntPtr client, int traceChannel, [MarshalAs(UnmanagedType.I4)] out int noPoints, [MarshalAs(UnmanagedType.I4)] out int sampleRate, [MarshalAs(UnmanagedType.I4)] out int torqueUnit);
/*
* MT_GetTracePoints
* This function retrieves MTCom The actual trace point of the currently cached trace in . You should call... First MT GetTraceInfo To get available points . According to the parameters passed to it , You can use this function to retrieve the entire trace or part of the trace . Variable traceChannel Express MTCom For which channel should trace data be retrieved . Usually this is the passage 0( stay G4 Drive in , stay acme - mt4 Is the first sensor ). As TracePoints Delivered MT The trace point structure array should be able to be saved in variables maxPoints The number of points passed in . Integer starting point indicates MTCom Where should I start copying trace points of trace data .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_GetTracePoints")]
public static extern bool MT_GetTracePoints(IntPtr client, int traceChannel, [MarshalAs(UnmanagedType.LPArray)][Out] TracePointStruct[] points, int startPoint, int maxPoints, [MarshalAs(UnmanagedType.I4)] out int noPoints);
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 16)]
public struct TracePointStruct
{
[MarshalAs(UnmanagedType.R8)]
public double torque;
[MarshalAs(UnmanagedType.R8)]
public double angle;
}
/*
* MT_GetOutput
* It returns the status of the internal output of the device . The retrieved value is a bitmask , According to the type of equipment queried , Its meaning is also different .
*/
[DllImport("MTCom.dll", EntryPoint = "MT_GetOutput")]
public static extern bool MT_GetOutput(IntPtr client, [MarshalAs(UnmanagedType.I4)] out int output);
/*
* MT_GetLastError
* This function returns the error code of the last failed function . It can be in any MTCom API 1 Then call
*/
public enum ErrorCodeEnum : int
{
MT_OK = 0,
MT_ERR_INVALID_VERSION = -1,
MT_ERR_INVALID_PARAMETER = -2,
MT_ERR_INVALID_DATA = -3,
MT_ERR_INVALID_CHECKSUM = -4,
MT_ERR_CONNECTION_ERROR = -5,
MT_ERR_INVALID_MESSAGE_ID = -6,
MT_ERR_MUTEX_TIMEOUT = -7,
MT_ERR_PIPE_READ_FAILED = -8,
MT_ERR_PIPE_WRITE_FAILED = -9,
MT_ERR_USB_READ_FAILED = -10,
MT_ERR_USB_WRITE_FAILED = -11,
}
[DllImport("MTCom.dll", EntryPoint = "MT_GetLastError")]
public static extern ErrorCodeEnum MT_GetLastError();
#endregion
public Atlas400Form()
{
InitializeComponent();
this.Load += Atlas400Form_Load;
}
private void ShowLog(string str) {
logLines.Insert(0,DateTime.Now.ToString("yyyy-MM-dd HHmmss")+" "+str);
this.Invoke(new Action(() =>
{
TxtLog.Lines = logLines.ToArray();
}));
}
List<string> logLines = new List<string>();
private void Atlas400Form_Load(object sender, EventArgs e)
{
bool initMt = MT_Init();
ShowLog($" initialization COM {initMt}");
if (initMt)
{
}
}
IntPtr client;
private void BtnOpen_Click(object sender, EventArgs e)
{
if (TxtSn.Text.Trim() == "")
{
ShowLog(" equipment SN Can't be empty ");
return;
}
string serialNo = TxtSn.Text.Trim();
client = MT_Open(serialNo, 0);
if (client != INVALID_HANDLE_VALUE)
{
ShowLog(" Device connected successfully !");
// byte[] request = System.Text.Encoding.ASCII.GetBytes("IV");
// bool success = MT_WriteSet(client, 5, request, request.Length);
//MT_Close(ref client);
}
else {
ShowLog(" Device connection failed !");
}
}
private void BtnRead_Click(object sender, EventArgs e)
{
bool success = MT_GetTraceInfo(client, 13, out int noNopoints, out int sampleRate, out int torqueUnit);
if (success)
{
byte[] reply = new byte[4096];
Task.Run(async () => {
while (true)
{
success = MT_ReadSet(client, 13, reply, out int noBytes, 1000);
if (noBytes > 0)
{
ShowLog($"Reply: {System.Text.Encoding.ASCII.GetString(reply, 0, noBytes)}");
break;
}
else
{
ShowLog($" Read failed , Overtime ");
// Timed out.
}
await Task.Delay(1000);
}
});
//TracePointStruct[] points = new TracePointStruct[noNopoints];
// MT_GetTracePoints(client, TxtChannel.Value.ToInt(), points, 0, points.Length - 1, out int nopoints);
}
else
{
ShowLog($"Operation failed w/err: { MT_GetLastError()}.");
}
}
private void BtnChannel_Click(object sender, EventArgs e)
{
MT_GetNoTraceChannels(client, out int num);
ShowLog($" passageway :{num}");
}
}
}
边栏推荐
- Introduction, use and principle of synchronized
- Dataframe returns the whole row according to the value
- Série yolov5 (i) - - netron, un outil de visualisation de réseau
- Tencent internship interview sorting
- Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Relationship between truncated random distribution and original distribution
- Composite type (custom type)
- 视觉上位系统设计开发(halcon-winform)-2.全局变量设计
- 视觉上位系统设计开发(halcon-winform)-5.相机
- 【pytorch学习笔记】Datasets and Dataloaders
猜你喜欢
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
Jvm-06-execution engine
Yolov5系列(一)——网络可视化工具netron
B2020 points candy
Jvm-09 byte code introduction
High quality workplace human beings must use software to recommend, and you certainly don't know the last one
Can‘t connect to MySQL server on ‘localhost‘
详解指针进阶1
Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
Basic SQL tutorial
随机推荐
Can‘t connect to MySQL server on ‘localhost‘
Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
Idea does not specify an output path for the module
PyTorch crop images differentiablly
视觉上位系统设计开发(halcon-winform)-1.流程节点设计
【可能是全中文网最全】pushgateway入门笔记
C语言刷题~Leetcode与牛客网简单题
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
Use of Tex editor
【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
qt使用QZxing生成二维码
求字符串函数和长度不受限制的字符串函数的详解
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
北京共有产权房出租新规实施的租赁案例
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
Global and Chinese markets for indoor HDTV antennas 2022-2028: Research Report on technology, participants, trends, market size and share
Troubleshooting method of CPU surge
Jvm-03-runtime data area PC, stack, local method stack