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

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

问题描述

伙计们

我正在尝试使用c Sharp将文本文件发送到调制解调器.

在调制解调器手册中,它指定:在ASCII设置中使用发送文本"文件:在启用了超级终端属性的情况下,将带有换行符的行末尾和将换行符追加至传入的行尾.
您如何看待这些属性会影响要发送的文本文件?

这是我用来发送文本文件的代码.

port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.Encoding = System.Text.Encoding.GetEncoding(1252);
port.DtrEnable = true;
port.RtsEnable = true;
port.Handshake = Handshake.RequestToSend;


StreamReader readtext =新的StreamReader("filename.txt");
字符串内容= readtext.ReadToEnd();
readtext.Close();
readtext.Dispose();
byte [] WriteBuffer =新的byte [contents.Length];
ASCIIEncoding enc =新的System.Text.ASCIIEncoding();
WriteBuffer = enc.GetBytes(contents);
port.Write(WriteBuffer,0,contents.Length); <pre></pre>

Hi Guys

I am trying to send a text file to a modem using c sharp.

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 text file to be sent??

Here is my code I am using to send the text file.

port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.Encoding = System.Text.Encoding.GetEncoding(1252);
port.DtrEnable=true;
port.RtsEnable = true;
port.Handshake = Handshake.RequestToSend;


StreamReader readtext = new StreamReader("filename.txt");
string contents = readtext.ReadToEnd();
readtext.Close();
readtext.Dispose();
byte[] WriteBuffer=new byte[contents.Length];
ASCIIEncoding enc = new System.Text.ASCIIEncoding();
WriteBuffer = enc.GetBytes(contents);
port.Write(WriteBuffer, 0,contents.Length );<pre></pre>

推荐答案

这是指换行符表示的行尾(ASCII 0x0A),但是,它看起来像是在谈论超级终端程序.一些程序更喜欢换行,另一些程序更喜欢换行符(ASCII 0x0D),而有些则希望两者兼而有之,但这通常是程序的功能",而不是调制解调器.

实际上,串行端口和调制解调器只是对您发送的字节进行编码,除非中断以进入命令模式,否则您几乎可以发送任何内容,并且可以传输出去,因此在大多数情况下,您可以发送文件CR, LF和所有.唯一可能引起混淆的是混合使用Linux/Unix和Windows,因为它们对行尾的处理方式不同.

如果编写的软件仅用于发送,则应按接收端的预期处理EOL.如果同时写TX和RX,则选择要执行的操作并保持一致.如果TX和RX都使用相同的操作系统,则可能无需执行任何操作.
What it means is the end of a line is represented by a line feed (ASCII 0x0A), however, that looks like it''s talking about the HyperTerminal program. Some programs prefer a line feed, others a carriage return (ASCII 0x0D) and some want both or either, but that''s usually a "feature" of the program, not the modem.

Actually a serial port and a modem just encode the bytes you send and unless you interrupt to go to a command mode, you can pretty much send anything and it will make it across, so you can just send the file in most cases, CR, LF and all. The only time there might be some confusion is when you mix Linux/Unix and Windows, since they handle end-of-line differently.

If you are writing software only to send, you should handle EOL as expected by the receiving end. If you are writing both TX and RX, then choose what you want to do and be consistent. If both TX and RX are using the same operating system, you probably don''t have to do anything.


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

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