Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 846 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 6 of 7 1 2 3 4 5 6 7
Re: Serial Communications Header [Re: EvilSOB] #334543
07/23/10 20:32
07/23/10 20:32
Joined: Nov 2007
Posts: 14
D
druid Offline
Newbie
druid  Offline
Newbie
D

Joined: Nov 2007
Posts: 14
i have a new question about using the " Serial Communications Header" on reading a number from serial,please help me.

i was using the "port_read_number(portSerial,tmp);" and tmp is a var. how can i get the right number from serial? i have only got 789516.xxxx things. i have tried print DEC,BIN,BYTE,String from the serial device.i have tried &tmp and float tmp or int tmp or long tmp and didn't get the right number.

if i use other serial tool,i can get the wanted number (0-9).what should i do?

thank u~~~

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 Offline OP
Expert
EvilSOB  Offline 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
Code:
// 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" )
Code:
// 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: EvilSOB] #334595
07/24/10 05:08
07/24/10 05:08
Joined: Nov 2007
Posts: 14
D
druid Offline
Newbie
druid  Offline
Newbie
D

Joined: Nov 2007
Posts: 14
thank u EvilSOB
i follow ur advice and do these things:
the device send variable by "Serial.print(1000+speedCount);" 10 times a second.(speedCount is an int form 0 to 9.)

and i was trying to read a long-integer :
var tmp;
...//open Serial and other code.
long tmp_long=0;
port_read_number(portSerial,&tmp_long);
tmp = tmp_long;
and i got tmp=-1036239 .is there anything i mis-understanding?

or i have to send serial 4-byte long-integer in the format "1,0,0,0"-"1,0,0,9"?

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 Offline OP
Expert
EvilSOB  Offline 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: EvilSOB] #334661
07/24/10 14:15
07/24/10 14:15
Joined: Nov 2007
Posts: 14
D
druid Offline
Newbie
druid  Offline
Newbie
D

Joined: Nov 2007
Posts: 14
EvilSOB, u r so kind hearted~~~
i am using arduino.

Re: Serial Communications Header [Re: druid] #334662
07/24/10 14:17
07/24/10 14:17
Joined: Nov 2007
Posts: 14
D
druid Offline
Newbie
druid  Offline
Newbie
D

Joined: Nov 2007
Posts: 14
here is the reference link

http://arduino.cc/en/Serial/Print

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 Offline OP
Expert
EvilSOB  Offline 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.
Code:
//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
D
druid Offline
Newbie
druid  Offline
Newbie
D

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:
Code:
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 Offline OP
Expert
EvilSOB  Offline 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...
Code:
//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...
Code:
//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 Offline OP
Expert
EvilSOB  Offline 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]
Quote:
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
Page 6 of 7 1 2 3 4 5 6 7

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1