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