完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,GuySi正在尝试把一系列字符串传送到Python,所有的值都显示得很完美,但是它们都以结尾的随机字符结尾,每当我重新启动MPLAB X IDE时,我得到新的字符串字符的随机结尾。这是我的代码;还有,这里是我在Pyth.B,'4.5'\x13n12b,'x13n'b'- 450.380,x13n'b''600,x13n'b'4.5000,x13n'b'0.1235050x13n'b'- 450.380,'x13n'b''600 .000万x13n',你可以看到,我得到了我想要的字符串,但是在结尾有附加的随机字符。就像我说的那样,随意的角色变成了别的东西,但它们总是在那里。我错过了什么吗?或者我可以手动实现一些东西(例如空字符)?最后,这只是一个针对不同程序的测试代码,所以不要太担心它没有意义,比如声明一个int并立即将它转换为Frava.Tnx中的高级!费利克斯
以上来自于百度翻译 以下为原文 Hi guys I am trying to transmit a bunch of strings over serial to python, all the values show up perfectly but all of them end with random characters at the end, every time I restart MPLAB X IDE I get new random end-of-string characters. Here is my code; #include "mcc_generated_files/mcc.h" #include float LOG_DATA = 0; int w = 600; float x = 4.5; float y = 0.12345; float z = -450.38; int main(void) { SYSTEM_Initialize(); while (1) { CONV_FLOAT_2_STRING(x); CONV_FLOAT_2_STRING(y); CONV_FLOAT_2_STRING(z); LOG_DATA = w; CONV_FLOAT_2_STRING(LOG_DATA); } return -1; } void CONV_FLOAT_2_STRING(float LOG_DATA ) { char MyString[4]; sprintf(MyString,"%f",LOG_DATA); SEND_STRING(MyString); } void SEND_STRING(unsigned char * OutStr) { while (*OutStr) //loop until we hit a NULL UART2_Write(*OutStr++); //send character, and bump pointer UART2_Write(10); //so python receives NL command } And then also, void UART2_Write(uint8_t txData) { while(U2STAbits.UTXBF == 1) { } U2TXREG = txData; // Write the data byte to the USART. } Here is what I am getting in python; b'4.500000|x13n' b'0.123450|x13n' b'-450.380|x13n' b'600.0000|x13n' b'4.500000|x13n' b'0.123450|x13n' b'-450.380|x13n' b'600.0000|x13n' So as you can see I am getting the string I want but with additional random characters at the end. And like I said sometime the random characters change to something else, but they are always there. Am I missing something? Or can I maybe implement something manually (e.g. null character)? Lastly, this is just test code meant for a different program so don't worry to much about it not making sense, like declaring an int and instantly changing it to a float. tnx in advanced! Felix |
|
相关推荐
4个回答
|
|
对不起,我忘了在字符串中声明以下内容:b’4.5000’x13n'b’- 450.380’x13’n'b’600 .x13’n'b’4.5000’x13n'b' 0.1234 50' x13n'b'- 450.380 'x13n'b' 600 .000万x13'黑色部分是随机字符(大多数人可能都是这样想的)
以上来自于百度翻译 以下为原文 Sorry I forgot to state the following, In the string; b'4.500000|x13n' b'0.123450|x13n' b'-450.380|x13n' b'600.0000|x13n' b'4.500000|x13n' b'0.123450|x13n' b'-450.380|x13n' b'600.0000|x13n' The black part is the random characters (which most of you probably figured anyway) |
|
|
|
5月10日在Python结束时发送13和10。你试过了吗?
以上来自于百度翻译 以下为原文 Sending 10 may be 13 and 10 at python end. Have you tried UART2_Write(13); //which is UART2_Write('r'); |
|
|
|
首先,这些长度比分配给MyScript的4个字符长得多,因此您有缓冲区溢出。这可能会导致很多有趣的事情,所以你需要首先解决这个问题。x13是回车(r)-在Windows“rn”中通常表示断线。所以,我猜,它是在Python的某个地方插入了一些软件。
以上来自于百度翻译 以下为原文 To begin with, these are much longer than 4 characters which you allotted to MyString, so you have buffer overruns. This may result in a lot of funny things, so you need to fix this first. x13 is carriage return (r) - in Windows "rn" commonly denotes line breaks. So, my guess is, it is inserted by some software somewhere on the way to Python. |
|
|
|
什么…我完全忘记了我的弦长!非常感谢你们,解决了我的问题!
以上来自于百度翻译 以下为原文 what...I totally forgot about my string length! Thank you so much guys, that solved my problem! |
|
|
|
只有小组成员才能发言,加入小组>>
5242 浏览 9 评论
2031 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3207 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2256 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
596浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
678浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 17:57 , Processed in 1.391293 second(s), Total 54, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号