https://stackoverflow.com/questions/6569882/reading-data-from-mettler-toledo-scale-device-using-c-sharp
private SerialPort port = new SerialPort("COM1", 4800, Parity.None, 8, StopBits.One);
public Inwardsfrm()
{
InitializeComponent();
port.DtrEnable = true;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
private void Inwardsfrm_Load(object sender, EventArgs e)
{
if (port.IsOpen == false)
try
{
port.Open();
}
catch (Exception oex)
{
MessageBox.Show(oex.ToString());
}
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
Thread.Sleep(30);
string data = port.ReadExisting() + port.ReadExisting();
try
{
richTextBox1.Text = data.Trim().Remove(0, 3);
}
catch (Exception f)
{
MessageBox.Show(f.Message.ToString());
}
}
private void DoUpdate(object s, EventArgs e)
{
Thread.Sleep(30);
string data = port.ReadExisting() + port.ReadExisting();
if(data.Trim().Count() < 3)
MessageBox.Show("data = " + data);
else
try
{
richTextBox1.Text = data.Trim().Remove(0, 3);
}
catch (Exception f)
{
MessageBox.Show(f.Message.ToString());
}
}
========================================================================================
https://control.com/forums/threads/read-weight-from-mettler-toledo-scale-via-rs232.32068/
I understand that you want to capture Mettler Toledo RS232 port weight data in a VB.NET application. And you are after source code for VB.NET.
To query the scale, you need to send an ASCII command:
S<CR><LF>
To process the returned weight:
<?><LF>S S 0.000 lb
<?><LF>S S 0.000 g
It would be best to extract the value and the units and then implemenmt a switch statement on the units toi convert to a standard weight.
I would suggest reading the captured string into a string seperator using space " " as the delimiter such that
str[0] = "<?><LF>S"
str[1] = "S"
str[2] = "0.000"
str[3] = "lb|g|kg|..."
then process the result
Which version of VB are you using? - I might be able to supply VB.NET 2008 code.
=========================================================================================
https://stackoverflow.com/questions/9671294/read-weight-from-a-serial-mettler-toledo-digital-scale
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
I faced a problem like this and I solved it changing a COM configuration (Configuration > Comunication > Conections) to SICS in the device. I don't know your scale model but maybe my code can help.
https://stackoverflow.com/questions/35483240/reading-data-from-mettler-toledo-ind560-scale-device-using-c-sharp
===========================================================================================================
https://stackoverflow.com/questions/10130837/connecting-to-digital-scalemetler-toledo-ps90-as-hid-runs-onreport-only-when-c
I am using Mike O Brien's HID Library to connect to digital scale, Device opens successfully then displays device attached & removed messages perfectly. But only runs OnReport for about 20 times initially
=================================================
https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.datareceived?view=netframework-4.8
using System;
using System.IO.Ports;
class PortDataReceived
{
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM1");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
mySerialPort.Open();
Console.WriteLine("Press any key to continue...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
}
}
==================================================================
https://blog.csdn.net/newbie_xymt/article/details/78178820
一定要在com实例化的时候设置ReceivedBytesThreshold 属性就可以
https://blog.csdn.net/inr12345/article/details/7679538
_serialBluetooth.ReceivedBytesThreshold = 1024; //1KB时触发一次事件, 此设置非常关键。之前设置为1,造成了程序运行起来,将近死程序。
https://blog.csdn.net/HorseRoll/article/details/80493408
ser.Dispose();
======================================================================
https://blog.csdn.net/u010307521/article/details/50238997
对于读操作,由于串口有dataReceived事件可以监听,这里选择不用线程,而是监听事件。建立一个timer用来扫描第二个comboBox,当第二个comboBox中有选中的时候,事件会被监听到。
private void timer1_Tick(object sender, EventArgs e)
{
this.AddEventHandlerForResponse();
}
private void AddEventHandlerForResponse()
{
for (int i = 0; i < this.portNames.Length; i++)
{
try
{
if (this.portNames.ElementAt(i) == this.portNumberComboBox2.Text.ToString())
{
if ((this.serialPorts.ElementAt(i).IsOpen)&&(this.serialPorts.ElementAt(i).BytesToRead > 0))
{
this.serialPorts.ElementAt(i).Read(this.portBuffer, 0, this.serialPorts.ElementAt(i).BytesToRead);
this.serialPorts.ElementAt(i).DataReceived += new SerialDataReceivedEventHandler(this.DataReceiveEventHandler);
}
}
}
catch (IOException eio)
{
MessageBox.Show("串口异常:" + eio);
}
}
}
上面的代码中出现了处理DataReceived事件的函数this.DataReceiveEventHandler
这里由于串口的读操作相对特殊,串口读取缓冲区数据通过辅助线程进行,进行读操作的时候不能直接修改UI中的内容,所以文本框中的接收内容要通过invoke来实现。
private void DataReceiveEventHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
this.receiveTextBox.Invoke(
new MethodInvoker(
delegate
{
this.receiveTextBox.AppendText(sp.ReadExisting());
this.receiveTextBox.Text += " ";
}
)
);
}
================================================================================
https://blog.csdn.net/qq_30725967/article/details/89149551
C# SerialPort串口通信发送接收,处理接收数据完整
================================================================================
https://www.cnblogs.com/rorysix/p/8038338.html
[填坑]SerialPort的“端口被关闭”
一年前用winform给公司做了一个软件,用到了电子秤,因此使用了SerialPort来读串口数据。
做完后,DataReceived事件里偶尔出现“端口被关闭”错误,都是在关闭串口后出现。
(出错位置要么是读数据ReadLine,要么时清除缓存DiscardInBuffer)
当时研究了半天没解决,想着影�
没有合适的资源?快使用搜索试试~ 我知道了~
ML3001T_Read_Demo.zip
共23个文件
cs:6个
exe:3个
pdb:2个
需积分: 9 5 下载量 99 浏览量
2019-11-27
12:45:14
上传
评论
收藏 50KB ZIP 举报
温馨提示
利用C#的SerialPort读取梅特勒托利多(ML3001T)天平,你想要的参考,我可能都帮你找到了,我参考了10多个方法,踩了好几个坑,总结了这一套程序,目前实现了:读取稳定值,读取之前先去皮,不存在串口禁止访问的情况,不存在程序假死的情况。先看一下程序能否运行,如果遇到了问题,看一看打包里的txt文档,应该有你想要的。
资源推荐
资源详情
资源评论
收起资源包目录
ML3001T_Read_Demo.zip (23个子文件)
ML3001T_Read_Demo
ML3001T_Read_Demo.sln 941B
总结,希望对你有帮助.txt 10KB
ML3001T_Read_Demo
Program.cs 509B
Form3.Designer.cs 8KB
Properties
Settings.settings 249B
Resources.Designer.cs 3KB
AssemblyInfo.cs 1KB
Settings.Designer.cs 1KB
Resources.resx 5KB
Form3.resx 6KB
Form3.cs 5KB
obj
Debug
ML3001T_Read_Demo.csproj.GenerateResource.Cache 847B
ML3001T_Read_Demo.pdb 26KB
Refactor
ML3001T_Read_Demo.Form3.resources 180B
ML3001T_Read_Demo.Properties.Resources.resources 180B
TempPE
ML3001T_Read_Demo.exe 12KB
ML3001T_Read_Demo.csproj.FileListAbsolute.txt 1KB
bin
Debug
ML3001T_Read_Demo.vshost.exe.manifest 490B
ML3001T_Read_Demo.pdb 26KB
ML3001T_Read_Demo.exe 12KB
ML3001T_Read_Demo.vshost.exe 14KB
ML3001T_Read_Demo.csproj 4KB
ML3001T_Read_Demo.suo 20KB
共 23 条
- 1
资源评论
onlinepay
- 粉丝: 27
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DMG3407SSN-VB一款SOT23封装P-Channel场效应MOS管
- DMG3407SSN-7-VB一款SOT23封装P-Channel场效应MOS管
- DMG3401LSN-VB一款SOT23封装P-Channel场效应MOS管
- CloudCompareV2.13.0
- DMC4050SSD-13-VB一款N+P-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- 1166-加减运算器实验.ms14
- DMC4040SSD-13-VB一款SOP8封装N+P-Channel场效应MOS管
- 绿茶基本知识及冲泡PPT
- 2001-2019上市公司历史业绩预期差距计算Stata代码(附2001-2019年数据和结果)
- DMC4028SSD-VB一款SOP8封装N+P-Channel场效应MOS管
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功