Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (vicknick, howardR, sleakz), 674 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 5 of 7 1 2 3 4 5 6 7
Re: Serial Communications Header [Re: qoolelee] #304976
01/12/10 12:10
01/12/10 12:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
port_close waits for the port to be idle before it closes,
and I think thats the problem...

Try changing the port_close step to this...
Code:
...
    }
    port_close(hPort);
    while(proc_status(port_close))   wait(1);	
    //
    //
    sys_exit("");
}

Let me know how it goes... any changes in behaviour.
Then if its fixed I'll explain what was happening...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Serial Communications Header [Re: EvilSOB] #305136
01/13/10 03:35
01/13/10 03:35
Joined: Dec 2007
Posts: 5
Q
qoolelee Offline
Newbie
qoolelee  Offline
Newbie
Q

Joined: Dec 2007
Posts: 5
Thank you for your response.

The situation is the same, the second re-run of the script is still not able to successfully open the port in SED. After changing my device to com1 instead the usb virtual com9 port, still the same problem happened.

I've got a mcu device designed for my other project for stationary bike control, if it got the order control command "0xFD", it will return "0xFD R", where R stands for a single byte indicates the rpm of the bike. So I change the script to

Code:
#include <acknex.h>
#include <default.c>
#include "Port_IO.h"

TEXT* debug = {  pos_x=20;  pos_y=20;  size_y=400; font="Arial#20b";  strings=20;  flags=SHOW + WWRAP;  }

var hPort;
var temp;
var temp2;
byte sent_data = 0xFD;
byte received_data[2] = { 0x00, 0x00};

function main()
{
	wait(1);	level_load(NULL);	wait(1);	diag("\n\n\n");
	on_esc = NULL;
	//
	//

	hPort = port_open_readwrite("COM1", "2400,n,8,1");
	
	wait(-1);
	
	if(port_read_status(hPort))
	{
		temp = port_write_bytes(hPort, &sent_data, 1, 500);	// write to com1 1 byte 500ms time out
	}
	else
	{
		str_cpy((debug.pstring)[0], "Port is Busy");
	   port_close(hPort);
	   while(proc_status(port_close))   wait(1);
	   //
	   //
	   while(!key_any){wait(1);	}
	   sys_exit("");		
	}
	
	wait(-1);
	
	if(port_read_status(hPort))
	{
		port_read_bytes(hPort, received_data, 2);	// read data from com1 per 1 byte
	}
	
	//	
	while(1)
	{
		str_cpy((debug.pstring)[0], "Port Handle = ");
		str_cat((debug.pstring)[0], _chr(str_for_int(NULL,hPort)));
		str_cpy((debug.pstring)[1], "Data Sent = ");
		str_cat((debug.pstring)[1], _chr(str_for_int(NULL,temp)));	
		str_cpy((debug.pstring)[2], "Data Read [0]= ");
		str_cat((debug.pstring)[2], _chr(str_for_int(NULL,(long)received_data[0])));
		str_cpy((debug.pstring)[3], "Data Read [1]= ");
		str_cat((debug.pstring)[3], _chr(str_for_int(NULL,(long)received_data[1])));				
		if(key_esc)	break;
		wait(1); 
		
	}
	port_close(hPort);
	while(proc_status(port_close))   wait(1);
	//
	//
	sys_exit("");	
}



The result became more confusing,

1. the port sometimes is opened successfully, sometimes don't.
2. when press ecs key to end, sometimes the script crashes, sometimes don't.

result 1
result 2

Any advise will be much appreciated. laugh



Last edited by qoolelee; 01/13/10 05:14.
Re: Serial Communications Header [Re: qoolelee] #305143
01/13/10 05:37
01/13/10 05:37
Joined: Dec 2007
Posts: 5
Q
qoolelee Offline
Newbie
qoolelee  Offline
Newbie
Q

Joined: Dec 2007
Posts: 5
Another test with my little mcu device, if send "0xFF T1 T2" 3 byte command, the device will return "0xFF T1 T2" immediantly.

Though the "Data send =" item on PC end still show the huge number but the LED digits on the mcu device show me it received the command and the T1 T2 bytes and number correctly. But on pc end it seems there's no return from it for me to show it on the computer window.

If I comment out the newly added "while(proc_status(port_close)) wait(1);" line it stop crashed.

Code:
#include <acknex.h>
#include <default.c>
#include "Port_IO.h"

TEXT* debug = {  pos_x=20;  pos_y=20;  size_y=400; font="Arial#20b";  strings=20;  flags=SHOW + WWRAP;  }

var hPort;
var temp;
var temp2;
byte sent_data[3] = {0xFF, 0x10, 0x00};
byte received_data[3] = {0x00, 0x00, 0x00};

