PsychoMantis
asked on
Sending binary starting LSB throught serial port
Hi,
I am writing a program to communicate with a device throught a serial port. The device embedded software reads in the packets by LSM (Least Significant Bit).
Can i hard code the binary numbers in my program to send to the device?
How am i going to send by LSM?
Thanks,
I am writing a program to communicate with a device throught a serial port. The device embedded software reads in the packets by LSM (Least Significant Bit).
Can i hard code the binary numbers in my program to send to the device?
How am i going to send by LSM?
Thanks,
ASKER
OK...
In C++
Part of the code:
//Serial class
Cserial serial;
//Packet settings to communicate the device
s.negH= 0x06;
s.seqNo= 0x01;
s.Uart= 0x0b;
s.bRate= 0xe0;
s.tDetect= 0x2580;
s.pMode= 0x13;
//Storing the values in a char like u say serial send by char
static char szMessage[]={s.negH, s.seqNo, s.Uart, s.bRate, s.tDetect, s.pMode};
//Send the packet to the device
serial.SendData(szMessage, strlen(szMessage));
//Echo send message
cout<<szMessage<<" send"<<endl;
I have used hexadecimal to send the data to the serial port. How do i know that the serial port is using LSB or MSB, is it only apple computers use MSB?
Now how can i use binary to send the serial port?
If i am going to send an 'A' to the serial port with binary does it looks like this?
int a = 00001010;
static char szMessage[]={a};
serial.SendData(szMessage, strlen(szMessage));
By the way i'm using borland c++ builder 6.
Thanks,
In C++
Part of the code:
//Serial class
Cserial serial;
//Packet settings to communicate the device
s.negH= 0x06;
s.seqNo= 0x01;
s.Uart= 0x0b;
s.bRate= 0xe0;
s.tDetect= 0x2580;
s.pMode= 0x13;
//Storing the values in a char like u say serial send by char
static char szMessage[]={s.negH, s.seqNo, s.Uart, s.bRate, s.tDetect, s.pMode};
//Send the packet to the device
serial.SendData(szMessage,
//Echo send message
cout<<szMessage<<" send"<<endl;
I have used hexadecimal to send the data to the serial port. How do i know that the serial port is using LSB or MSB, is it only apple computers use MSB?
Now how can i use binary to send the serial port?
If i am going to send an 'A' to the serial port with binary does it looks like this?
int a = 00001010;
static char szMessage[]={a};
serial.SendData(szMessage,
By the way i'm using borland c++ builder 6.
Thanks,
To find out if particular computer uses MSB or LSB scheme you need to read specs. on serial port. I would think that all serial ports on all PCs ( be it Mac or IBM clone ) using the same scheme.
>> Now how can i use binary to send the serial port?
I still don't understand the question. When your are writing to serial port you will be writing bytes.
so
char ch1 = 'A';
char ch2 = 65; // decimal 'A'
char ch3 = 0x41; // hex 'A'
Send(ch1);
Send(ch2);
Send(ch3);
will produce exactly the same result.
>>
>> int a = 00001010;
>> static char szMessage[]={a};
>> serial.SendData(szMessage, strlen(szMessage));
well, first of all binary representation for 'A' would be 01000001. Secondly that would send 8 bytes each of them will represent bit in A. Is that what you want?
See all outputs from serial ports are binary, since serial port outputs bit by bit. So I think that may be you confused here. To find out what you need to send you need to know exactly what you device expects.
Does it expect one byte per input character or eight?
>> Now how can i use binary to send the serial port?
I still don't understand the question. When your are writing to serial port you will be writing bytes.
so
char ch1 = 'A';
char ch2 = 65; // decimal 'A'
char ch3 = 0x41; // hex 'A'
Send(ch1);
Send(ch2);
Send(ch3);
will produce exactly the same result.
>>
>> int a = 00001010;
>> static char szMessage[]={a};
>> serial.SendData(szMessage,
well, first of all binary representation for 'A' would be 01000001. Secondly that would send 8 bytes each of them will represent bit in A. Is that what you want?
See all outputs from serial ports are binary, since serial port outputs bit by bit. So I think that may be you confused here. To find out what you need to send you need to know exactly what you device expects.
Does it expect one byte per input character or eight?
ASKER
Answer:
All pc send by LSB
Apple computers send by MSB
Therefore you can just writing you program to send either of the hexa,oct or binary and the hardware layer will automatically send by LSB binary first (on normal PC) and MSB binary first (on Apple pc).
I got the answer to my question...
Sorry I am deleting the question and not giving any points..
Thanks for your time mblat,
All pc send by LSB
Apple computers send by MSB
Therefore you can just writing you program to send either of the hexa,oct or binary and the hardware layer will automatically send by LSB binary first (on normal PC) and MSB binary first (on Apple pc).
I got the answer to my question...
Sorry I am deleting the question and not giving any points..
Thanks for your time mblat,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In any case, all serial ports I know of don't take bit inputs, they take characters(bytes).
So what bit get send first LSB or MSB is characteristic of serial port (hardware) itself and has nothing to do with C++ or any other language/OS per se.
So either you port will output LSB fist and you have no problem sending any data out ( binary or otherwise ) or if it sends MSB fist then all you need to reverse bits in your byte BEFORE sending it out to the port.
As far as hardcoding binary - i just don't understand question here. It doesn't make any difference how you represent you data.
Any way generally it is helpfull to know hardware/OS/compiler combination when answring this kind of a questions.....