LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a downloadable(Binary file formate) to a flash memory using the RS 232 communication system.

Hi..!
How to write a downloadable(Binary file formate) to a flash memory using the RS 232 communication system.
In detail,
I have a motorola s-records, I have set of tools to convert the s-records to binary file.
I have binary file which can run the flash memory.
I have to transfer the binary file from the host pc to the
target device.I am famillar with sending and recevibng the commands to device and recive the responce from the device and controling manpilating the device responce. But this is my first time that try to transfer a file using the Rs 232 communication...Is there any examples for that..? Is there any special protocals which is supported to write a file
via RS232 communication..?
 

Thanx and regards,
Venki
0 Kudos
Message 1 of 12
(5,139 Views)
ComFromFile function in RS232 library should be what you need to do your job. Unfortunately I had never used it so I cannot give you any hint on this, but the online help seems good in explaining how to use it.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 12
(5,130 Views)
Dear Venki,
Please try the following steps..
1. Open and cnfig the COM port with "OpenComConfig (1, "COM1", 14400, 0, 7, 1, 512, 512);" function.
2. Use the function to open function.
3. Read a byte from the file.
4. use the "ComWrtByte (1, 1);" function to write to the comport.
ComWrtByte() function writes the byte informationin the comport. Other function writes the ASCII charector in the port.
Regards,
Kumar.E
0 Kudos
Message 3 of 12
(5,134 Views)
Can you clarify your sentence in step 4, Kumar? 'Cause I am regularly using ComWrt to write messages to the serial port that includes non-printable characters without problems.
 
To test ComFromFile function I have written this simple program that sends a file to COM1 then reading it back from COM2 connected via a null-modem cable to com1. The file is the complete set of bytes from 0x00 to 0xff: it is regularly written and read back using ComFromFile and ComRd.
 
Hope that this can help Venki in his Job.
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 12
(5,126 Views)

Many thanx for reply it helps me a lot ....

Still,

I could send the binary file to the comport....

I have to monitor the several chunks from the binary file to comport transport......

For that i have tried to get the serial port monitors...

such as.....

lookrs232
Advanced Serial port monitor
BillSerialMonitor
free-serial-port monitor
etc..etc...

but all of them are not usefull for me as i can not view simultaneouly when send the file by CVI....

Is there any way to monitor it..when use send via CVI ..In detail...

I want to notice what happend at the comport after sending the binary file by ComFromFile function......

Any ideas suggessions...

Thanx and Regards,

Venki.

 

 

 

0 Kudos
Message 5 of 12
(5,105 Views)
Dear Roberto,
With "ComWrt (1, , ); "  you can send the anything in ASCII hex equalent. In "ComWrtByte (1, );" you can send the any byte in binary format.
I have tried to write MODUS RTU master functions. That time I found only "ComWrtByte (1, );" could help to  do my job.
Regards,
Kumar.E
0 Kudos
Message 6 of 12
(5,096 Views)

Excuse me Kumar but I cannot get the difference between "ASCII hex equivalent" and "byte in binary format": suppose I have to write a character to the device: this character is associated to a given bit pattern that is actually sent to it via com port and cabling. Hex, binary, octal or ascii are only different representations of this bit pattern mainly for our confort. Wether I send to the device "A" or 0x41 or \101, I am always sending the same bit pattern: 1000001, sent as a series of different voltage levels one after the other.

What may be happening is that other functions from ComWrt or ComWrtByte acts differently from how we expect; for example, passing a string with an embedded NUL character to ComWrt and strlen(string) as "number of bytes to send" parameters causes this function to stop at this NUL byte even if we wanted to proceed with the rest of the string, but this is due to strlen actual behaviour, NOT from com functions.

Or I had not understood your thinking...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 12
(5,090 Views)

Dear Roberto,

ComWrt() write the charactor 'A' as 65. On the hardware layer the information finally goes as '1000001'. ( Forget about the start bit, stop bit & parity ) what ever we write as charector to the com port , it get converts  into binary and goes through the hardware layer.

Suppose an application requires the information through Comport as follows,

0x06 0x03 0x00 0x6B 0x00 0x03

I have  experienced only ComWrtByte() will send the information. Because there is no ASCII equalent charactor for 0x00.

Please refer the following coding which I have written to read temerature from a temperature controller through  MODBUS RTU protocol.