function main()
{
	wait(1);	level_load(NULL);	wait(1);	diag("\n\n\n");
	on_esc = NULL;
	//
	//

	hPort = port_open_readwrite("COM1", "2400,n,8,1");
	
	wait(-1);
	
	
	if(port_read_status(hPort))
	{
		temp = port_write_bytes(hPort, sent_data, 3, 500);	// write to com1 1 byte 500ms time out
	}
	else
	{
		str_cpy((debug.pstring)[0], "Port is Busy");
	   port_close(hPort);
	   while(proc_status(port_close))   wait(1);
	   //
	   //
	   while(!key_any){wait(1);	}
	   sys_exit("");		
	}
	
	wait(-1);
	
	while(!port_read_status(hPort)){	wait(1);}
	
	if(port_read_status(hPort))
	{
		port_read_bytes(hPort, received_data, 3);	// read data from com1 3 byte
	}
	
	//	
	while(1)
	{
		str_cpy((debug.pstring)[0], "Port Handle = ");
		str_cat((debug.pstring)[0], _chr(str_for_int(NULL,hPort)));
		str_cpy((debug.pstring)[1], "Data Sent = ");
		str_cat((debug.pstring)[1], _chr(str_for_int(NULL,temp)));	
		str_cpy((debug.pstring)[2], "Data Read [0]= ");
		str_cat((debug.pstring)[2], _chr(str_for_int(NULL,(long)received_data[0])));
		str_cpy((debug.pstring)[3], "Data Read [1]= ");
		str_cat((debug.pstring)[3], _chr(str_for_int(NULL,(long)received_data[1])));
		str_cpy((debug.pstring)[4], "Data Read [2]= ");
		str_cat((debug.pstring)[4], _chr(str_for_int(NULL,(long)received_data[2])));				
		if(key_esc)	break;
		wait(1); 
		
	}
	port_close(hPort);
//	while(proc_status(port_close))   wait(1);
	//
	//
	sys_exit("");	
}



For your reference. Thanks.

Last edited by qoolelee; 01/13/10 05:55.
Re: Serial Communications Header [Re: qoolelee] #305144
01/13/10 06:15
01/13/10 06:15
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
OK, Im having a think on this, but I need to refresh myself with
how my code works first, so give me time... maybe a couple of days...

Firstly, to try and remove the random "crash on exit issue",
try putting "on_esc=NULL;" at the beginning of main,
and re-enable my while(proc_status... line.
default.c has an on_esc function that almost-instant-closes.
I think it is making the code skip some (if not all) of the
port_close stages, thereby leaving the port open and crashing.


From memory, I have not (intentionally) limited the COM port numbers to 8,
but if I find something during my memory-refreshing process, I'll take it
out and let you know...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Serial Communications Header [Re: EvilSOB] #305147
01/13/10 07:20
01/13/10 07:20
Joined: Dec 2007
Posts: 5
Q
qoolelee Offline
Newbie
qoolelee  Offline
Newbie
Q

Joined: Dec 2007
Posts: 5
Really appreciate your quick response.

I must apologize to you, it's my fault, after checking my rusty mcu device. I found some glitch in my firmware.

After re-write and upload to the chip, it works in both reading and writing with your header. Except that on the PC end the port_write_bytes still returns a huge number.

Thank you for your great contribution and your continuous attention on this thread, I think I own you a beer. laugh

Wish you a best day.

Re: Serial Communications Header [Re: qoolelee] #305308
01/14/10 05:05
01/14/10 05:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hehe... been there, done that, myself.
Pulling the wrong MCU from the shelf sucks,
thats why I toss or erase all out-of-date mcu's now.

I'll have a look at the port-write-bytes again because
I can vaguely remember that being a bug I had for a while.
I thought I had fixed it but I may be wrong...
I dont remember if I tested it with an MCU, only with hyperterminal.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Serial Communications Header [Re: EvilSOB] #305824
01/17/10 15:22
01/17/10 15:22
Joined: Oct 2008
Posts: 15
Montevideo, Uruguay
C
charrua Offline
Newbie
charrua  Offline
Newbie
C

Joined: Oct 2008
Posts: 15
Montevideo, Uruguay
nice to see that i were not the only one interested in serial communications, my first post was on this subject about 2 years, in that time i posted code to do serial communications with liteC but on these days seems that few people were working on this topic (seen by many but only few posts). is good to see that serial communications are still alive!

i mantain my offer so if some needs some help, here i'm.
(edit: sorry, i should say: i'm back, i been disconected from this forum for a while, best regards)
(sorry my bad english)

Juan




Last edited by charrua; 01/17/10 19:43.
Re: Serial Communications Header [Re: charrua] #324502
05/21/10 10:27
05/21/10 10:27
Joined: Nov 2007
Posts: 14
D
druid Offline
Newbie
druid  Offline
Newbie
D

Joined: Nov 2007
Posts: 14
i have test the wonderful work and Thanks!

but i have a problem i didn't know whether it is my mistake or bug.

i have tried COM1~COM9 and it works fine,but COM10 and above is not connect correctly.

have anyone get similar problem?

Re: Serial Communications Header [Re: druid] #324532
05/21/10 14:40
05/21/10 14:40
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive just done a bit of research, and it SHOULD work for COM1 right through to COM256

The core API functions should allow this, according to several on-line sources.

But I dont have a USB device that will let me 'set' it above COM8 to test with ATM.
Im gonna try and beg/borrow/steal one in the next few days and I'll post my results...


FYI :: be certain you are trying to access the ports with COM in capital letters, and be sure there is no trailling "."
ie "COM25" is correct, but NOT "com25" or "COM25."


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Serial Communications Header [Re: EvilSOB] #324757
05/23/10 03:13
05/23/10 03:13
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Bug Found and fixed. Thanks for that druid.
The top post of this thread has been corrected.
Read the dark-green [EDIT] up there for explaination.

[WARNING :: TECHNICAL CONTENT]
Serial ports COM1 -> COM9 'appear' to be dos-legacy names,
whereas COM10 -> COM256 are not.
So when accessing the COM10 and above you NEED to lead the port name
with the 'root-path' accessor "\\.\" (eg \\.\COM25 ),
but when accessing ports 1->9 it is assumed by the OS.
My code now adds this accessor automatically, so you dont
NEED to know this, Im just giving this infomation out for the curious...



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 5 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