LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW YMODEM file transfer protocol via RS-232 port

Hi folks,

 

Recently I come across a project that requires me to load firmware to a device via RS-232 using YMODEM protocol. I could do it via TeraTerm, however, TeraTerm pops up annoying windows during the operation. Hence, I would like to use LabVIEW so that everything is under the control.

 

Unfortunately, LabVIEW does not provide any module that can transfer file using YMODEM over RS-232. I have studied the YMODEM protocol myself, and the protocol is summarised as below:

 

SENDER                                                                                    RECEIVER 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<              C
SOH 00 FF "foo.c" "1064'' NUL[118] CRC CRC >>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<            ACK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<               C
STX 01 FE data[1024] CRC CRC>>>>>>>>>>>>>>>>>>>>>>>> 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
STX 02 FD data[1024] CRC CRC>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
STX 03 FC data[1024] CRC CRC>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
STX 04 FB data[1024] CRC CRC>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
SOH 05 FA data[100] 1A[28] CRC CRC>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
EOT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             NAK
EOT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<               C
SOH 00 FF NUL[128] CRC CRC >>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK

 

I can write command to COM port and the device returns ASCII string "C" to indicate that it is ready to receive file transfer. According to the protocol, I need to send "Header info" as block 0 which is:

 

SOH 00 FF "foo.c" "1064'' NUL[118] CRC CRC

 

I checked many example code in other programming languages, i.e. C#, C, people just write to COM port with "SOH", "00", concatenate("FF", "foo.c", "1064"), CRC[2], one after the other, everything is in byte data type. However, LabVIEW "VISA Write" VI only takes string as input.

 

I have made the VI that reads my .bin file to convert them as 2D byte array, because I need to split the file into 1024 bytes blocks as required by the protocol. Also, I have made the VI to calculate CRC based on the each data block. Then I send them one after the other as described above. As mentioned, the "VISA Write" VI only takes string input, hence, I convert the byte data array to string using "Byte array to string" function before sending.

 

Now I am stuck at the last stage where I need to send an empty data block to indicate that there are no more files to be transferred (YMODEM is batch file transfer protocol). After after sending the first file, I sent "EOT" to indicate the first file is done and wait for "C" from the device to tell me that it is ready for second file. Then, I have sent the data block formatted as follow to the device to tell the device I am done with transferring the files:

 

SOH 00 FF NUL[128] CRC CRC

 

After this step, instead of sending me back "Done" from the device, it sends me "Failed to receive the file!".

 

I have no idea what is wrong with my LabVIEW code. Other third party software is able to successfully transfer the file to the device. Could anyone help me to debug? Thanks in advance.

 

Jacky

0 Kudos
Message 1 of 9
(6,780 Views)

@GJ.VVU wrote:

I checked many example code in other programming languages, i.e. C#, C, people just write to COM port with "SOH", "00", concatenate("FF", "foo.c", "1064"), CRC[2], one after the other, everything is in byte data type. However, LabVIEW "VISA Write" VI only takes string as input.


 A string is just a series of bytes.  You can set it to Normal display mode to look at it as ASCII characters.  Or Hex display mode to see it has hex bytes, especially useful for non-printable characters.  Or \codes mode which is a combination of printable characters and codes for non-printable characters.

 


@GJ.VVU
wrote:

Hi folks,

 


I have no idea what is wrong with my LabVIEW code. Other third party software is able to successfully transfer the file to the device. Could anyone help me to debug? Thanks in advance.

 

 We have no idea what is wrong with your LabVIEW code either.  How come?  You failed to attach your VI so we can see what you did.  Attach your VI, and only then could someone help you debug.

0 Kudos
Message 2 of 9
(6,757 Views)

Hi RevensFan,

 

Sorry for not attaching the files, they were a bit messy yesterday, I have tidied it up a bit. Please see attachment. Thank you.

 

 

0 Kudos
Message 3 of 9
(6,730 Views)

In Send YMODEM Packet.vi, should the case labeled "PostPacket" emit a SOH or an EOT?  Presently it emits a SOH, same as the "PrePacket" case.

 

Wow... YMODEM/XMODEM... that's just ancient, man.

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 4 of 9
(6,709 Views)

Hi Dave,

 

According to the protocol, the post packet is used to tell the receiver that there is no more files to be transmitted, the EOT is to indicate the end of each file. Hence, after the EOT the receiver is still sending C to indicate that the transmission is still going. The post packet is to tell the receiver that there is no more file. The transmission is done.

 

This YMODEM is used by the device boot loader, unfortunately I cannot do ISP to flash the device.

0 Kudos
Message 5 of 9
(6,697 Views)

Hi GJ.VVU,

 

do you have a (PDF) document, where the YMODEM transfer mechanism is described?

I cannot find a document where it is documented.

 

Are you sure, it is in this way?

SOH 05 FA data[100] 1A[28] CRC CRC>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
EOT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             NAK
EOT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<               C
SOH 00 FF NUL[128] CRC CRC >>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             ACK

 

 

Thanks and BR

EW

-------------------------------------------------------------------
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
0 Kudos
Message 6 of 9
(5,543 Views)

I have found the protocol here:

http://www.blunk-electronic.de/train-z/pdf/xymodem.pdf

 

page 16:

 

EWiebe_0-1576745563429.png

-------------------------------------------------------------------
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
Message 7 of 9
(5,512 Views)

Hi

Do I need to enable/disable some cases?

I like to use it for an ST controller and with TeraTerm its working, did anybody has an idea whats the differenec between the LabView vi and TeraTerm?

Thanks in advance

0 Kudos
Message 8 of 9
(5,097 Views)

One is a programming language while the other is a terminal emulator.  They do have one thing in common, though.  In your post, they are both spelled incorrectly.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 9
(5,089 Views)