我试图从串口获取数据 [英] I am trying to get data from the serial port

查看:53
本文介绍了我试图从串口获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从串口获取数据


我已经构建了一个简单的串口程序,打开端口并显示到文本框。它正在工作,它打开和关闭端口。


但数据有些需要转换。数据是8位字节是乱码如何让它们以十六进制显示?这是它们在十六进制值中应该看起来的样子,它们代表传输到串行端口的(小时,分钟,秒,月,日,年和温度,以度为单位)。我可以在视频中看到正确的波特率。


这是一个公共视频http://dl.dropbox.com/u/23363133/C_Prog/SimpleSerialC%23prog1 .AVI的操作程序,你可以看到我遇到的问题,任何帮助将不胜感激。


简单的程序如下......

I am trying to get data from the serial port

I have built a simple serial program that opens the port and displays to a text box. It is working in that it opens and closes the port alright.

BUT the data some how needs to be converted. It is garbled the data is in 8bit bytes how do I get them to show in hexdecimal? This is what they should look like in hex values, 19 39 43 09 29 11 19 80 they represent the (hour, minutes, seconds, month, date, year, and temperature in deg C) that is being transmitted into the serial port. I have the right baud rate as can be seen in the video.

Here is a public video http://dl.dropbox.com/u/23363133/C_Prog/SimpleSerialC%23prog1.AVI of the program in operation you can see the problem I am having, Any help would be appreciated.

The simple program is below...

展开 | 选择 | Wrap | 行号

推荐答案

这是一个后续视频,显示值以串行方式作为十六进制显示,并在C#GUI中显示为ASCII如何转换(更正此)


公共视频链接在这里...... http://dl.dropbox.com/u/23363133/C_P...progVideo2.AVI


如果可以请帮忙,


谢谢Tom
Here is a followup video that shows that the values are coming over the serial line as hex and showing in the C# GUI as ASCII how can I convert (correct this)

Public Video Link is here... http://dl.dropbox.com/u/23363133/C_P...progVideo2.AVI

Please help if you can,

Thanks Tom


150和250Mb?我不认为这些视频会从很多人那里下载...


现在,如果我理解正确你需要将ascii转换为十六进制吗?

如果是这样,请看下面的链接,它解释了如何。

http://www.dotnetspider.com/resource...ing-c-dot.aspx


但无论如何,一个简单的谷歌搜索C#ascii to hex会给你很多结果。


如果这不是你需要的,请再次发帖,并解释一下你需要什么。


问候,

Alexandros
150 and 250Mb? I don''t think that these videos will be downloaded from many people...

Now if I understood correctly you need to convert ascii to hex right?
If so, take a look at the following link, it explains how.

http://www.dotnetspider.com/resource...ing-c-dot.aspx

But anyway, a simple google search for "C# ascii to hex" will give you plenty of results.

If this is not what you need, post again and kindly explain what is it that you need.

Regards,
Alexandros


我能够通过这样的汇编程序将微控制器更改为微控制器内的ASCII ...


movff SECONDS,ALSECONDS

movff SECONDS,AUSECONDS

bcf ALSECONDS,4

bcf ALSECONDS,5

bcf ALSECONDS,6

bcf ALSECONDS,7

movlw 0x30

addwf ALSECONDS,1

swapf AUSECONDS,1

bcf AUSECONDS,4

bcf AUSECONDS,5

bcf AUSECONDS,6

bcf AUSECONDS ,7 $ / $
movlw 0x30

addwf AUSECONDS,1


结果是积极的,现在你可以在这个视频中看到GUI采取来自串口的ascii数据... http://dl.dropbox.com/u/23363133/C_P...progVideo3.AVI

现在最棘手的是温度它是一个12位分辨率传感器,作为两个8位字节发送一个MSB和一个LSB​​,MSB是2 ^ 7,2 ^ 6,2 ^ 5,2 ^ 4,2 ^ 3,2 ^ 2,2 ^ 1,2 ^ 0和LSB 2 ^ -1,2 ^ -2,2 ^ -3,2 ^ -4,0,0,0,0。提供12位分辨率,在-25到125摄氏度的精度范围内,在0.125摄氏度时,这种转换要复杂一些。但看起来我会再次尝试使用汇编程序将其强制转换为ASCII,以便C#GUI可以轻松读取它。


欢迎任何建议...


谢谢,汤姆
I was able to brute force change the hex into ASCII within the microcontroller with assembler like this...

movff SECONDS,ALSECONDS
movff SECONDS,AUSECONDS
bcf ALSECONDS,4
bcf ALSECONDS,5
bcf ALSECONDS,6
bcf ALSECONDS,7
movlw 0x30
addwf ALSECONDS,1
swapf AUSECONDS,1
bcf AUSECONDS,4
bcf AUSECONDS,5
bcf AUSECONDS,6
bcf AUSECONDS,7
movlw 0x30
addwf AUSECONDS,1

The results were positive now you can see in this video the GUI taking in the ascii data from the serial port... http://dl.dropbox.com/u/23363133/C_P...progVideo3.AVI

Now the tricky one is the Temperature it is a 12 bit resolution sensor that transmits as two 8bit bytes A MSB and a LSB the MSB is 2^7,2^6,2^5,2^4,2^3,2^2,2^1,2^0 and LSB 2^-1,2^-2,2^-3,2^-4,0,0,0,0. Giving a 12 bit resolution for -55 to 125 degC accuracy with in 0.125 deg C The conversion for this is a little more complicated. But is looks like I will again try an brute force it into ASCII with assembler so the C# GUI can easily read it.

Any suggestions welcome...

Thanks, Tom


这篇关于我试图从串口获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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