简体   繁体   English

终端输入串行命令,输出Arduino Tx

[英]Terminal input serial commands, output Arduino Tx

I am somewhat of a beginner in this space 我在这个领域有点新手

I am using Arduino Mega2560 and interfacing it with a coin machine from a vending machine. 我正在使用Arduino Mega2560,并将其与自动售货机中的投币机接口。 The coin machine runs on a protocol called MDB (multi-drop bus) which is 9bit serial. 投币机基于称为9位串行MDB(多点总线)的协议运行。 I would normally use the Arduino IDE but that does not cater for 9-bit serial. 我通常会使用Arduino IDE,但这不能满足9位串行。 I have therefore decided to code using c and ubuntu 12.04. 因此,我决定使用c和ubuntu 12.04进行编码。 I have come across a usart setup function which can bitbash into 9bit mode. 我遇到过一个usart设置功能,该功能可以将bitbash转换为9bit模式。 I have installed avr-gcc avr-libc avrdude. 我已经安装了avr-gcc avr-libc avrdude。

The coin machine acts depending on serial data it recieves. 投币机根据接收到的串行数据起作用。 ie to reset it needs to read 100101010 from its Rx (this is a random 9-bit number, I am not sure what the true number is at this moment). 即要重置它,需要从其Rx读取100101010(这是一个随机的9位数字,我不知道目前的真实数字是多少)。 Another example would be if it recieves 10101111 on Rx it would dispense a coin of desired type etc. There are also various other commands like ack,poll, etc. So what I want to do is send the appropriate binary numbers out from the Arduino's Tx and into the coin machine's Rx and try get communication with the coin machine. 另一个示例是,如果它在Rx上接收到10101111,它将分配所需类型的硬币等。还有其他各种命令,例如ack,poll等。所以我要做的是从Arduino的Tx中发送适当的二进制数字并进入投币机的Rx,并尝试与投币机进行通信。

This was just for context but my main question is more general (lets assume we are working in 8bit mode): 这只是出于上下文,但是我的主要问题是更笼统的(假设我们在8位模式下工作):

a) how can I type a 8bit binary number (eg 10111010) on the terminal, and have that number be put on the Tx line of the arduno. a)如何在终端上键入8位二进制数字(例如10111010),并将该数字放在arduno的Tx行上。 b) since the mega2560 has 3 Tx/Rx modules, can I Tx from one module and Rx from another module, for testing, such that the 8bit binary number I type in terminal appears on the terminal too. b)由于mega2560具有3个Tx / Rx模块,因此可以从一个模块的I Tx和从另一个模块的Rx进行测试,以便我在终端上输入的8位二进制数也出现在终端上。

note: The reason I want the numbers to be represented in binary is because I want to see each bit, it will make more sense to me that way 注意:我希望数字以二进制表示的原因是因为我想查看每一位,所以这样对我来说更有意义

I am trying to do something similar to Bouni's MateDealer (see github repository) but he is implementing the Arduino as a slave, I want to implement as a master. 我正在尝试做与Bouni的MateDealer类似的事情 (请参阅github存储库),但是他正在将Arduino实现为从属,我想实现为主控。 More on his project here . 更多关于他的项目在这里

Thank you kindly! 非常感谢你!

A) There is two solutions: A)有两种解决方案:

  • you send the binary representation of the number, like '00001111' through the serial line, and then in the µC you use the function strtoul, which takes as parameters an array of char (in this case '00001111') and the base (here 2) and returns the corresponding value (here 0x0F, or 16); 您可以通过串行线路发送数字的二进制表示形式,例如“ 00001111”,然后在µC中使用函数strtoul,该函数将char数组(在本例中为“ 00001111”)和基数(此处为参数)作为参数2)并返回相应的值(此处为0x0F或16);
  • you create your own terminal, which converts the input binary representations into decimal representations (here, converts '00001111' into '16'), sends to the µc which uses the function atoi to get the corresponding value (here, 16 or 0x0F) 您将创建自己的终端,该终端将输入的二进制表示形式转换为十进制表示形式(此处将“ 00001111”转换为“ 16”),并发送至使用函数atoi来获取相应值的µc(此处为16或0x0F)

I think that the former will be easier, but a little bit slower, while the latter could offload the microcontroller. 我认为前者会容易一些,但会慢一些,而后者则可以减轻微控制器的负担。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM