Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Serial Port access slow (with code)

Author
Message
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 14:57
Hi All,
I am trying to receive data across the serial port. This is my first attempt and it works ok. I haven't gone down the Cattlerustler route just yet as i've tried to do it using Kernel32 instead. I'm going to try Cattlerustlers DBP_SerialPortMulti_exp.dll plugin in a minute and see if it works better.

Since I couldn't find a suitable answer on the forum I thought I would post this anyway and see if anyone knew the answer.

When I read from the serial port it pauses the program for a period of a second or so - obviously not good since it is supposed to be doing other things as well.

Here is the code - much thanks for any help.

Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 17:00
Sorry, to make it easier I should have added:

It runs with no pauses without the following line:

result = call dll(c_KERNEL32, "ReadFile", r_hPort, char_buf+4, 255, char_buf, 0)

where,
char_buf = alloc zeroed(4+255)
r_hPort = call dll(c_KERNEL32, "CreateFileA", r_CommPort$, 0x80000000, 0, 0, 3, 0x80, 0)

Unfortunately, and obviously, that is the line that reads from the serial port. Hence my problem....
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Jul 2011 17:08
Did you get any better results using the other method?

I do know that even with your baud rate at 9600 serial ports can be very slow for large amounts of data. Kinda like back in the days of dial up internet. And the pause from what I gather should only be a fraction of that time while it's synchronising.

Warning! May contain Nuts!
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 18:33
I'm having fun with the other method to be honest. Even simple code is crashing.



The line containing SPM_Openport causes the program to crash saying that the I/O operation has been aborted because of either a thread exit or an application request.

So I don't seem to be able to open the port. I am playing with SPM_ConfigurePort at the moment, but different values don't seem to do much.

The amount of data coming across the serial port isn't very large (or shouldnt be). It is probably only about 30 numbers, each around 8 digits long and sent every 5 seconds.

I'm puzzled on both ends at the moment...
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 18:36
I should add that I can hyperterminal (yep, im on Win 7, but put it on anyway. Bloomin MS) the port and the data is fine and isn't a large quantity - sorry should have put that in the other post.
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 19:31
Ok, I've answered it myself. It was my own fault naturally.

The example I was using stated that some code was optional. I am now disputing that

From the Microsoft library:
When reading from a communications device, the behavior of ReadFile is determined by the current communication time-out as set and retrieved by using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS.

So when I put this back in:


It all works without slowing down.

Time for a cup of tea
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Jul 2011 19:31
Are you getting dropped data/packets? I did this some years ago transferring over serial and parallel to 8 bit machines. Ideally you should only need to sync on one side, the receiver. I tried syncing both ends and it slowed transfer rates to something very bad. I've not used these plugins yet but interested in finding out if it's a viable option for the future...

Warning! May contain Nuts!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Jul 2011 19:33
I'll link back to this page for future reference on my website.

Warning! May contain Nuts!
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 2nd Jul 2011 20:40
Hi,
Thanks for the advice. See my comment up above - all sorted now. Was just to do with the timeouts.

I had a go at the using the plugin, but I've solved it using Kernel32 now and it's working fine. In another comment I saw someone write that they had more stability using this method than the plugin so I'm happy enough to use it.

Anyone wanting the code for using Kernel32 to get at the serial port can use my code up above it is all there in the two posts (though it's largely based on someone else's who I would thank if I could remember - thank you).

Login to post a reply

Server time is: 2024-04-17 00:28:21
Your offset time is: 2024-04-17 00:28:21