我有一个应用程序通过rs232读取不同的硬件.它已经过测试,并且运行良好.对于最终的应用,我需要引入一些hunder m长电缆,这意味着我有rs485转换器.
当我运行我的应用程序来读取硬件时,我得到System.IO.Ports.SerialStream.Read的超时错误.我已将超时时间增加到20秒,不幸的是它没有解决问题
我尝试了不同的应用程序来读取硬件,它们甚至可以在1秒的读取频率下工作.
通信正在使用modbus协议,我认为这是当前阶段无关紧要,因为我没有到达接收任何东西的阶段.
我的代码看起来像这样:首先是串口打开和初始化:
//get the right modbus data structure element
ModBus MB = (ModBus)s[0].sensorData;
//set up the serial port regarding the data structure's data
SerialPort sp = new SerialPort();
sp.PortName = MB.portName;
sp.BaudRate = Convert.ToInt32(MB.baudRate);
sp.DataBits = MB.dataBits;
sp.Parity = MB.parity;
sp.StopBits = MB.stopBits;
//Set time outs 20 sec for now
sp.ReadTimeout = 20000;
sp.WriteTimeout = 20000;
Run Code Online (Sandbox Code Playgroud)
//将端口添加到List,读者可以访问portList.Add(sp); sp.Open();
读硬件:
//get the right port for com
SerialPort sp = getRightPort();
ModBus MB = getRightModBusStructureelement();
try
{
//Clear …Run Code Online (Sandbox Code Playgroud) 我正在尝试捕获屏幕的一部分。问题是,即使我使用 png 保存图像,质量仍然比使用普通打印屏幕差。
这是我使用的代码:
//display a save file dialog for the user to set the file name
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PNG (*.png)|*.png";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
//if the user proceed saving the picture
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
//simplify code with constant numbers for demo
//get the width of the panel we need the screenshoot off
int x = 10;
//get the height of the panel we need the screenshoot off
int y = …Run Code Online (Sandbox Code Playgroud)