04-22-2020 12:53 AM
Hello everyone!
I'm trying to connect my controller (atmega2560) with Labview via Com-port.
The task is to send the commant to the controller and receive the answer. Command and answer should be hexadecimal type.
For my task, I use standart example "Serial Write and read on two Ports". The only one changing is selecting of hexadecimal display style to the "Read string" and "Write string".
Well, I send to my controller this one:
0x01 00 00 01
For this message, controller have to anser:
0x 0d 00 00 0d
But I have:
0x 00 02 00 02 - this is the message of error, what means that controller does not get the command right (0x01000001).
As I can understand, changing the display style for "Write string" is not enough.
What I also have to do, to send the hexadecimal constant to my controller?
Sorry for my English:)
Solved! Go to Solution.
04-22-2020 05:54 AM
What all settings did you use? And why are you using the 2 port example? That example was designed to be used between 2 ports on the same machine with a NULL Modem cable between them.
My current thought is that you need to turn off the End Write On Termination Character and the End Read On Termination Character.
But do you have any documentation on the message protocol? Based on your description, it is a very poor protocol. Hex/Binary/Raw communication schemes need structure around the message data to make sure you are properly aligned (ie: you are interpreting the correct bytes). This typically includes a start character (I often see 0x2), a message id or message length byte(s), the data, and finally a checksum or CRC (to error check the data, extra step to make sure you are aligned to the message frame).
04-22-2020 09:53 PM
Baudrate 9600.
I use 2 port example just because it is close fo my task- send and receive the essage from my device. Maybe, in the library of labview examples have another good variant.
I'm sorry, could you, please explain how I can "turn off the End Write On Termination Character and the End Read On Termination Character"? This is my first time of using labview. Quite possibe, my question is very stupid 😄
I use "some kind of MODBUS protocol". The principle of work is similar, but the commands are different. Consequently, you are totaly right: it includes message id, command and CRC.
04-22-2020 09:59 PM
All setting for ports:
BAUD 9600
number of bits: 8
Stop bits: 1
parity: no
control: no
This is all settings from the terminal. And I repite this in labview.
04-22-2020 10:29 PM
I turned off the "End Write" and "End Read" and now it works!
I received:
0x 0d 00 00 0d
But I also have the error: Timeout expired before operation completed. By the way, it works!
Thanks!
04-23-2020 05:15 AM - edited 04-23-2020 05:15 AM
@iaz5 wrote:
I use "some kind of MODBUS protocol". The principle of work is similar, but the commands are different. Consequently, you are totaly right: it includes message id, command and CRC.
Without knowing the details, I can give a very simple example here. In a real system, I would use a more complicated setup where I read a single byte until the start byte is read, then read the ID, read the data, read the CRC and verify the CRC.