通过串口C#发送文本文件 [英] sending text file via serial port C#

查看:97
本文介绍了通过串口C#发送文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们

我在C#应用程序中使用以下方法将文本文件发送到调制解调器.

Hi Guys

I am using the following method in my C# application to send a text file to a modem.

private static void SendBinaryFile(  SerialPort port, string FileName)
{
  using (FileStream fs = File.OpenRead(FileName))
    port.Write((new BinaryReader(fs)).ReadBytes((int)fs.Length), 0, (int)fs.Length);
}



根据调制解调器,这必须通过硬件流控制来完成,因此我通过设置以下内容来做到这一点:



According to modem this must be done with hardware flow control , so I have done this by setting the following:

port.DtrEnable=true;
port.RtsEnable = true;
port.Handshake = Handshake.RequestToSend;



在调制解调器手册中,它指定:
...使用具有ASCII设置的发送文本文件:在启用了超级终端属性的情况下,发送带有换行符的行尾,并将换行符追加到传入的换行符.

您如何看待这些属性对二进制数据流的影响?



In the modem manual it specifies:
...use Send Text file with ASCII Setup: Send line ends with line feeds and Append line feeds to incoming line ends in HyperTerminal Properties enabled.

How do you think these properties affect the binary data stream?

推荐答案

似乎该调制解调器支持UNIX,因为Windows需要CR + LF来插入实际的新行.使用超级终端,您可以将数据读取为文本,并且当正确显示新行时,效果会更好.因此,我认为它不会对二进制数据传输产生影响,但是实际测试当然是最好的.只需来回转发一些二进制数据并验证它是否相同.

祝你好运!
It seems this modem is favoring unix because windows needs CR+LF to insert an actual new line. With HyperTerminal you would read the data as text and that goes much better when a new line is shown properly. So, I don''t think it will have effect on binary data transmission, but an actual test would of course be best. Simply send some binary data back and forward and verify it''s the same.

Good luck!


将二进制数据从串行端口发送到硬件时出现问题,
如果要通过串行端口发送二进制数据,则必须更改串行端口的编码

使用以下代码
There is a Problem while sending the binary data from the serial port to Hardware,
if you want to send binary data through the serial port you have to change the Encoding of your Serial port

Use the below code
SerialPort port = new SerialPort();
port.Encoding  = System.Text.Encoding.GetEncoding(1252);


这篇关于通过串口C#发送文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