09-03-2009 03:26 AM
im communicating through rs232 interface talking to this device card just testing the LED to see if it would come on.
so im trying to format a 16 bit word.
the 16bit word is what im going to send to the write the device for the LED to come on.
on this document i have
this may help a lil more
a 16 bit parallel bus
connector P1 bits 1-5
then address bits 6-15
upper byte =18 which is in binary the lower bit can be garbage.
so basically the switch is going to recognize 00001xxxxxxxxxxx
to explain more upper byte is 18 which is 00010010xxxxxxxx
but you you 000010010xxxxxxx
the 16 bit is cut off
the lower byte is any binary number.
but the upper byte have to be combine with the lower byte
then that out goes to the device.
you probably got to do some bit shifting
09-03-2009 03:54 PM
Standard RS-232 UARTS use 8 bit bytes. 16 bit RS-232 would require specialized hardware, so let's assume you can only write 8 bits at a time.
Where is the 16 bit parallel bus you mention? On your test card?
In order to build a 16 bit word, you test board must receive two 8 bit bytes and build the 16 bit word. Do you know the expected byte order of your test board? MSB first or LSB first?
Do you have the data your are sending as 16 bits words? You can only send 8 bit bytes, so if you have 16 bit words, you need to split them into 8 bit bytes.
Once you have the 8 bit bytes, send them in the order that the test board expects.
char lowerByte, upperByte; // 8 bit bytes
int my16bitWord = 0x1234;
// get the lower byte
// mask off the upper byte, and cast it as a char
lowerByte = (char) (my16bitWord & 0xFF);
// get the upper byte
// shift the value right 8 bits, mask off the upper byte, and cast it as a char
upperByte = (char) ((my16bitWord >> 😎 & 0xFF);
09-03-2009 04:21 PM
//this is not not working
int main()
{
short int DATA1=1,DATA2=2,DATA_RESULT=0;
short int ADDRESS=25;
char Ch[7];
int result=0;
int bytes_sent=0;
char read_data[7];
char inbuff[7]={0};
char *TEST;
OpenComConfig(1,"COM1",115200,0,7,1,512,512);
{
Ch[0] = 0;
Ch[1] = 'U';
//DATA_RESULT= (DATA1* 32 + DATA2) * 32 +ADDRESS;
DATA_RESULT= (DATA1* 32 + DATA2) * 32 +ADDRESS;
Ch[2] = (DATA_RESULT>>8) & 0xff;
Ch[3] = DATA_RESULT & 0xff;
Ch[4] = 0;
Ch[5] = 0;
Ch[6] = Ch[0] + Ch[1] + Ch[2] + Ch[3] +Ch[4] + Ch[5];
Ch[6] = Ch[6] & 0xFF;
bytes_sent=ComWrt(1,Ch,7);
Delay(1);
bytes_sent=GetInQLen(1);
bytes_sent=ComRd(1,inbuff,7);
// compare card Address bytes
if (Ch[0] != inbuff[0])
{
MessagePopup("%s","ADDRESS BYTES DONT EQUAL");
}
// compare checksum bytes
if (Ch[6] != inbuff[2])
{
MessagePopup("%s","CHECK SUM NOT EQUAL");
}
// Check returned status byte
if (inbuff[3] != 0)
{
MessagePopup("%s","ADDRESS BYTES DONT EQUAL");
}
}
return 0;
}
09-03-2009 04:55 PM - edited 09-03-2009 04:56 PM
Darnell:
You need to be more specific than just to say "this is not not working". We can't help you if you don't help us a little more.
What have you tried?
What have you seen?
Have you verified that the bytes in Ch are what you expect?
The point of your formulas isn't clear. Are you sure they're doing what you want them to? Have you looked at the values and do you know what to expect?
You reuse bytes_sent multiple times. What was its value at each step on the way? How many bytes are sent? How many were received?
Do you know how long you should wait before you get a response?
Are you getting any response?
Do you have any test points you can probe on your test card to see if it's doing what you expect?
Do you know if your test card is functional?
As a general rules, it's good practice to check for errors on all your serial commands like OpenComConfig, ComWrt, and ComRd. Did you get any errors?
Do any of your message boxes pop up?
09-03-2009 05:18 PM
Al trust me i have all that you said , im going to send you what i got.
09-03-2009 05:19 PM
09-03-2009 05:20 PM
09-04-2009 01:04 AM
Hi darnell,
You have commanded your serial port to read 7 bytes.
Are you sure your device is sending you 7 bytes as a response to the 'Ch' string?
If it is sending less than 7 bytes then your ComRd call will wait for some time and then it will timeout.
Check the return value of your ComRd function to see if it is less than 7.
That might be why you think it is not working.
Hope this helps,
09-04-2009 08:12 AM
what im thinking it may be is i im having a cable issue again where in the cable is not wire correctly. as pins 2 and 3, and 7 and 6. it could be that issue again.
then if its not that issue , it got to be the address im sending it is not correct. so i call the vendor to find out if they had a manual to the device card. so they are going to
email me the manual this morning. soi will know what it is defnitely when he email me this morning. sometimes when i can get communication through an instrument or
device i usually get frustrated , and i start second guess myself . so i will no defnitely today what the issue you is.
is there a program execution someware in CVI ladwindows or somewhere where there shifting and formating 16bit words. so i can make sure mypart is right.
that would be helpful to have a reference.
Also am im formating the the 16bit word? check the Bit zip thats attach already.
09-08-2009 05:56 PM