double ReadTemperature(void)
{
int i,val,send_array[8]={0x01,0x03,0x00,0x40,0x00,0x01,0x85,0xDE},read_array[7];
double temperature=0.0;
for (i=0; i<=7; i++)
ComWrtByte (TCport, send_array[i]);
for (i=0; i<=6; i++)
read_array[i] = ComRdByte (TCport);
read_array[3]=read_array[3]<<8;
val=read_array[3]+read_array[4] ;
temperature=(val-19999)/10.0;
return (temperature);   
}

One more interesting point....

When I short the Tx and Rx pin in my PC serial port and send the ComWrtByte() and use the "GetInQLen (1);" it did not gave me the input buffer length.

Still I need to dig to learn more

Regards,

Kumar.E 

0 Kudos
Message 8 of 12
(5,087 Views)

Dear Kumar,  I am using ComWrt and ComRd in communication with some serial device we have produced internally; in the messages I interchange with such devices I can send and receive NUL charachters the same as every other combination of bits from 0x00 through 0xff: I had no problems using those functions after I understood not to use strlen () to determine how many bytes to send.

I have also used the same command to communicate with a Siemens S7 PLC using Modbus to control a climatic chamber: here an abstract from the source code, as you can see there may be several NUL bytes inside the message.

In my opinion your difficulty to transmit the NUL character lies in other parts of your application and not in ComWrt function.

Regards

Roberto

 

typedef struct {
 int  type;    // Message type
 int  msgLen;    // Message lenght (CRC excluded)
 int  ansLen;    // Expected answer lenght (CRC included)
 int  err;    // Communication error
 int  wait;    // Wait state counter
 double t;     // Tome the message was sent
 unsigned char msg[256]; // Message to the chamber
 unsigned char ans[256]; // Answer from the chamber
} ACS;
ACS clima;

int rifClima (float temp, float slope)

// Starts the chamber work
{
 int  r = 500; // Address
 int  n = 12;  // # of registers written
 int  ncar;
 char msg[512] = { 0 };

 // ...

 clima.type = WRITE;
 memset (clima.msg, 0, 256);
 clima.t = Timer ();  // Message time
 clima.msg[ 0] = 0x11; // chamber address
 clima.msg[ 1] = 0x10; // modbus function number
    clima.msg[ 2] = (unsigned char)(r >> 8);
    clima.msg[ 3] = (unsigned char)(r & 0xFF);
    clima.msg[ 4] = (unsigned char)(n >> 8);
    clima.msg[ 5] = (unsigned char)(n & 0xFF);
    clima.msg[ 6] = n * 2; // Byte count (# of registers * 2)
    clima.msg[ 7] = 0x1; // Start chamber
    clima.msg[ 8] = 0x1; // Activate temp. regulation
    floatpcS7(temp, clima.msg + 15); // Temperature
    floatpcS7(slope, clima.msg + 19); // Temp. gradient
    floatpcS7(0.0, clima.msg + 23); // Humidity
    floatpcS7(0.0, clima.msg + 27); // Hum. gradient

    clima.msgLen = clima.msg[6] + 7;    // Actual query length (plus 2 bytes added later on)
    clima.ansLen = 8;  // Expected answer length

 if (GetInQLen (cli)) FlushInQ (cli);
 CalcCRC(clima.msg, clima.msgLen);
 if (CheckCRC (clima.msg, clima.msgLen)) {
  error = kRS_CRCError;
  goto Error;
 }

    err = ComWrt (cli, clima.msg, clima.msgLen + 2);

 // ...

 return err

}

void floatpcS7(float pc_real, unsigned char *plc_real)

// Conversion from FLOAT to PLC format
{

 plc_real[0] = * (( unsigned char *) &pc_real + 3);
 plc_real[1] = * (( unsigned char *) &pc_real + 2);
 plc_real[2] = * (( unsigned char *) &pc_real + 1);
 plc_real[3] = * (( unsigned char *) &pc_real + 0);

 return;
}

 

Message Edited by Roberto Bozzolo on 02-06-2006 09:26 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 12
(5,060 Views)

Dear Roberto,

I agree with you.

But if you want send the 0x00 through serial port you will not able to do through string. I just give you few steps. please do it your CVI AND WATCH "View varialble Value" (Shift +F7) and see the value

Example 1

    char c[5]="";

      c[0]=65;
      c[1]=66
      c[2]=67;
      c[3]=68;

You will be getting the string value as "ABCD"

Example 2

    char c[5]="";

      c[0]=65;
      c[1]=66
      c[2]=0;
      c[3]=68;

You will be getting the string value as "AB"

So if you load NULL in one index position then the string is treated as completed.

Regards,

Kumar.E

0 Kudos
Message 10 of 12
(5,049 Views)