2 registered members (Ayumi, 1 invisible),
584
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Serial Communications Header
[Re: druid]
#334572
07/24/10 00:18
07/24/10 00:18
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
What is the number being sent by the other device? Is it a single byte, or a 4-byte long-integer, or what? If you are trying to read a single BYTE, then use
// var tmp; //assumed...
BYTE tmp_byte=0;
port_read_bytes(portSerial, &tmp_byte, 1);
tmp = tmp_byte;
If you are trying to read a long-integer (ie "9, 0, 0, 0" )
// var tmp; //assumed...
long tmp_long=0;
port_read_number(portSerial,&tmp_long);
tmp = tmp_long;
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Serial Communications Header
[Re: druid]
#334599
07/24/10 07:01
07/24/10 07:01
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
What language / hardware / platform is the "serial.print" being executed by?
I need to know is the serial.pring sending a 4-byte integer or something else...
If you can tell me what hardware/software is doing the talking I can look it up myself.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Serial Communications Header
[Re: druid]
#334662
07/24/10 14:17
07/24/10 14:17
|
Joined: Nov 2007
Posts: 14
druid
Newbie
|
Newbie
Joined: Nov 2007
Posts: 14
|
|
|
|
Re: Serial Communications Header
[Re: druid]
#334745
07/25/10 00:12
07/25/10 00:12
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I thought it might be. Arduino seems to be the only hardware around that has a "serial.print" function. Ugly little thing that it is. Now, is the +1000 'needed' for the finished product, or is it only for testing? And are you able to change the arduino code? Because if you can change the code, and the +1000 is un-necessary, you can use the following.
//arduino
Serial.print(speedCount, BYTE);
or
Serial.write(speedCount); //does the same thing
//lite-c
byte tmp_byte=0;
port_read_bytes(portSerial, &tmp_byte, 1);
tmp = tmp_byte;
This will let you send a value of speedCount of 0 -> 255 I cant test this of course, as I dont have any arduinos to test with. Does this get you up and running? Do you NEED to send numbers larger than 255? If it doesnt do exactly what you NEED, let me know.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Serial Communications Header
[Re: EvilSOB]
#334789
07/25/10 08:29
07/25/10 08:29
|
Joined: Nov 2007
Posts: 14
druid
Newbie
|
Newbie
Joined: Nov 2007
Posts: 14
|
ok,that works. the +1000 is not for testing. i have change both arduino and lite-c as u said and it works. thank u ,Evilsob last night,before getting ur reply,i tried this in lite-c:
byte last_recieved[2] = {0,0};
if(port_read_bytes(hPort, last_recieved, 2)){
str_cpy((debug.pstring)[0]," ");
str_for_asc((debug.pstring)[0],(long)last_recieved[0]);
str_for_asc(inNumber,(long)last_recieved[1]);
str_cat((debug.pstring)[0],inNumber);
debugDr=str_to_num((debug.pstring)[0]);
}
it works too. but i still don't understand the difference. how to use port_read_number()? i found that u always use port_read_bytes(). it seems port_read_string() don't clear the Read-buffer,but port_read_bytes() did clear the buffer. am i mis-understanding? is 4 byte integer means 4 byte binary data?
|
|
|
Re: Serial Communications Header
[Re: druid]
#334827
07/25/10 14:17
07/25/10 14:17
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
"port_read_number" and "port_read_string" were really only meant for, and only tested with, a lite-c application at BOTH ends. The reason that I tend to use port-read_bytes all the time is because, at its lowest level, that is what the port is 'physically' doing. So I keep thinking that way to avoid confusion. In your arduino code, Im going to assume that speedCount is an arduino-int.(appears the same as a liteC-short) Due to you saying so, and the fact you get two bytes back with your above code. So try these code-combinations. If you dont mind...
//arduino
Serial.write(1000+speedCount);
//lite-c
short tmp_number = 0;
port_read_bytes(portSerial, &tmp_number, 2);
tmp = tmp_number;
and let me know how it goes... And try this one too...
//arduino
Serial.write(1000L + speedCount);
//lite-c
long tmp_number = 0;
port_read_number(portSerial, &tmp_number);
tmp = tmp_number;
//if this fails, leave lite-c as is, but change the arduino code to
long tmp_num = 1000 + speedCount;
Serial.write(tmp_num);
Im curious on this one too...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Serial Communications Header
[Re: EvilSOB]
#334828
07/25/10 14:21
07/25/10 14:21
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
As for the buffer clearing, its old code so I cant remember well. But it may be buggy, but more likely that because the arduino doesnt put a null on the end of its Serial.print strings, then my code doesnt know the string is finished. [EDIT] is 4 byte integer means 4 byte binary data? Yes, as in a datatype of "long". Both arduino and liteC appear to have this onein common. See my second test for you above...
Last edited by EvilSOB; 07/25/10 14:29.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|