02-02-2006 08:40 AM
02-02-2006 10:22 AM
02-02-2006 08:47 PM
02-03-2006 01:52 AM
02-03-2006 07:53 AM
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.
02-03-2006 11:35 AM
02-03-2006 01:47 PM
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...
02-03-2006 08:49 PM
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
02-06-2006 02:25 AM - edited 02-06-2006 02:25 AM
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
02-06-2006 09:30 AM
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